@taxum/cookie
Version:
Cookie jar for Taxum
78 lines (77 loc) • 2.12 kB
TypeScript
/**
* A Temporal.Instant-compatible object.
*/
type TemporalInstantLike = {
readonly epochMilliseconds: number;
};
/**
* A Temporal.ZonedDateTime-compatible object.
*/
type TemporalZonedDateTimeLike = {
toInstant(): TemporalInstantLike;
};
/**
* A Temporal.Duration-compatible object.
*/
type TemporalDurationLike = {
total(totalOf: {
unit: "seconds";
}): number;
};
export type CookieOptions = {
expires?: Date | TemporalZonedDateTimeLike | TemporalInstantLike;
maxAge?: number | TemporalDurationLike;
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 | TemporalZonedDateTimeLike | TemporalInstantLike | undefined;
readonly maxAge: number | TemporalDurationLike | 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;
}
export {};