js-cookie-next is a native-first, TypeScript-first utility library designed for managing browser cookies with a focus on modern web standards. It transparently supports the Asynchronous Cookie Store API where available and falls back to `document.cookie` for broader compatibility. Currently at version 1.0.1, the library maintains a stable release cadence, with updates primarily driven by new browser features or bug fixes rather than frequent major API changes. Key differentiators include its zero-dependency footprint, small size (< 2 KB gzipped), SSR-safe imports that make sync APIs no-ops in non-browser environments, and built-in support for Partitioned Cookies (CHIPS) via a simple preset option. It prioritizes type safety and a clear API for both synchronous and asynchronous cookie operations, catering to contemporary web development practices.
npm install js-cookie-nextVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates both the synchronous and asynchronous APIs, including setting and getting cookies, removing them, and utilizing advanced options like `partitioned` mode for CHIPS.
Always include `secure: true` when `sameSite: "none"`, e.g., `{ sameSite: "none", secure: true }`.Ensure `remove('key', { path: '/original/path', domain: 'original.domain' })` matches the original set options.For SSR, if cookie management is needed, ensure it's handled by your SSR framework or use server-specific cookie parsing/setting mechanisms. `js-cookie-next` is primarily for client-side use or isomorphic applications that gracefully degrade on the server.
Always test `mode: "partitioned"` in target browsers. Be aware that `sameSite: "none"` still implicitly requires `secure: true` even when using this preset.
The library's sync APIs are designed to be no-ops in SSR. If you encounter this error in a non-browser environment, it indicates a misconfiguration or an attempt to use client-side logic on the server. Consider conditional rendering or ensure code runs only in the browser.
When removing a cookie, ensure that all relevant options (like `path` and `domain`) are identical to those used during the `set()` operation. For example, if set with `set('mycookie', 'value', { path: '/app' })`, remove with `remove('mycookie', { path: '/app' })`.If `sameSite` is `"none"`, you *must* also set `secure: true`. Ensure your site is served over HTTPS when setting `secure` cookies. Also, check for `domain` mismatches if you're attempting cross-subdomain cookies.
No dependency data recorded yet.