{"name":"set-cookie-parser","version":"3.1.2","description":"Parses set-cookie headers into objects","homepage":"https://github.com/nfriedly/set-cookie-parser","repository":{"type":"git","url":"git+https://github.com/nfriedly/set-cookie-parser.git"},"author":{"name":"Nathan Friedly","url":"http://nfriedly.com/"},"main":"./dist/set-cookie.cjs","module":"./lib/set-cookie.js","types":"./lib/set-cookie.d.ts","type":"module","exports":{".":{"types":"./lib/set-cookie.d.ts","module-sync":"./lib/set-cookie.js","import":"./lib/set-cookie.js","require":"./dist/set-cookie.cjs"}},"sideEffects":false,"keywords":["set-cookie","set","cookie","cookies","header","parse","parser"],"devDependencies":{"eslint":"^8.57.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.1.3","husky":"^9.1.7","mocha":"^11.7.5","prettier":"^3.2.5","pretty-quick":"^4.0.0","sinon":"^21.0.3","tsd":"^0.33.0"},"scripts":{"lint":"eslint . --ignore-pattern '!.eslintrc.js'","test":"npm run build && npm run lint && mocha && npm run typecheck","typecheck":"tsd","autofix":"npm run lint -- --fix","format":"npm run lint -- --fix","build":"node ./build-cjs.js","prepare":"husky"},"license":"MIT","prettier":{"trailingComma":"es5"},"gitHead":"60b9d7f2b2a029238676bb0c34cd1a324198c766","_id":"set-cookie-parser@3.1.2","bugs":{"url":"https://github.com/nfriedly/set-cookie-parser/issues"},"_nodeVersion":"24.18.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-5/r/lTwbJ3zQ+qwdUFZYeRNqda7P5HD8zQKqlSjdGt1/S0cjLAphHusj4Y58ahDtWn/g32xrIS58/ikOvwl0Lw==","shasum":"f4e490298759d756a68eabcbcd0fc9261ad0fee0","tarball":"http://registry-npm.ywwl.com/set-cookie-parser/download/set-cookie-parser-3.1.2.tgz","fileCount":7,"unpackedSize":27291,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/set-cookie-parser@3.1.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCfBRetiLbX0FOqPHSfTRZQvY8WSmiznmAIKV3W9H3FDgIhAKh5EkwUSACbYofS7zjcjIVGvOLcO8cLEEPUhEgT5NWP"}],"size":7116,"noattachment":false,"key":"/set-cookie-parser/-/set-cookie-parser-3.1.2.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:32175cf7-d8a0-451b-80e6-3ca7bb446fb8"}},"directories":{},"maintainers":[{"name":"nfriedly","email":"nathan@nfriedly.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/set-cookie-parser_3.1.2_1783612084161_0.2595835181693178"},"_hasShrinkwrap":false,"readme":"# set-cookie-parser \n\n[![Node.js CI](https://github.com/nfriedly/set-cookie-parser/actions/workflows/node.js.yml/badge.svg)](https://github.com/nfriedly/set-cookie-parser/actions/workflows/node.js.yml)\n[![NPM version][npm-image]][npm-url] \n[![npm downloads](https://img.shields.io/npm/dm/set-cookie-parser)][npm-url]\n\n---\n\nParses set-cookie headers into JavaScript objects\n\nAccepts a single `set-cookie` header value, an array of `set-cookie` header values, a Node.js response object, or a `fetch()` `Response` object that may have 0 or more `set-cookie` headers.\n\nReturns either an array of cookie objects or a map of name => cookie object with options set to `{map: true}`. Each cookie object will have `name` and `value` properties, and may have additional properties depending on the set-cookie header:\n\n* `name` - cookie name (string)\n* `value` - cookie value (string)\n* `path` - URL path to limit the scope to (string or undefined)\n* `domain` - domain to expand the scope to (string or undefined, may begin with \".\" to indicate the named domain or any subdomain of it)\n* `expires` - absolute expiration date for the cookie (Date object or undefined)\n* `maxAge` - relative expiration time of the cookie in seconds from when the client receives it (integer or undefined)\n  * Note: when using with [express's res.cookie() method](http://expressjs.com/en/4x/api.html#res.cookie), multiply `maxAge` by 1000 to convert to milliseconds.\n* `secure` - indicates cookie should only be sent over HTTPs (true or undefined)\n* `httpOnly` - indicates cookie should *not* be accessible to client-side JavaScript (true or undefined)\n* `sameSite` - indicates if cookie should be included in cross-site requests ([more info](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value)) (string or undefined)\n  * Note: valid values are `\"Strict\"`, `\"Lax\"`, and `\"None\"`, but set-cookie-parser copies the value verbatim and does *not* perform any validation.\n* `partitioned` - indicates cookie should be scoped to the combination of 3rd party domain + top page domain ([more info](https://developer.mozilla.org/en-US/docs/Web/Privacy/Privacy_sandbox/Partitioned_cookies)) (true or undefined)\n\n(The output format is loosely based on the input format of https://www.npmjs.com/package/cookie)\n\n## Install\n\n```sh\n$ npm install --save set-cookie-parser\n```\n\n\n## Usage\n\n### Get array of cookie objects\n\n```js\nimport * as http from 'node:http';\nimport { parseSetCookie } from 'set-cookie-parser';\n// or const { parseSetCookie } = require('set-cookie-parser');\n\nhttp.get('http://example.com', function(res) {\n  const cookies = parseSetCookie(res, {\n    decodeValues: true  // default: true\n  });\n\n  cookies.forEach(console.log);\n}\n```\n\nExample output:\n\n```js\n[\n    {\n        name: 'bam',\n        value: 'baz'\n    },\n    {\n        name: 'foo',\n        value: 'bar',\n        path: '/',\n        expires: new Date('Tue Jul 01 2025 06:01:11 GMT-0400 (EDT)'),\n        maxAge: 1000,\n        domain: '.example.com',\n        secure: true,\n        httpOnly: true,\n        sameSite: 'lax'\n    }\n]\n```\n\n### Get map of cookie objects\n\n```js\nimport * as http from 'node:http';\nimport { parseSetCookie } from 'set-cookie-parser';\n// or const { parseSetCookie } = require('set-cookie-parser');\n\nhttp.get('http://example.com', function(res) {\n  const cookies = parseSetCookie(res, {\n    decodeValues: true,  // default: true\n    map: true            // default: false\n  });\n\n  const desiredCookie = cookies['session'];\n  console.log(desiredCookie);\n});\n```\nExample output:\n```js\n{\n    bam: {\n        name: 'bam',\n        value: 'baz'\n    },\n    foo: {\n        name: 'foo',\n        value: 'bar',\n        path: '/',\n        expires: new Date('Tue Jul 01 2025 06:01:11 GMT-0400 (EDT)'),\n        maxAge: 1000,\n        domain: '.example.com',\n        secure: true,\n        httpOnly: true,\n        sameSite: 'lax'\n    }\n}\n```\n\n### Creating a new, modified set-cookie header\n\nThis library can be used in conjunction with the [cookie](https://www.npmjs.com/package/cookie) library to modify and replace set-cookie headers:\n\n```js\nimport * as libCookie from 'cookie';\nimport { parseSetCookie } from 'set-cookie-parser';\n// or const { parseSetCookie } = require('set-cookie-parser');\n\nfunction modifySetCookie(res){\n  // parse the set-cookie headers with this library\n  const cookies = parseSetCookie(res);\n  \n  // modify the cookies here\n  // ...\n  \n  // create new set-cookie headers using the cookie library\n  res.headers['set-cookie'] = cookies.map(function(cookie) {\n      return libCookie.serialize(cookie.name, cookie.value, cookie);\n  });\n}\n```\n\nSee a real-world example of this in [unblocker](https://github.com/nfriedly/node-unblocker/blob/08a89ec27274b46dcd80d0a324a59406f2bdad3d/lib/cookies.js#L67-L85)\n\n## API\n\n### parseSetCookie(input, [options])\n\nParses cookies from a string, array of strings, or a http response object. \nAlways returns an array, regardless of input format. (Unless the `map` option is set, in which case it always returns an object.)\n\nAlso accepts an optional options object. Defaults:\n\n```js\n{\n    decodeValues: true, // Calls decodeURIComponent on each value - default: true\n    map: false,         // Return an object instead of an array - default: false\n    silent: false,      // Suppress the warning that is logged when called on a request instead of a response - default: false\n    split: 'auto',      // Separate combined cookie headers. Valid options are true/false/'auto'. 'auto' splits strings but not arrays.\n}\n```\n\n## References\n\n* [RFC 6265: HTTP State Management Mechanism](https://tools.ietf.org/html/rfc6265)\n* [draft-ietf-httpbis-rfc6265bis-10](https://httpwg.org/http-extensions/draft-ietf-httpbis-rfc6265bis.html)\n\n## License\n\nMIT © [Nathan Friedly](http://www.nfriedly.com/)\n\n\n[npm-image]: https://badge.fury.io/js/set-cookie-parser.svg\n[npm-url]: https://npmjs.org/package/set-cookie-parser\n","publish_time":1783612084332,"_cnpm_publish_time":1783612084332,"dist-tags":{"backports":"2.7.3","latest":"4.0.0"}}