Website/utils/cookies.ts

19 lines
534 B
TypeScript
Raw Normal View History

2024-08-29 13:20:28 +00:00
export function getCookie(name: string): string | null {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2)
return decodeURIComponent(parts.pop()?.split(';').shift()!) || null;
return null;
}
export function getCookieFromContext(name: string, cookie: string): string | null {
const value = `; ${cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2)
return decodeURIComponent(parts.pop()?.split(';').shift()!) || null;
return null;
}