{"_id":"set-cookie-parser@3.2.2","bugs":{"url":"https://github.com/nfriedly/set-cookie-parser/issues"},"dist":{"shasum":"e1aded19f953adcc2a7bc2904837c32067df46a8","tarball":"http://registry-npm.ywwl.com/set-cookie-parser/download/set-cookie-parser-3.2.2.tgz","fileCount":7,"integrity":"sha512-df017qMeYuXo4emL09nlyMpi2i2MtEIKS/6jtXH3vmjFgIRsOi852/5RmhJ4EkvN3ZF8jXadM/EkTPXgc8yPIw==","signatures":[{"sig":"MEUCIHfVaAeVs+ylj8zzHT20YL7qfEnlmS92fr/b7pCYTgP9AiEAmt3FEhkjO7fvg/nQGv1jfBK4lUPv8R5C06Bk6Concjc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHNBs1yrjZT6DQnWQn6BrtH38jQ3si5GIEBQkDDSqxu/AiBIk7CcV+FmKwNFnoM4NRUOxUsxsh+XvXsSNIAt4XLHSg=="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/set-cookie-parser@3.2.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":31474,"size":8066,"noattachment":false,"key":"/set-cookie-parser/-/set-cookie-parser-3.2.2.tgz"},"main":"./dist/set-cookie.cjs","name":"set-cookie-parser","type":"module","types":"./lib/set-cookie.d.ts","author":{"url":"http://nfriedly.com/","name":"Nathan Friedly"},"module":"./lib/set-cookie.js","exports":{".":{"types":"./lib/set-cookie.d.ts","import":"./lib/set-cookie.js","require":"./dist/set-cookie.cjs","module-sync":"./lib/set-cookie.js"}},"gitHead":"36f53c3a4928ce6045d72cf491e81f823b187a78","license":"MIT","scripts":{"lint":"eslint . --ignore-pattern '!.eslintrc.js'","test":"npm run build && npm run lint && mocha && npm run typecheck","build":"node ./build-cjs.js","format":"npm run lint -- --fix","autofix":"npm run lint -- --fix","prepare":"husky","typecheck":"tsd"},"version":"3.2.2","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"32175cf7-d8a0-451b-80e6-3ca7bb446fb8"}},"homepage":"https://github.com/nfriedly/set-cookie-parser","keywords":["set-cookie","set","cookie","cookies","header","parse","parser"],"prettier":{"trailingComma":"es5"},"repository":{"url":"git+https://github.com/nfriedly/set-cookie-parser.git","type":"git"},"_npmVersion":"11.19.1","description":"Parses set-cookie headers into objects","directories":{},"maintainers":[{"name":"nfriedly","email":"nathan@nfriedly.com"}],"sideEffects":false,"_nodeVersion":"24.22.1","_hasShrinkwrap":false,"devDependencies":{"tsd":"^0.33.0","husky":"^9.1.7","mocha":"^12.0.0","sinon":"^21.0.3","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":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/set-cookie-parser_3.2.2_1793374857252_0.47963491362835275"},"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\nUnknown attributes are added to the object automatically unless there's a conflict, in which case a warning is logged. (See [Errors and Warnings](#errors-and-warnings) section below.)\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 various warnings and errors that would otherwise be logged\n    split: 'auto',      // Separate combined cookie headers. Valid options are true/false/'auto'. 'auto' splits strings but not arrays.\n}\n```\n\n## Errors and Warnings\n\nThe library detects and logs (via `console.warn()` and `console.error()`) a variety of conditions, including:\n\n* Calling `parseSetCookie` on a request object with a `Cookie:` header rather than a `Set-Cookie:` header.\n    * An empty array or object is returned.\n* Any cookie where calling `decodeURIComponent()` on the `value` fails.\n    * The original un-decoded value is used.\n    * Set `options.decodeValues=false` to prevent automatic decoding.\n* Cookies with a name that could cause a conflict in JavaScript, such as `__proto__`.\n    * These cookies are dropped entirely.\n* Cookies attributes named `name` or `value` (because these would overwrite the actual name and value), or something like `__proto__`.\n    * These attributes are dropped, but the rest of the cookie is returned.\n* An `expires` or `max-age` time that cannot be parsed\n    * Attribute is dropped, the rest of the cookie is returned.\n\nSetting `options.silent=true` suppresses these and future warnings without changing the behavior of the library.\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":1793374857346,"_cnpm_publish_time":1793374857346,"dist-tags":{"backports":"2.7.3","latest":"4.0.0"}}