js-cookie

A simple, lightweight JavaScript API for handling browser cookies, client-side.

Library
npm
v3.0.8
22,570 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
82 /100 Excellent
Development Activity 84
Maintenance 68
Community 76
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
89 /100 Excellent
Architecture 88
Code Quality 90
Innovation 85
Learning Curve 95

js-cookie is a tiny, dependency-free JavaScript library that provides a clean, ergonomic API for creating, reading, and deleting HTTP cookies in the browser. It wraps the awkward document.cookie string interface behind straightforward set, get, and remove methods, handling encoding, attribute serialization, and RFC 6265 compliance automatically.

At under 800 bytes gzipped with no dependencies, it supports ES modules, AMD, and CommonJS, works across an extensive range of browsers, and lets you configure attribute defaults, per-call attributes, and custom encoding/decoding converters. It has become one of the most widely used cookie utilities in the JavaScript ecosystem, downloaded tens of millions of times each week.

What You Get

  • A minimal Cookies API with set, get, remove, withAttributes, and withConverter methods
  • Automatic RFC 6265-compliant encoding and decoding of cookie names and values
  • Configurable cookie attributes: expires, path, domain, secure, sameSite, and partitioned
  • Custom read/write converters for interoperability with cookies written by other systems
  • ES module, UMD, and CommonJS builds plus a namespace-conflict-safe noConflict mode

Common Use Cases

  • Persisting user preferences such as theme, language, or dismissed banners across sessions
  • Storing lightweight client-side state like feature flags or onboarding progress
  • Reading server-set cookies (e.g. CSRF tokens or session identifiers) from JavaScript
  • Managing consent and tracking opt-in/opt-out flags with explicit expiry control

Under The Hood

Architecture

js-cookie is built from three small ES modules in src/. api.mjs contains an init(converter, defaultAttributes) factory that closes over the active converter and default attributes and returns a frozen API object created via Object.create, exposing set, get, remove, withAttributes, and withConverter. set merges attributes with assign.mjs, converts numeric expires values to Date UTC strings, percent-encodes the cookie name, serializes attributes into the document.cookie string, and truncates attribute values at the first semicolon per RFC 6265 section 5.2. get splits document.cookie, decodes each name, and lazily builds a jar object, returning a single value or the whole map. converter.mjs holds the default read/write encoders, and the public entry point exports init(defaultConverter, { path: '/' }). The withAttributes and withConverter methods re-invoke init with merged state, giving an immutable, instance-per-configuration design.

Tech Stack

The library is plain ES2015-era JavaScript with no runtime dependencies. It is authored as native .mjs modules and bundled with Rollup (rollup.config.mjs) plus @rollup/plugin-terser into UMD and ES module dist artifacts. Tooling includes ESLint 10, Prettier 3, and a Grunt-driven test harness (Gruntfile.js) running QUnit suites, with Selenium WebDriver and BrowserStack for cross-browser verification and simple-git-hooks/nano-staged for pre-commit checks.

Code Quality

The source is exceptionally compact and readable — the entire API is roughly 100 lines. Tests are thorough: test/tests.js (~617 lines) and test/encoding.js (~1170 lines) exercise setting, reading, removal, attribute handling, edge-case encoding, and RFC compliance across real browsers. The get loop guards decoding with a try/catch to skip malformed cookies, and assign.mjs explicitly skips __proto__ to avoid prototype pollution. Immutability is enforced via Object.freeze on attributes and converters. There are no TypeScript types in-repo (types ship separately as @types/js-cookie).

API Design

The developer experience is a key strength: three intuitively named core methods, sensible defaults (site-wide path: '/'), and progressive configuration through withAttributes and withConverter that return new instances rather than mutating global state. Getting started requires a single import and one call. Documentation is extensive, covering every attribute, encoding behavior, converters, and namespace-conflict handling. The main friction points are cookie-removal gotchas (attributes must match those used to set) which the README calls out explicitly.

Used by 40 apps in this directory

TypeScript
85%
MIT

LibreChat

AI Assistants · Developer Tools

46,236

Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.

View details
93
Repo Health
81
Technical
62
Dependency
Built with
TypeScript 85%
JavaScript 14%
Updated 5 days ago
JavaScript
42%
Other

LimeSurvey

Forms Surveys

3,778

The world's most flexible open-source survey platform with 900+ templates, conditional logic, 80+ languages, and full GDPR compliance for any scale.

View details
86
Repo Health
62
Technical
62
Dependency
Built with
JavaScript 42%
PHP 36%
CSS 12%
Updated 5 days ago
Python
62%
Apache 2.0

marimo

Data Engineering · Developer Tools

23,309

A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.

View details
90
Repo Health
91
Technical
65
Dependency
Built with
Python 62%
TypeScript 37%
Updated 5 days ago
Svelte
32%
GPL 3.0

Mathesar

Databases

5,158

Spreadsheet-like interface for your PostgreSQL database — self-hosted, no SQL required, native Postgres access control.

View details
70
Repo Health
80
Technical
68
Dependency
Built with
Svelte 32%
TypeScript 27%
Python 21%
Updated 6 days ago
Clojure
57%
Other

Metabase

Analytics

49,827

The open-source BI platform that lets anyone ask questions and build dashboards without writing SQL — with an embedded analytics SDK and AI-powered query assistant included.

View details
95
Repo Health
84
Technical
62
Dependency
Built with
Clojure 57%
TypeScript 38%
Updated 5 days ago
TypeScript
98%
Other

Novu

Developer Tools

40,195

Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.

View details
93
Repo Health
80
Technical
64
Dependency
Built with
TypeScript 98%
Updated 5 days ago
Python
64%
Other

Onyx

AI Agents · AI Assistants · Knowledge Management

32,935

Self-hostable AI platform with agentic RAG, 50+ connectors, deep research, code execution, and support for every major LLM provider.

View details
92
Repo Health
83
Technical
68
Dependency
Built with
Python 64%
TypeScript 26%
Updated 5 days ago
TypeScript
39%
AGPL 3.0

OpenObserve

Analytics · Devops · Monitoring

22,475

Open source observability platform for logs, metrics, traces, and real user monitoring — delivering 140x lower storage costs than Elasticsearch with a single binary you can run in under 2 minutes.

View details
90
Repo Health
9
Technical
68
Dependency
Built with
TypeScript 39%
Rust 30%
Vue 17%
Updated 5 days ago
TypeScript
82%
Apache 2.0

Palmr.

File Storage · Security

2,395

Self-hosted, privacy-focused file sharing without limits

View details
57
Repo Health
62
Technical
68
Dependency
Built with
TypeScript 82%
MDX 13%
Updated 1 weeks ago

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