js-cookie is a simple, lightweight JavaScript library designed for handling browser cookies. Currently stable at version 3.0.5, it provides a minimal and dependency-free API for setting, getting, and deleting cookies. It supports ES Modules, CommonJS, and AMD, and is compatible with all major browsers. The library is RFC 6265 compliant and known for its small footprint (under 800 bytes gzipped). Releases appear to be somewhat infrequent but consistent, with bug fix releases for the 3.x series. Its key differentiator is its small size and lack of dependencies, focusing solely on efficient client-side cookie management without extra features, making it ideal for browser environments.
npm install js-cookieVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to set, get, and remove cookies using js-cookie, including options for expiration, path, and secure flag, and highlights important considerations for cookie deletion.
Refactor code to use `Cookies.withAttributes()` to create API instances with predefined attributes. Example: `const api = Cookies.withAttributes({ path: '/', secure: true }); api.set('key', 'value');`Ensure `Cookies.remove('name', { path: '/specific-path', domain: '.example.com' });` includes all relevant attributes that were specified during the cookie's creation.Understand that cookie visibility for reading is determined by the browser based on the current URL, not by attributes passed to `get()`. Ensure cookies are set with appropriate `path` and `domain` for the desired visibility.
Thoroughly test cookie interactions after upgrading, especially if your application relies on specific encoding behaviors from pre-v3 versions or interacts with backend systems with strict encoding expectations. No direct code fix is typically required, but awareness is crucial.
Use `Cookies.withAttributes({ expires: 7, path: '/' })` to create a new API instance with predefined attributes instead of setting global defaults.For browser-only usage, either include the library via a `<script>` tag and access `window.Cookies` globally, or use an ES module `import Cookies from 'js-cookie';` with a compatible bundler setup.
Ensure that `Cookies.remove('myCookie', { path: '/specific-path', domain: '.example.com' });` includes all relevant attributes (`path`, `domain`) that were used when the cookie was initially created.Use the default import syntax: `import Cookies from 'js-cookie';`
No dependency data recorded yet.