[cookie] add linting and fix found issues (#18310)

This commit is contained in:
Dimitri Benin
2017-07-24 19:56:31 +02:00
committed by Andy
parent 6b00563c2d
commit 56d1e73dc8
3 changed files with 12 additions and 11 deletions

View File

@@ -1,23 +1,21 @@
import cookie = require('cookie');
function test_serialize(): void {
var retVal: string;
let retVal: string;
retVal = cookie.serialize('foo', 'bar');
retVal = cookie.serialize('foo', 'bar', { httpOnly: true });
}
function test_parse(): void {
var retVal: { [key: string]: string };
let retVal: { [key: string]: string };
retVal = cookie.parse('foo=bar; bar=baz;');
retVal = cookie.parse('foo=bar; bar=baz', { decode: x => x });
}
function test_options(): void {
var serializeOptions: cookie.CookieSerializeOptions = {
const serializeOptions: cookie.CookieSerializeOptions = {
encode: (x: string) => x,
path: '/',
expires: new Date(),
@@ -27,7 +25,7 @@ function test_options(): void {
httpOnly: false
};
var parseOptios: cookie.CookieParseOptions = {
const parseOptios: cookie.CookieParseOptions = {
decode: (x: string) => x
};
}

View File

@@ -1,15 +1,16 @@
// Type definitions for cookie v0.3.0
// Type definitions for cookie 0.3
// Project: https://github.com/jshttp/cookie
// Definitions by: Pine Mizune <https://github.com/pine613>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface CookieSerializeOptions {
export interface CookieSerializeOptions {
/**
* Specifies the value for the Domain Set-Cookie attribute. By default, no
* domain is set, and most clients will consider the cookie to apply to only
* the current domain.
*/
domain?: string;
/**
* Specifies a function that will be used to encode a cookie's value. Since
* value of a cookie has a limited character set (and must be a simple
@@ -20,7 +21,8 @@ interface CookieSerializeOptions {
* encode a JavaScript string into UTF-8 byte sequences and then URL-encode
* any that fall outside of the cookie range.
*/
encode?: (val: string) => string;
encode?(val: string): string;
/**
* Specifies the `Date` object to be the value for the `Expires`
* `Set-Cookie` attribute. By default, no expiration is set, and most
@@ -83,7 +85,7 @@ interface CookieSerializeOptions {
secure?: boolean;
}
interface CookieParseOptions {
export interface CookieParseOptions {
/**
* Specifies a function that will be used to decode a cookie's value. Since
* the value of a cookie has a limited character set (and must be a simple
@@ -96,7 +98,7 @@ interface CookieParseOptions {
* *Note* if an error is thrown from this function, the original, non-decoded
* cookie value will be returned as the cookie's value.
*/
decode?: (val: string) => string;
decode?(val: string): string;
}
/**

1
types/cookie/tslint.json Normal file
View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }