cookie-es

An ESM-ready, RFC 6265bis-compliant parser and serializer for HTTP Cookie and Set-Cookie headers.

Library
npm
v3.1.1
253stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
47/100Fair
Development Activity52
Maintenance20
Community40
Maturity56
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
72/100Good
Architecture70
Code Quality75
Innovation60
Learning Curve82

cookie-es parses and serializes the Cookie and Set-Cookie HTTP headers, combining the parsing logic of the popular cookie and set-cookie-parser packages into a single, ESM-first library with built-in TypeScript types. It follows the RFC 6265bis draft spec, including newer attributes like Partitioned and Priority, so it stays current with modern browser cookie behavior.

As part of the unjs ecosystem, it’s built with zero runtime dependencies and ships only ESM output, making it a lightweight fit for edge runtimes, server frameworks, and any code that needs to read or write cookie headers without pulling in a larger HTTP utility belt.

What You Get

  • parseCookie() to turn a Cookie header string into a plain object
  • parseSetCookie() to parse a Set-Cookie header into an object with all attributes (Domain, Path, HttpOnly, Secure, SameSite, Max-Age, Partitioned, Priority)
  • serializeCookie()/stringifyCookie() to build a Set-Cookie header string from name/value/options
  • splitSetCookieString() for correctly splitting multiple Set-Cookie values from a combined header
  • Custom encode/decode hooks and a key filter option for selective cookie parsing
  • Full TypeScript types and ESM-only output with zero runtime dependencies

Common Use Cases

  • Reading and writing cookies in an edge or serverless function without a full Node.js http cookie stack
  • Building a lightweight session or auth layer for a web framework that needs standards-compliant cookie parsing
  • Parsing multiple Set-Cookie headers correctly, including newer Partitioned (CHIPS) and Priority attributes
  • Adding cookie support to a custom HTTP server or middleware without adopting a larger cookie framework

Under The Hood

Architecture cookie-es is a small, focused module: src/index.ts implements the parse/serialize functions directly against the RFC 6265bis grammar, with shared encode/decode and splitting helpers factored into src/_utils.ts, avoiding any dependency on Node’s built-in http cookie handling so it works identically in edge runtimes. Tech Stack It’s a zero-dependency TypeScript library built with unjs’s standard build.config.ts tooling, shipping ESM-only output (dist/index.mjs) with bundled .d.mts type declarations. Code Quality The project has a test/ suite run via Vitest, uses Renovate for automated dependency updates, and Codecov for coverage tracking, and is actively maintained as part of the broader unjs ecosystem shared across many Nitro/h3-based projects. API Design The API is a handful of narrowly-scoped functions (parseCookie, parseSetCookie, serializeCookie, splitSetCookieString) with clear single responsibilities and optional hooks (custom decode/encode, key filtering) rather than one configurable do-everything class, making it easy to import only what’s needed.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search