seitu
Version:
38 lines • 1.14 kB
text/typescript
//#region src/utils/cookie/index.d.ts
interface CookieAttributes {
path?: string;
domain?: string;
maxAge?: number;
expires?: Date;
sameSite?: 'strict' | 'lax' | 'none';
secure?: boolean;
partitioned?: boolean;
}
/**
* Returns the raw value of `key` from a `Cookie` header or `document.cookie`,
* or `null` when the cookie is missing.
*
* @example
* ```ts twoslash
* import { parseCookie } from 'seitu/utils'
*
* parseCookie('a=1; theme=dark', 'theme') // 'dark'
* parseCookie('a=1', 'theme') // null
* ```
*/
declare function parseCookie(header: string, key: string): string | null;
/**
* Builds a `document.cookie`/`Set-Cookie` string. Defaults: `Path=/`,
* `SameSite=Lax`, `Max-Age` of 400 days unless `expires` is set.
*
* @example
* ```ts twoslash
* import { serializeCookie } from 'seitu/utils'
*
* serializeCookie('theme', 'dark', { maxAge: 60 })
* // 'theme=dark; Path=/; Max-Age=60; SameSite=Lax'
* ```
*/
declare function serializeCookie(key: string, raw: string, attributes?: CookieAttributes): string;
//#endregion
export { parseCookie as n, serializeCookie as r, CookieAttributes as t };