@taxum/cookie
Version:
Cookie jar for Taxum
58 lines (57 loc) • 1.71 kB
TypeScript
import type { Temporal } from "temporal-spec";
export type CookieOptions = {
expires?: Date | Temporal.ZonedDateTime;
maxAge?: number | Temporal.Duration;
domain?: string;
path?: string;
secure?: boolean;
httpOnly?: boolean;
sameSite?: "Strict" | "Lax" | "None";
partitioned?: boolean;
};
/**
* Represents an HTTP cookie.
*
* @example
* ```ts
* import { Cookie } from "@taxum/cookie";
*
* const cookie = new Cookie("my-cookie", "my-value");
* ```
*/
export declare class Cookie {
readonly name: string;
readonly value: string;
readonly expires: Date | Temporal.ZonedDateTime | undefined;
readonly maxAge: number | Temporal.Duration | undefined;
readonly domain: string | undefined;
readonly path: string | undefined;
readonly secure: boolean | undefined;
readonly httpOnly: boolean | undefined;
readonly sameSite: "Strict" | "Lax" | "None" | undefined;
readonly partitioned: boolean | undefined;
/**
* Creates a new {@link Cookie} with a given name and value.
*
* You can additionally supply any of the standard cookie options.
*/
constructor(name: string, value?: string, options?: CookieOptions);
/**
* Parses a cookie string into a `Cookie` header.
*/
static parse(cookie: string): Cookie | null;
/**
* Converts the cookie to a removal cookie.
*/
asRemoval(): Cookie;
/**
* Returns a new cookie with the specified value.
*/
withValue(value: string): Cookie;
/**
* Encodes the cookie for `Set-Cookie` headers.
*
* biome-ignore lint/complexity/noExcessiveCognitiveComplexity: simple enough
*/
encode(): string;
}