es-cookie is a lightweight, dependency-free JavaScript module designed for managing browser cookies, adhering to RFC 6265 specifications. It provides a simple, type-safe API for setting, getting, removing, and parsing cookies. The library is written in TypeScript and ships with native ES module definitions, making it well-suited for modern web development. The current stable version is 1.5.0, with recent updates including support for experimental `partitioned` cookies and fixes for cookie expiration handling. While originally inspired by `js-cookie`, es-cookie differentiates itself through its TypeScript rewrite, lean API, and explicit focus on ES module distribution, ensuring a modern, tree-shakable approach to cookie management without relying on external packages.
npm install es-cookieVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting a secure, expiring cookie, retrieving individual and all cookies, and correctly removing a cookie by matching attributes, along with parsing a raw cookie string.
Always specify `path` and `domain` options in `Cookies.remove()` if they were provided during `Cookies.set()`. For example, `Cookies.set('name', 'value', { path: '/app' }); Cookies.remove('name', { path: '/app' });`Ensure your project is configured for ES module imports (e.g., `type: "module"` in `package.json` for Node.js, or using a modern bundler like Webpack/Rollup/Vite). Use `import` statements exclusively for `es-cookie`.
Upgrade to `es-cookie@1.5.0` or newer to ensure that cookies with very long `expires` values are handled correctly and expire on the maximum possible date.
When using the `partitioned` attribute, ensure target browsers support CHIPS. Be aware that this is an experimental standard and may evolve.
Change `const Cookies = require('es-cookie');` to `import * as Cookies from 'es-cookie';` and ensure your project is configured for ES modules.Verify and provide the identical `path` and `domain` attributes to `Cookies.remove()` as were used with `Cookies.set()`. For example: `Cookies.remove('myCookie', { path: '/some/path', domain: 'example.com' });`If you intend to use `Cookies.set`, `Cookies.get`, etc., change your import to `import * as Cookies from 'es-cookie';`. Alternatively, use named imports: `import { set, get } from 'es-cookie';`.No dependency data recorded yet.