commerce/packages/kibocommerce/lib/prepare-set-cookie.ts
2022-01-14 13:33:59 -05:00

15 lines
461 B
TypeScript

export function prepareSetCookie(name: string, value: string, options: any = {}): string {
const encodedValue = Buffer.from(value).toString('base64')
const cookieValue = [`${name}=${encodedValue}`];
if (options.maxAge) {
cookieValue.push(`Max-Age=${options.maxAge}`);
}
if (options.expires && !options.maxAge) {
cookieValue.push(`Expires=${options.expires.toUTCString()}`);
}
const cookie = cookieValue.join('; ')
return cookie
}