https://github.com/angular/angular
Raw File
Tip revision: 1fb0dbb30061b7cb84a275a18110f3eb9a107771 authored by Andrew Kushnir on 10 March 2021, 18:03:45 UTC
release: cut the v12.0.0-next.4 release (#41156)
Tip revision: 1fb0dbb
cookie.ts
/**
 * @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.io/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;
}
back to top