fn

getCookieValue

v0.0.5

Looks up a single cookie in a document.cookie-style string without building a full map — same first-occurrence and verbatim-raw-value semantics as parseCookieString, but allocation-free for misses and cheap for hot paths (reactive reads, polling).

Example

ts
getCookieValue('theme=dark; sid=a%3Bb', 'sid'); // 'a;b'

Signature

ts
declare function getCookieValue(cookie: string, name: string, decode?: (value: string) => string): string | null;

Parameters

ParameterTypeDescription
cookiestringThe cookie string to search
namestringThe raw (decoded) cookie name to look up
decode?(value: string) => stringThe raw (decoded) cookie name to look up

Returns

string | nullThe cookie value, or null when absent