cookie-muncher
Version:
Effortless cookie management for server and browser
54 lines (49 loc) • 1.86 kB
text/typescript
declare const httpCookie: {
parse: (cookies: string) => Cookie[];
serialize: (cookie: Cookie, options?: HttpCookieOptions) => string;
};
declare const domCookie: {
getAll: () => Cookie[];
get: (name: string) => Cookie | null;
set: (cookie: Cookie, options?: DomCookieOptions) => void;
remove: (name: string, options?: RemoveDomCookieOptions) => void;
};
declare enum CookieMaxAge {
Now = -1,
OneHour = 3600,// 1 hour
SixHours = 21600,// 6 hours
TwlveHours = 43200,// 12 hours
OneDay = 86400,// 1 day
OneWeek = 604800,// 1 week
TwoWeeks = 1209600,// 2 weeks
OneMonth = 2592000,// 1 month
ThreeMonths = 7776000,// 3 months
SixMonths = 15552000,// 6 months
OneYear = 31536000
}
type Cookie = {
name: string;
value: string;
};
/**
* @property {number} maxAge - The maximum age of the cookie in seconds
* @property {Date} expires - The expiration date of the cookie
* @property {string} domain - The domain for which the cookie is valid
* @property {string} path - The path for which the cookie is valid
* @property {boolean} secure - Whether the cookie should only be sent over HTTPS
* @property {boolean} httpOnly - Whether the cookie should only be accessible via HTTP
* @property {"strict" | "lax" | "none"} sameSite - The same-site policy for the cookie
*/
type CookieOptions = {
maxAge?: number;
expires?: Date;
domain?: string;
path?: string;
secure?: boolean;
httpOnly?: boolean;
sameSite?: "strict" | "lax" | "none";
};
type DomCookieOptions = Omit<CookieOptions, "httpOnly">;
type HttpCookieOptions = CookieOptions;
type RemoveDomCookieOptions = Pick<CookieOptions, "domain" | "path" | "sameSite">;
export { type Cookie, CookieMaxAge, type DomCookieOptions, type HttpCookieOptions, type RemoveDomCookieOptions, domCookie, httpCookie };