function parseCookie
Since 0.2.0
parseCookie(header: string | null | undefined): Record<string, string>

Parses a Cookie request header into a name→value record.

Values are percent-decoded, mirroring serializeCookie's encoding so that the two round-trip. A value that is not valid percent-encoding is returned verbatim rather than throwing, because a malformed cookie is a client concern. Pairs without = are skipped, and when a name repeats the first occurrence wins — browsers send the most specific cookie first.

Examples

Example 1

parseCookie('sid=abc; theme=dark');
// → { sid: 'abc', theme: 'dark' }

Parameters

header: string | null | undefined

The raw Cookie header value; null/undefined when absent

Return Type

Record<string, string>

Parsed cookies, empty when the header is absent or holds no valid pairs

Usage

import { parseCookie } from "common/src/index.ts";