MCPcopy Create free account
hub / github.com/angular/angular / parseCookieValue

Function parseCookieValue

packages/common/src/cookie.ts:9–36  ·  view source on GitHub ↗
(cookieStr: string, name: string)

Source from the content-addressed store, hash-verified

7 */
8
9export function parseCookieValue(cookieStr: string, name: string): string | null {
10 name = encodeURIComponent(name);
11
12 for (const cookie of cookieStr.split(';')) {
13 const eqIndex = cookie.indexOf('=');
14 const [cookieName, cookieValue]: string[] =
15 eqIndex == -1 ? [cookie, ''] : [cookie.slice(0, eqIndex), cookie.slice(eqIndex + 1)];
16
17 if (cookieName.trim() !== name) {
18 continue;
19 }
20
21 let value = cookieValue;
22 try {
23 value = decodeURIComponent(cookieValue);
24 } catch {
25 // Fall back to raw cookie value if decoding fails (e.g. malformed percent-encoding).
26 }
27
28 if (value.length > 1 && value[0] === '"' && value[value.length - 1] === '"') {
29 value = value.slice(1, -1);
30 }
31
32 return value;
33 }
34
35 return null;
36}

Callers 3

cookie_spec.tsFile · 0.90
getCookieMethod · 0.85
getTokenMethod · 0.85

Calls 1

indexOfMethod · 0.80

Tested by

no test coverage detected