https://github.com/angular/angular
Raw File
Tip revision: a16e3b8fe1f77b163b0763c263d98f275a6c038c authored by Dylan Hunn on 27 September 2023, 20:21:49 UTC
release: cut the v16.2.7 release
Tip revision: a16e3b8
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