{"_id":"browser-cookie-utils","_rev":"4-08cfbe9e6830cd9f956b9a0f95dfafe4","name":"browser-cookie-utils","dist-tags":{"latest":"2.1.0"},"versions":{"1.0.0":{"name":"browser-cookie-utils","version":"1.0.0","keywords":["cookie","browser","utils"],"author":{"name":"Sami Ahmed Siddiqui","email":"samiahmedsiddiqui91@gmail.com"},"license":"MIT","_id":"browser-cookie-utils@1.0.0","maintainers":[{"name":"samiahmedsiddiqui","email":"sami@trunkcode.com"}],"homepage":"https://github.com/samiahmedsiddiqui/browser-cookie-utils#readme","bugs":{"url":"https://github.com/samiahmedsiddiqui/browser-cookie-utils/issues"},"dist":{"shasum":"550fead253472659b9bf3206baec20e792ad9569","tarball":"https://registry.npmjs.org/browser-cookie-utils/-/browser-cookie-utils-1.0.0.tgz","fileCount":7,"integrity":"sha512-XJMvgybzel8raevQNmPmmJLci3hukMVoMP4O6S6R/RjWjlq/eDsLl8IafpHHyAnxEkcNRBImuLHV+JXZMhPN2w==","signatures":[{"sig":"MEUCIFU7gtzkJG45iLtrU2p85RwlWeQlUKNTwVh/0zsSCF6GAiEAvv5cLMq0/bc43MfIK4XKKGkVtiNkbl6cTt+W43Mxl0g=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":10998},"main":"dist/browser-cookie-utils.min.js","type":"module","gitHead":"b09f9016ee611fefe27fa415c3c144a4167fc6a3","scripts":{"lint":"eslint .","build":"node build.js","format":"prettier --write src/**/*.js","lint:fix":"eslint . --fix"},"_npmUser":{"name":"samiahmedsiddiqui","email":"sami@trunkcode.com"},"repository":{"url":"git+https://github.com/samiahmedsiddiqui/browser-cookie-utils.git","type":"git"},"_npmVersion":"11.5.1","description":"Lightweight, dependency-free JavaScript helpers for getting, setting, and deleting browser cookies safely and consistently.","directories":{},"_nodeVersion":"24.6.0","_hasShrinkwrap":false,"devDependencies":{"eslint":"9.39.2","terser":"5.44.1","prettier":"3.7.4","eslint-config-prettier":"10.1.8","eslint-plugin-prettier":"5.5.4"},"_npmOperationalInternal":{"tmp":"tmp/browser-cookie-utils_1.0.0_1766150496704_0.7399251827747695","host":"s3://npm-registry-packages-npm-production"}},"2.0.0":{"name":"browser-cookie-utils","version":"2.0.0","keywords":["cookie","cookies","browser","utils","samesite","secure","frontend","web"],"author":{"name":"Sami Ahmed Siddiqui","email":"samiahmedsiddiqui91@gmail.com"},"license":"MIT","_id":"browser-cookie-utils@2.0.0","maintainers":[{"name":"samiahmedsiddiqui","email":"sami@trunkcode.com"}],"homepage":"https://github.com/samiahmedsiddiqui/browser-cookie-utils#readme","bugs":{"url":"https://github.com/samiahmedsiddiqui/browser-cookie-utils/issues"},"dist":{"shasum":"a3becf418da92d18bf0912b488c36f064ee47626","tarball":"https://registry.npmjs.org/browser-cookie-utils/-/browser-cookie-utils-2.0.0.tgz","fileCount":10,"integrity":"sha512-RWBWml8Ho0SJXJFVHIjj5wGT6o9L8nhkqA48uQrkxBWLZjx2UQz5zB0a0HBSH7iZDcuVDHu7Cf0LrLOmAc6Bcw==","signatures":[{"sig":"MEUCIQCnb+HbnnlxHh/tixu0Qi7PdzdP7gD3QpQ7JQqg0NJRmgIgL/LA02Du2c0T3eF3TEbRy7caeS0SanaIXdx7igLBv64=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":23861},"main":"dist/browser-cookie-utils.cjs.min.js","type":"module","module":"dist/browser-cookie-utils.min.js","exports":{".":{"import":"./dist/browser-cookie-utils.min.js","require":"./dist/browser-cookie-utils.cjs.min.js"}},"gitHead":"bbfe07c8c95af99066e9b16053cefb7f24c4da42","scripts":{"lint":"eslint .","build":"node build.js","format":"prettier --write src/**/*.js","lint:fix":"eslint . --fix"},"_npmUser":{"name":"samiahmedsiddiqui","email":"sami@trunkcode.com"},"repository":{"url":"git+https://github.com/samiahmedsiddiqui/browser-cookie-utils.git","type":"git"},"_npmVersion":"11.6.2","description":"Lightweight, dependency-free JavaScript helpers for getting, setting, and deleting browser cookies with modern browser support.","directories":{},"sideEffects":false,"_nodeVersion":"24.12.0","_hasShrinkwrap":false,"devDependencies":{"eslint":"9.39.2","terser":"5.44.1","prettier":"3.7.4","eslint-config-prettier":"10.1.8","eslint-plugin-prettier":"5.5.4"},"_npmOperationalInternal":{"tmp":"tmp/browser-cookie-utils_2.0.0_1767602243783_0.2657611773799917","host":"s3://npm-registry-packages-npm-production"}},"2.0.1":{"name":"browser-cookie-utils","version":"2.0.1","keywords":["cookie","cookies","browser","utils","samesite","secure","frontend","web"],"author":{"name":"Sami Ahmed Siddiqui","email":"samiahmedsiddiqui91@gmail.com"},"license":"MIT","_id":"browser-cookie-utils@2.0.1","maintainers":[{"name":"samiahmedsiddiqui","email":"sami@trunkcode.com"}],"homepage":"https://github.com/samiahmedsiddiqui/browser-cookie-utils#readme","bugs":{"url":"https://github.com/samiahmedsiddiqui/browser-cookie-utils/issues"},"dist":{"shasum":"b33afc05947ecf1797030173ab2ca6e6c5def9ab","tarball":"https://registry.npmjs.org/browser-cookie-utils/-/browser-cookie-utils-2.0.1.tgz","fileCount":10,"integrity":"sha512-vKuYhw790h9x62BsuU0fFoSLYQq6dJI6w7lzr/YSSD/0ALD5pC/1HYh8Oa+pt/yWtN+p3x1fiQnoHC1TZUTvOw==","signatures":[{"sig":"MEUCIQDq8mhOp+fA078YLLaft0IcUMBqLSQYlaoaFbX+3rOb7AIgYypHP3hucb0aYhC/7ZeZJ0/HG+l49m/PBaKACeGvNeE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":24127},"main":"dist/browser-cookie-utils.cjs.min.js","type":"module","module":"dist/browser-cookie-utils.min.js","exports":{".":{"import":"./dist/browser-cookie-utils.min.js","require":"./dist/browser-cookie-utils.cjs.min.js"}},"gitHead":"4bf9e9f359b674b691a184b5561a306b550402b2","scripts":{"lint":"eslint .","build":"node build.js","format":"prettier --write src/**/*.js","lint:fix":"eslint . --fix"},"_npmUser":{"name":"samiahmedsiddiqui","email":"sami@trunkcode.com"},"repository":{"url":"git+https://github.com/samiahmedsiddiqui/browser-cookie-utils.git","type":"git"},"_npmVersion":"11.6.2","description":"Lightweight, dependency-free JavaScript helpers for getting, setting, and deleting browser cookies with modern browser support.","directories":{},"sideEffects":false,"_nodeVersion":"24.12.0","_hasShrinkwrap":false,"devDependencies":{"eslint":"9.39.2","terser":"5.44.1","prettier":"3.7.4","eslint-config-prettier":"10.1.8","eslint-plugin-prettier":"5.5.4"},"_npmOperationalInternal":{"tmp":"tmp/browser-cookie-utils_2.0.1_1769014407455_0.11253788007985821","host":"s3://npm-registry-packages-npm-production"}},"2.1.0":{"_id":"browser-cookie-utils@2.1.0","bugs":{"url":"https://github.com/samiahmedsiddiqui/browser-cookie-utils/issues"},"dist":{"shasum":"33d47fa0f14ef3dd0c352affa5b4e2da68502cdc","tarball":"https://registry.npmjs.org/browser-cookie-utils/-/browser-cookie-utils-2.1.0.tgz","fileCount":12,"integrity":"sha512-Q4D045iIybVqYK5n4H25WpTjZ/nUQgSX+3n97dAb/oOoQBkKTFjCtByUiideEubxSvXeys9d2pblhEh9w5kCQQ==","signatures":[{"sig":"MEYCIQDsqZXmWV8UoiRn8Uv5msaCjdz1cTLwg+SgJHI1377dkQIhAO7ag8BbfQdmAbzFYCPSyDgOBZ/UTqy4+NMpaGQJPNRY","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCYqxO8qJ8PCsrxpmscRe398fmoB/QbnDo4hkJDWD0HSwIgUKK8Cfs5EO1/Mns2HFVuhu7BrlRU6ejiV2HSkeWJuUk="}],"unpackedSize":105795},"main":"dist/browser-cookie-utils.min.cjs","name":"browser-cookie-utils","type":"module","types":"dist/browser-cookie-utils.d.ts","unpkg":"dist/browser-cookie-utils.umd.js","author":{"url":"https://www.linkedin.com/in/sami-ahmed-siddiqui/","name":"Sami Ahmed Siddiqui","email":"samiahmedsiddiqui91@gmail.com"},"module":"dist/browser-cookie-utils.min.js","exports":{".":{"import":{"types":"./dist/browser-cookie-utils.d.ts","default":"./dist/browser-cookie-utils.min.js"},"default":"./dist/browser-cookie-utils.min.js","require":{"types":"./dist/browser-cookie-utils.d.cts","default":"./dist/browser-cookie-utils.min.cjs"}},"./umd":"./dist/browser-cookie-utils.umd.js","./package.json":"./package.json"},"gitHead":"2e085b058d144217666a5c3f2ad4321cd138e03c","license":"MIT","scripts":{"lint":"eslint .","test":"npm run build && node --test test/*.test.js","build":"node build.js","format":"prettier --write \"src/**/*.{js,ts}\" \"test/**/*.js\" build.js eslint.config.js","docs:dev":"vitepress dev docs","lint:fix":"eslint . --fix","docs:build":"vitepress build docs","docs:preview":"vitepress preview docs","format:check":"prettier --check \"src/**/*.{js,ts}\" \"test/**/*.js\" build.js eslint.config.js","test:browser":"npm run build && playwright test --config test/browser/playwright.config.js","test:coverage":"npm run build && node --test --experimental-test-coverage --test-coverage-include=\"src/**\" --test-coverage-lines=100 --test-coverage-functions=100 --test-coverage-branches=98 test/*.test.js","prepublishOnly":"npm run lint && npm test"},"version":"2.1.0","_npmUser":{"name":"samiahmedsiddiqui","email":"sami@trunkcode.com"},"homepage":"https://samiahmedsiddiqui.github.io/browser-cookie-utils/","jsdelivr":"dist/browser-cookie-utils.umd.js","keywords":["cookie","cookies","browser","utils","samesite","secure","frontend","web"],"repository":{"url":"git+https://github.com/samiahmedsiddiqui/browser-cookie-utils.git","type":"git"},"_npmVersion":"11.16.0","description":"Lightweight, dependency-free JavaScript helpers for getting, setting, and deleting browser cookies with modern browser support.","directories":{},"maintainers":[{"name":"samiahmedsiddiqui","email":"sami@trunkcode.com"}],"sideEffects":false,"_nodeVersion":"24.18.0","_hasShrinkwrap":false,"devDependencies":{"eslint":"10.12.0","terser":"5.51.2","globals":"17.13.0","prettier":"3.9.10","vitepress":"1.6.4","@eslint/js":"10.0.1","@playwright/test":"1.64.1","eslint-config-prettier":"10.1.8","eslint-plugin-prettier":"5.5.7"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/browser-cookie-utils_2.1.0_1792149470779_0.3261927080775171"}}},"time":{"created":"2025-12-19T13:21:36.703Z","modified":"2026-10-16T11:17:51.074Z","1.0.0":"2025-12-19T13:21:36.844Z","2.0.0":"2026-01-05T08:37:23.937Z","2.0.1":"2026-01-21T16:53:27.591Z","2.1.0":"2026-10-16T11:17:50.871Z"},"bugs":{"url":"https://github.com/samiahmedsiddiqui/browser-cookie-utils/issues"},"author":{"url":"https://www.linkedin.com/in/sami-ahmed-siddiqui/","name":"Sami Ahmed Siddiqui","email":"samiahmedsiddiqui91@gmail.com"},"license":"MIT","homepage":"https://samiahmedsiddiqui.github.io/browser-cookie-utils/","keywords":["cookie","cookies","browser","utils","samesite","secure","frontend","web"],"repository":{"url":"git+https://github.com/samiahmedsiddiqui/browser-cookie-utils.git","type":"git"},"description":"Lightweight, dependency-free JavaScript helpers for getting, setting, and deleting browser cookies with modern browser support.","maintainers":[{"name":"samiahmedsiddiqui","email":"sami@trunkcode.com"}],"readme":"# browser-cookie-utils\n\n[![License: MIT][license-image]][license-url]\n[![NPM version][npm-image]][npm-url]\n[![Build][build-image]][build-url]\n[![Downloads][jsdelivr-image]][jsdelivr-url]\n\nLightweight, dependency-free JavaScript helpers for getting, setting, and deleting browser cookies safely and consistently in modern browsers.\n\n📖 **Documentation:** https://samiahmedsiddiqui.github.io/browser-cookie-utils/ · 🗺️ [Roadmap](https://samiahmedsiddiqui.github.io/browser-cookie-utils/roadmap)\n\n## Features\n\n- Zero runtime dependencies\n- Browser-only, but safe to import during SSR (helpers are no-ops without `document`)\n- TypeScript declarations included\n- Simple, ergonomic API\n- Cookie expiration with time units\n- Multi-domain cookie support\n- Automatic Secure flag on HTTPS (and always with `SameSite=None`)\n- SameSite support (`Lax`, `Strict`, `None`)\n- Path customization\n- Safe encoding / decoding\n\n## Installation\n\n### NPM (Modern ESM / CJS)\n\n```sh\nnpm install browser-cookie-utils@2\n```\n\n#### ESM import (modern bundlers):\n\n```js\nimport { setCookie, getCookie, deleteCookie } from 'browser-cookie-utils';\n```\n\n#### CJS import (CommonJS bundlers):\n\n```js\nconst { getCookie, setCookie, deleteCookie } = require('browser-cookie-utils');\n```\n\n### Browser (UMD / CDN)\n\n```html\n<script src=\"https://cdn.jsdelivr.net/npm/browser-cookie-utils@2/dist/browser-cookie-utils.umd.js\"></script>\n```\n\n> Pin the major version (`@2`) so a future breaking release doesn't break your page.\n\n### Available Builds\n\n| File                              | Format     | Notes                                      |\n| --------------------------------- | ---------- | ------------------------------------------ |\n| `browser-cookie-utils.js`         | ESM        | Non-minified, modern bundlers              |\n| `browser-cookie-utils.min.js`     | ESM        | Minified, production-ready (ES module)     |\n| `browser-cookie-utils.cjs`        | CJS        | Non-minified, CommonJS                     |\n| `browser-cookie-utils.min.cjs`    | CJS        | Minified, production-ready                 |\n| `browser-cookie-utils.umd.js`     | UMD        | Minified, `<script>` tag / AMD / CommonJS  |\n| `browser-cookie-utils.d.ts`       | Types      | TypeScript declarations (`.d.cts` for CJS) |\n| `browser-cookie-utils.min.js.map` | Source map | For minified ESM (published to npm only)   |\n\nAll builds use ES2015+ syntax (`const`, arrow functions, template literals), so Internet Explorer is not supported.\n\n> **Note:** Only the UMD build attaches itself to `window.browserCookieUtils`.\n\n## Usage by environment\n\n### ES Modules (recommended)\n\n```js\nimport { getCookie, setCookie, deleteCookie } from 'browser-cookie-utils';\n\nsetCookie('theme', 'dark');\n```\n\n### CommonJS\n\n```js\nconst { getCookie, setCookie, deleteCookie } = require('browser-cookie-utils');\n\nsetCookie('theme', 'dark');\n```\n\n### Browser (script tag / CDN)\n\n```html\n<script src=\"https://cdn.jsdelivr.net/npm/browser-cookie-utils@2/dist/browser-cookie-utils.umd.js\"></script>\n<script>\n\tbrowserCookieUtils.setCookie('theme', 'dark');\n</script>\n```\n\n> The global `browserCookieUtils` is available only when using the UMD build.\n\n## API Usage\n\n### Set a cookie (basic)\n\n```js\nimport { setCookie } from 'browser-cookie-utils';\n\nsetCookie('theme', 'dark');\n```\n\nCreates a cookie with:\n\n- 1 hour expiration\n- `path=/`\n- `SameSite=Lax`\n- `Secure` (automatically on HTTPS)\n\n---\n\n### Check that a cookie was stored\n\nBrowsers drop invalid cookies **silently** (wrong domain, over the ~4 KB size limit, an `HttpOnly` cookie with the same name, an `expires` date in the past, …). `setCookie` returns whether the cookie can be read back with the new value:\n\n```js\nif (!setCookie('theme', 'dark', { domains: ['example.com'] })) {\n\tconsole.warn('Cookie was not stored');\n}\n```\n\n> JavaScript can only read cookies whose `path` matches the current page. A cookie set for another path (e.g. `path: '/admin'` from `/`) is stored by the browser but returns `false`.\n\n---\n\n### Set a cookie with options\n\n```js\nimport { setCookie } from 'browser-cookie-utils';\n\nsetCookie('session', 'abc123', {\n\ttimeToLive: 2,\n\tunit: 'hour'\n});\n```\n\nSupported units:\n\n- `second`, `minute`, `hour`, `day`, `week`\n- `month` (30 days)\n- `year` (365 days)\n\nAn unknown unit falls back to `hour`.\n\n### Exact expiry date\n\n```js\nsetCookie('promo', 'spring', {\n\texpires: new Date('2030-04-01T00:00:00Z')\n});\n```\n\n`expires` overrides `timeToLive` / `unit`. An invalid date is ignored.\n\n### Session cookie\n\n```js\nsetCookie('tab', 'open', { session: true });\n```\n\nNo expiry is set, so the browser removes the cookie when it closes. `session` overrides `expires` and `timeToLive`.\n\n---\n\n### Set cookie with full configuration\n\n```js\nimport { setCookie } from 'browser-cookie-utils';\n\nsetCookie('user', 'sami', {\n\ttimeToLive: 7,\n\tunit: 'day',\n\tdomains: ['example.com', '.example.org'],\n\tpath: '/',\n\tsameSite: 'Lax',\n\tsecure: true\n});\n```\n\n#### Available options\n\n| Option        | Type       | Default          | Description                                   |\n| ------------- | ---------- | ---------------- | --------------------------------------------- |\n| `timeToLive`  | `number`   | `1`              | Expiration duration                           |\n| `unit`        | `string`   | `hour`           | `second` … `year` (see above)                 |\n| `expires`     | `Date`     | —                | Exact expiry; overrides `timeToLive` / `unit` |\n| `session`     | `boolean`  | `false`          | No expiry; overrides `expires`                |\n| `domains`     | `string[]` | current hostname | Domains to set cookie on                      |\n| `path`        | `string`   | `/`              | Cookie path                                   |\n| `sameSite`    | `string`   | `Lax`            | `Lax`, `Strict`, `None`                       |\n| `secure`      | `boolean`  | auto             | Forced Secure flag                            |\n| `partitioned` | `boolean`  | `false`          | Adds `Partitioned` (CHIPS); forces `Secure`   |\n\n> The `domain` attribute is skipped for `localhost` and IP addresses (browsers reject it there), so a host-only cookie is set instead.\n\n> Cookie names must be valid RFC 6265 tokens (no spaces, `;`, `=`, etc.). Invalid names are ignored.\n\n### Partitioned cookies (CHIPS)\n\nFor third-party embeds (widgets, iframes) in browsers that block third-party cookies:\n\n```js\nimport { setCookie, deleteCookie } from 'browser-cookie-utils';\n\nsetCookie('__Host-widget', 'abc', { partitioned: true }); // SameSite=None by default\n\n// Deleting a partitioned cookie needs `partitioned: true` too.\ndeleteCookie('__Host-widget', { partitioned: true });\n```\n\nThe cookie is stored separately for each top-level site the embed appears on. `Secure` is always added. Browsers without CHIPS support ignore the attribute.\n\n### Cookie prefixes (`__Secure-` / `__Host-`)\n\nBrowsers enforce extra rules for cookies whose names start with these prefixes, and silently reject cookies that break them. The library applies the rules for you in `setCookie`, `deleteCookie` and `deleteCookies`:\n\n| Prefix      | Rules applied                                                         |\n| ----------- | --------------------------------------------------------------------- |\n| `__Secure-` | `Secure` is always set                                                |\n| `__Host-`   | `Secure` is always set, `path=/`, and no `domain` (`domains` ignored) |\n\n```js\nimport { setCookie } from 'browser-cookie-utils';\n\nsetCookie('__Host-session', 'abc123', { timeToLive: 1, unit: 'day' });\n```\n\n> Prefixed cookies can only be set from secure pages (HTTPS or `localhost`). Prefixes are matched case-insensitively.\n\n### Cross-site cookies (SameSite=None)\n\n```js\nimport { setCookie } from 'browser-cookie-utils';\n\nsetCookie('crossSite', 'true', {\n\tsameSite: 'None',\n\tsecure: true\n});\n```\n\n> ⚠️ Browsers **require `Secure`** when using `SameSite=None`.\n\n## JSON cookies\n\n```js\nimport { setJSONCookie, getJSONCookie } from 'browser-cookie-utils';\n\nsetJSONCookie('prefs', { theme: 'dark', fontSize: 14 }, { unit: 'month' });\n\ngetJSONCookie('prefs'); // { theme: 'dark', fontSize: 14 }\n```\n\n- `setJSONCookie(name, value, options)` takes the same options as `setCookie`. Nothing is written if the value can't be serialized (circular references, `BigInt`, `undefined`, functions).\n- `getJSONCookie(name)` returns the parsed value, or `null` if the cookie is missing or isn't valid JSON.\n- In TypeScript, pass the expected type: `getJSONCookie<Prefs>('prefs')`.\n\n> Browsers limit each cookie to about 4 KB **after** URI encoding, and JSON grows when encoded. Keep JSON cookies small.\n\n## Get a cookie\n\n```js\nimport { getCookie } from 'browser-cookie-utils';\n\nconst theme = getCookie('theme');\n```\n\nReturns:\n\n- `string` if found (URI-decoded; returned raw if it isn't valid URI encoding)\n- `null` if not found\n\n## Check if a cookie exists\n\n```js\nimport { hasCookie } from 'browser-cookie-utils';\n\nif (hasCookie('consent')) {\n\t// ...\n}\n```\n\nReturns `true` when the cookie exists, **even if its value is empty**. Use it instead of `getCookie(name) !== null` checks when an empty value is meaningful.\n\n## Get all cookies\n\n```js\nimport { getAllCookies } from 'browser-cookie-utils';\n\ngetAllCookies(); // { theme: 'dark', lang: 'en' }\n```\n\nReturns an object of name → decoded value for every cookie visible to JavaScript (`HttpOnly` cookies are never included). Returns `{}` when there are none.\n\n> If the same name exists on several paths, the browser lists the most specific path first, and that value is used (same as `getCookie`).\n\n## Get cookies by pattern\n\n```js\nimport { getCookies } from 'browser-cookie-utils';\n\ngetCookies('pref_*'); // glob: * matches any characters, ? matches one\ngetCookies(/^utm_/); // RegExp\ngetCookies((name) => name.startsWith('ab_')); // predicate\n```\n\nReturns an object with only the matching cookies.\n\n## Delete a cookie\n\n```js\nimport { deleteCookie } from 'browser-cookie-utils';\n\ndeleteCookie('theme');\n```\n\n### Delete with options (recommended)\n\n```js\nimport { deleteCookie } from 'browser-cookie-utils';\n\ndeleteCookie('user', {\n\tdomains: ['example.com'],\n\tpath: '/',\n\tsameSite: 'Lax',\n\tsecure: true\n});\n```\n\n> ⚠️ For deletion to succeed, `domains` and `path` **must match** the ones used when the cookie was set.\n\nWithout `domains`, `deleteCookie` removes both the host-only cookie and the domain cookie for the current hostname.\n\n`deleteCookie` returns `true` if no cookie with that name is readable afterwards, so you can detect a mismatch.\n\n## Delete cookies by pattern\n\n```js\nimport { deleteCookies } from 'browser-cookie-utils';\n\ndeleteCookies('_ga*'); // glob: * matches any characters, ? matches one\ndeleteCookies(/^utm_/); // RegExp\ndeleteCookies((name) => name.startsWith('tmp_')); // predicate\ndeleteCookies('*'); // every cookie visible to JavaScript\n```\n\nPaths are tried with and without a trailing slash (`/a`, `/a/`).\n\nReturns an array with the names of matching cookies that **still exist** afterwards (an empty array means everything matched was deleted).\n\nJavaScript can't read a cookie's domain or path, so by default each matching cookie is expired:\n\n- as a host-only cookie and on the current hostname and each parent domain (`app.example.com`, `example.com`)\n- for `/` and each prefix of the current path (`/`, `/a`, `/a/b`)\n\nPass `domains` and/or `paths` to try specific values only:\n\n```js\ndeleteCookies('session_*', {\n\tdomains: ['example.com'],\n\tpaths: ['/', '/app']\n});\n```\n\n> `HttpOnly` cookies are not visible to JavaScript and can't be deleted.\n\n> **Browser (UMD) usage:**\n> When using the UMD build via a `<script>` tag, replace imported functions with\n> `browserCookieUtils.*`.\n\n## Default options (`createCookieUtils`)\n\nCreate the helpers once with your defaults instead of repeating them in every call:\n\n```js\nimport { createCookieUtils } from 'browser-cookie-utils';\n\nconst cookies = createCookieUtils({\n\tdomains: ['example.com'],\n\tsameSite: 'Strict',\n\tunit: 'day'\n});\n\ncookies.setCookie('theme', 'dark'); // uses the defaults\ncookies.setCookie('lang', 'en', { sameSite: 'Lax' }); // overrides one option\ncookies.deleteCookie('theme');\n```\n\nThe returned object has the same helpers as the module (`getCookie`, `hasCookie`, `getAllCookies`, `getCookies`, `setCookie`, `getJSONCookie`, `setJSONCookie`, `deleteCookie`, `deleteCookies`). Options passed to a single call override the defaults.\n\n### Name prefix\n\nUse `namePrefix` to keep your app's cookies separate from others on the same domain:\n\n```js\nconst appCookies = createCookieUtils({ namePrefix: 'myapp_' });\n\nappCookies.setCookie('theme', 'dark'); // writes `myapp_theme`\nappCookies.getCookie('theme'); // reads `myapp_theme`\nappCookies.getAllCookies(); // { theme: 'dark' } — only `myapp_*`, prefix removed\nappCookies.deleteCookies('*'); // deletes only `myapp_*` cookies\n```\n\n## Migration Guide (v1.x → v2.0.0)\n\nVersion `2.0.0` introduces a **breaking API change** to improve flexibility and align with modern browser cookie requirements.\n\n### What changed?\n\nThe `setCookie` and `deleteCookie` functions now accept an **options object** instead of positional arguments.\n\n---\n\n### `setCookie` migration\n\n#### Before (v1.x):\n\n```js\nbrowserCookieUtils.setCookie('theme', 'dark', 2, 'day', ['.example.com']);\n```\n\n#### After (v2.0.0):\n\n```js\nbrowserCookieUtils.setCookie('theme', 'dark', {\n\ttimeToLive: 2,\n\tunit: 'day',\n\tdomains: ['.example.com']\n});\n```\n\n### `deleteCookie` migration\n\n#### Before (v1.x):\n\n```js\nbrowserCookieUtils.deleteCookie('theme', ['.example.com']);\n```\n\n#### After (v2.0.0):\n\n```js\nbrowserCookieUtils.deleteCookie('theme', {\n\tdomains: ['.example.com']\n});\n```\n\n### Why the change?\n\n- Clearer, self-documenting API\n- Easier future extensions\n- Better alignment with modern cookie attributes (SameSite, Secure, path)\n\nIf you need the old behavior, continue using `v1.x`, which remains stable.\n\n## Security behavior\n\n- Automatically adds `Secure` on HTTPS, with `SameSite=None` and with `Partitioned`\n- Values are encoded with `encodeURIComponent`, so they can't add attributes\n- `sameSite` only accepts `Lax`, `Strict` or `None`; anything else becomes `Lax`\n- `path` must start with `/` and can't contain spaces, control characters or `;`. Nothing is written for an unsafe path\n- Invalid `domains` are skipped. If none is usable, nothing is written and `setCookie` returns `false`\n- Glob patterns (`*`, `?`) are matched in linear time. **RegExp patterns you pass are run as-is**, so avoid patterns that can backtrack heavily (e.g. `/^(a+)+$/`)\n- `getJSONCookie` drops `__proto__` keys, so merging the result can't change prototypes\n- Lifetimes are capped at 400 days by the library. Chromium and Firefox cap at 400 days; WebKit caps lower, and Safari limits cookies set from JavaScript to 7 days (ITP)\n- Does **not** set `HttpOnly` (not possible via JavaScript)\n\n### Recommendations\n\n- **Don't store secrets** (session tokens, credentials) in cookies set from JavaScript. Any script on the page can read them. Set them server-side with `HttpOnly`.\n- **Subdomains:** by default the cookie is set on the current hostname as a domain cookie, so its subdomains can read it too. For a cookie only the current host can see, use the `__Host-` prefix.\n- **Cookie tossing:** a sibling subdomain can set a same-name cookie on the parent domain, and `getCookie` may return it. Treat cookie values as untrusted input, and use `__Host-` names for anything security-sensitive.\n\n## Browser support\n\n- All modern evergreen browsers\n- Works without polyfills\n- No reliance on deprecated APIs\n\n## Author\n\n**Sami Ahmed Siddiqui**\n\n- GitHub: [@samiahmedsiddiqui](https://github.com/samiahmedsiddiqui)\n- LinkedIn: [sami-ahmed-siddiqui](https://www.linkedin.com/in/sami-ahmed-siddiqui/)\n\nQuestions and bug reports: please use [GitHub Issues](https://github.com/samiahmedsiddiqui/browser-cookie-utils/issues). Security issues: see [SECURITY.md](SECURITY.md).\n\n## License\n\nMIT © [Sami Ahmed Siddiqui](https://github.com/samiahmedsiddiqui)\n\n[build-image]: https://img.shields.io/github/actions/workflow/status/samiahmedsiddiqui/browser-cookie-utils/ci.yml\n[build-url]: https://github.com/samiahmedsiddiqui/browser-cookie-utils/actions\n[npm-image]: https://img.shields.io/npm/v/browser-cookie-utils.svg\n[npm-url]: https://www.npmjs.com/package/browser-cookie-utils\n[license-image]: https://img.shields.io/badge/License-MIT-green.svg\n[license-url]: LICENSE\n[jsdelivr-image]: https://img.shields.io/jsdelivr/npm/hm/browser-cookie-utils\n[jsdelivr-url]: https://www.jsdelivr.com/package/npm/browser-cookie-utils\n","readmeFilename":"README.md"}