mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
20 lines
661 B
TypeScript
20 lines
661 B
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.dev/license
|
|
*/
|
|
|
|
export function parseCookieValue(cookieStr: string, name: string): string | null {
|
|
name = encodeURIComponent(name);
|
|
for (const cookie of cookieStr.split(';')) {
|
|
const eqIndex = cookie.indexOf('=');
|
|
const [cookieName, cookieValue]: string[] =
|
|
eqIndex == -1 ? [cookie, ''] : [cookie.slice(0, eqIndex), cookie.slice(eqIndex + 1)];
|
|
if (cookieName.trim() === name) {
|
|
return decodeURIComponent(cookieValue);
|
|
}
|
|
}
|
|
return null;
|
|
}
|