mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add cookie
This commit is contained in:
parent
1a9210fff5
commit
4e0f83c02f
33
cookie/cookie-test.ts
Normal file
33
cookie/cookie-test.ts
Normal file
@ -0,0 +1,33 @@
|
||||
/// <reference path="cookie.d.ts" />
|
||||
|
||||
import cookie = require('cookie');
|
||||
|
||||
function test_serialize(): void {
|
||||
var retVal: string;
|
||||
|
||||
retVal = cookie.serialize('foo', 'bar');
|
||||
retVal = cookie.serialize('foo', 'bar', { httpOnly: true });
|
||||
}
|
||||
|
||||
function test_parse(): void {
|
||||
var 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: CookieSerializeOptions = {
|
||||
encode: (x: string) => x,
|
||||
path: '/',
|
||||
expires: new Date(),
|
||||
maxAge: 200,
|
||||
domain: 'example.com',
|
||||
secure: false,
|
||||
httpOnly: false
|
||||
};
|
||||
|
||||
var parseOptios: CookieParseOptions = {
|
||||
decode: (x: string) => x
|
||||
};
|
||||
}
|
||||
28
cookie/cookie.d.ts
vendored
Normal file
28
cookie/cookie.d.ts
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
// Type definitions for cookie v0.1.2
|
||||
// Project: https://github.com/jshttp/cookie
|
||||
// Definitions by: Pine Mizune <https://github.com/pine613>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
interface CookieSerializeOptions {
|
||||
encode?: (val: string) => string;
|
||||
path?: string;
|
||||
expires?: Date;
|
||||
maxAge?: number;
|
||||
domain?: string;
|
||||
secure?: boolean;
|
||||
httpOnly?: boolean;
|
||||
}
|
||||
|
||||
interface CookieParseOptions {
|
||||
decode?: (val: string) => string;
|
||||
}
|
||||
|
||||
interface CookieStatic {
|
||||
serialize(name: string, val: string, options?: CookieSerializeOptions): string;
|
||||
parse(str: string, options?: CookieParseOptions): { [key: string]: string };
|
||||
}
|
||||
|
||||
declare module "cookie" {
|
||||
var cookie: CookieStatic;
|
||||
export = cookie;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user