Readme

parse_cookies

Parses Cookie headers into objects.

  • jar: Value of the Cookie header
  • decoder: Function to run on all cookie names and values. This is to get around character limitations (see RFC 6265). There is no formal standard, but as most sites prefer URL encoding, it is the default. x => x can be used as a way to disable decoding.
1
2
3
4
5
6
export function parse_cookies(
jar: String,
decoder: (data: string) => string = decodeURIComponent,
): { [key: string]: string } {
return Object.fromEntries(jar.split("; ").map(c => c.split("=").map(x => decoder(x.trim()))));
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 24, 2023