MCPcopy Create free account
hub / github.com/dailydotdev/apps / getCookies

Function getCookies

packages/shared/src/lib/cookie.ts:13–36  ·  view source on GitHub ↗
(
  names: T,
)

Source from the content-addressed store, hash-verified

11};
12
13export const getCookies = <
14 T extends string[] = string[],
15 R = Record<T[number], string>,
16>(
17 names: T,
18): R | undefined => {
19 const cookies =
20 globalThis?.document?.cookie?.split(';')?.map((cookie) => cookie.trim()) ||
21 [];
22 if (!cookies.length) {
23 return undefined;
24 }
25
26 return names.reduce((acc, name) => {
27 const foundCookie = cookies.find((cookie) => cookie.startsWith(`${name}=`));
28 if (!foundCookie) {
29 return acc;
30 }
31 return {
32 ...acc,
33 [name]: decodeURIComponent(foundCookie.split('=')[1]),
34 };
35 }, {} as R);
36};
37
38export const setCookie = (
39 name: string,

Callers 9

getConsentCookiesFunction · 0.90
getCookieFunction · 0.90
getIubendaConsentFunction · 0.90
getStoredTcStringFunction · 0.90
hasMarketingConsentFunction · 0.90
setBrowserCookieFunction · 0.90
useLogSharedPropsFunction · 0.90

Calls

no outgoing calls

Tested by 1

getConsentCookiesFunction · 0.72