UNPKG

1.54 kBTypeScriptView Raw
1// Type definitions for cookie-parser 1.4
2// Project: https://github.com/expressjs/cookie-parser
3// Definitions by: Santi Albo <https://github.com/santialbo>
4// BendingBender <https://github.com/BendingBender>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6// TypeScript Version: 2.3
7
8import * as express from 'express';
9
10declare global {
11 namespace Express {
12 // Inject additional properties on express.Request
13 interface Request {
14 /**
15 * This request's secret.
16 * Optionally set by cookie-parser if secret(s) are provided. Can be used by other middleware.
17 * [Declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html) can be used to add your own properties.
18 */
19 secret?: string;
20 }
21 }
22}
23
24declare function cookieParser(secret?: string | string[], options?: cookieParser.CookieParseOptions): express.RequestHandler;
25
26declare namespace cookieParser {
27 interface CookieParseOptions {
28 decode?(val: string): string;
29 }
30
31 function JSONCookie(jsonCookie: string): object | undefined;
32
33 function JSONCookies<T extends { [key: string]: string }>(jsonCookies: T): { [P in keyof T]: object | undefined };
34
35 function signedCookie(cookie: string, secret: string | string[]): string | false;
36
37 function signedCookies<T extends { [key: string]: string }>(cookies: T, secret: string | string[]): { [P in keyof T]?: string | false};
38}
39
40export = cookieParser;