{"name":"set-cookie-parser","version":"2.7.2","keywords":["set-cookie","set","cookie","cookies","header","parse","parser"],"author":{"url":"http://nfriedly.com/","name":"Nathan Friedly"},"license":"MIT","_id":"set-cookie-parser@2.7.2","maintainers":[{"name":"nfriedly","email":"nathan@nfriedly.com"}],"homepage":"https://github.com/nfriedly/set-cookie-parser","bugs":{"url":"https://github.com/nfriedly/set-cookie-parser/issues"},"dist":{"shasum":"ccd08673a9ae5d2e44ea2a2de25089e67c7edf68","tarball":"http://registry-npm.ywwl.com/set-cookie-parser/download/set-cookie-parser-2.7.2.tgz","fileCount":4,"integrity":"sha512-oeM1lpU/UvhTxw+g3cIfxXHyJRc/uidd3yK1P242gzHds0udQBYzs3y8j4gCCW+ZJ7ad0yctld8RYO+bdurlvw==","signatures":[{"sig":"MEQCIEfd6jT/YbFe7SRO4DV+XxfuQOPq2sS3utiUKuT+4DTtAiBDpv7jmu1BHTP3Ea8IH48h1MJzVqknn8PeAfVz/LARZw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/set-cookie-parser@2.7.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":16454,"size":6185,"noattachment":false,"key":"/set-cookie-parser/-/set-cookie-parser-2.7.2.tgz"},"main":"./lib/set-cookie.js","gitHead":"6e0577b39bddeb2ca30c6c6332f2abfccea51906","scripts":{"lint":"eslint . --ignore-pattern '!.eslintrc.js'","test":"npm run lint && mocha","autofix":"npm run lint -- --fix","precommit":"npm test"},"_npmUser":{"name":"nfriedly","email":"nathan@nfriedly.com"},"prettier":{"trailingComma":"es5"},"repository":{"url":"git+https://github.com/nfriedly/set-cookie-parser.git","type":"git"},"_npmVersion":"10.9.3","description":"Parses set-cookie headers into objects","directories":{},"sideEffects":false,"_nodeVersion":"22.20.0","_hasShrinkwrap":false,"devDependencies":{"husky":"^9.0.11","mocha":"^10.3.0","sinon":"^17.0.1","eslint":"^8.57.0","prettier":"^3.2.5","pretty-quick":"^4.0.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.1.3"},"_npmOperationalInternal":{"tmp":"tmp/set-cookie-parser_2.7.2_1761594659381_0.16640001876829702","host":"s3://npm-registry-packages-npm-production"},"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":1761594659587,"_cnpm_publish_time":1761594659587,"dist-tags":{"backports":"2.7.3","latest":"4.0.0"}}