cookie-es
An ESM-ready, RFC 6265bis-compliant parser and serializer for HTTP Cookie and Set-Cookie headers.
Repository Health
Technical Analysis
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 aCookieheader string into a plain objectparseSetCookie()to parse aSet-Cookieheader into an object with all attributes (Domain, Path, HttpOnly, Secure, SameSite, Max-Age, Partitioned, Priority)serializeCookie()/stringifyCookie()to build aSet-Cookieheader string from name/value/optionssplitSetCookieString()for correctly splitting multiple Set-Cookie values from a combined header- Custom encode/decode hooks and a key
filteroption 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
httpcookie 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) andPriorityattributes - 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.
Used by 2 apps in this directory
Hoppscotch
Developer Tools
A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.
NewsNow
Bookmarks Archiving
Self-hostable news aggregator with an elegant column layout, GitHub OAuth, adaptive scraping intervals, and seamless Cloudflare D1 or SQLite persistence.