type CookieSetOptions = { path?: string; expires?: Date | string; maxAge?: number; domain?: string; secure?: boolean; httpOnly?: boolean; sameSite?: boolean | `none` | `lax` | `strict`; encode?: (value: string) => string; }; export const setCookie = (name: string, value: any, options: CookieSetOptions = {}): void => { options = { path: `/`, ...options, }; if (options.expires instanceof Date) { options.expires = options.expires.toUTCString(); } let updatedCookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`; for (const optionKey in options) { updatedCookie += `; ${optionKey}`; // @ts-ignore const optionValue = options[optionKey]; if (optionValue !== true) { updatedCookie += `=${optionValue}`; } } document.cookie = updatedCookie; };