UNPKG

@tinyhttp/cookie-parser

Version:

Cookie parsing middleware for Node.js

26 lines (25 loc) 1.03 kB
/// <reference types="node" /> import { IncomingMessage, ServerResponse as Response } from 'http'; export interface CookieParserRequest extends IncomingMessage { cookies?: any; secret?: string | string[]; signedCookies?: any; } /** * Parse JSON cookie string. */ export declare function JSONCookie(str?: string | unknown): any; /** * Parse a signed cookie string, return the decoded value. */ export declare function signedCookie(str: string | unknown, secret: string | string[]): string | boolean | undefined; /** * Parse signed cookies, returning an object containing the decoded key/value * pairs, while removing the signed key from obj. */ export declare function signedCookies(obj: any, secret: string | string[]): Record<string, string | boolean | undefined>; /** * Parse Cookie header and populate `req.cookies` * with an object keyed by the cookie names. */ export declare const cookieParser: (secret?: string | string[]) => (req: CookieParserRequest, _res: Response, next?: () => void) => void;