fn
parseCookieString
v0.0.5testedParses a document.cookie-style string ('a=1; b=2') into a
Map of decoded names to values. Keeps the first occurrence per name —
browsers order cookies most-specific-path first, so the first one is the one
a server would use. The raw value is passed to decode verbatim (including
any wrapping quotes) so it matches what the Cookie Store API would report;
the default decoder unwraps quotes and percent-escapes.
Example
ts
parseCookieString('theme=dark; sid=a%3Bb'); // Map { 'theme' => 'dark', 'sid' => 'a;b' }Signature
ts
export function parseCookieString(cookie: string, decode: (value: string) => string = decodeCookieValue): Map<string, string>{ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
cookie | string | The cookie string to parse |
decode? | (value: string) => string | Value decoder; pass the identity function to keep raw encoded values |
Returns
Map<string, string>Decoded name -> value pairs