@techmely/utils
Version:
Collection of helpful JavaScript / TypeScript utils
37 lines (34 loc) • 1.33 kB
TypeScript
import { NodeEnv } from '@techmely/types';
interface CookieSerializeOptions {
domain?: string;
encode?(value: string): string;
expires?: Date;
httpOnly?: boolean;
maxAge?: number;
path?: string;
priority?: "Low" | "Medium" | "High";
sameSite?: true | false | "lax" | "strict" | "none";
secure?: boolean;
}
interface CookieParseOptions {
decode?(value: string): string;
}
declare function parseCookie(str: string, options?: CookieParseOptions): Record<string, string>;
declare function serializeCookie(name: string, value: string, options?: CookieSerializeOptions): string;
declare const listenCookieChange: (callback: ({ oldCookie, newCookie }: {
oldCookie: any;
newCookie: any;
}) => void, interval?: number) => void;
declare class CookieService {
nodeEnv: NodeEnv;
env: string;
domain: string;
tokenName: string;
constructor(nodeEnv: NodeEnv, env: string, cookieDomain: string);
get(name: string, options?: CookieParseOptions): string | undefined;
set(key: string, value: string, options?: CookieSerializeOptions): void;
setToken(token: string): void;
getToken(): string | undefined;
clearToken(): void;
}
export { type CookieParseOptions, type CookieSerializeOptions, CookieService, listenCookieChange, parseCookie, serializeCookie };