plane/app/lib/cookie.ts

17 lines
468 B
TypeScript
Raw Normal View History

2023-04-21 23:30:36 +00:00
export const convertCookieStringToObject = (cookieHeader: string | undefined) => {
const list: any = {};
if (!cookieHeader) return list;
cookieHeader.split(`;`).forEach(function (cookie) {
// eslint-disable-next-line prefer-const
let [name, ...rest] = cookie.split(`=`);
name = name?.trim();
if (!name) return;
const value = rest.join(`=`).trim();
if (!value) return;
list[name] = decodeURIComponent(value);
});
return list;
};