{"name":"content-disposition","version":"2.0.0","keywords":["content-disposition","http","rfc6266","res"],"author":{"name":"Douglas Christopher Wilson","email":"doug@somethingdoug.com"},"license":"MIT","_id":"content-disposition@2.0.0","maintainers":[{"name":"ulisesgascon","email":"ulisesgascondev@gmail.com"},{"name":"blakeembrey","email":"hello@blakeembrey.com"},{"name":"wesleytodd","email":"wes@wesleytodd.com"},{"name":"dougwilson","email":"doug@somethingdoug.com"}],"homepage":"https://github.com/jshttp/content-disposition#readme","bugs":{"url":"https://github.com/jshttp/content-disposition/issues"},"dist":{"shasum":"b39134e5f3fbd52cd95ef2850ef109b5ea331ac4","tarball":"http://registry-npm.ywwl.com/content-disposition/download/content-disposition-2.0.0.tgz","fileCount":6,"integrity":"sha512-qqGFOrKmFP1lTfG24opOJFcTMza1BqyTSUKVbMGUP5uRsBH+C00Q1loOk+JSFshyRE0ji4HtCJeNN2WHWd6PGw==","signatures":[{"sig":"MEYCIQDRnOMB0BlCR+r899QQr7l2QXPwTsy2GpThrDNqEVWGPwIhAL7EPzVdVi0rUnduPDkS9cCKgSL3yp9826g57bKaE2zt","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":48332,"size":11535,"noattachment":false,"key":"/content-disposition/-/content-disposition-2.0.0.tgz"},"main":"./dist/index.js","type":"commonjs","types":"./dist/index.d.ts","engines":{"node":">=18"},"exports":"./dist/index.js","funding":{"url":"https://opencollective.com/express","type":"opencollective"},"gitHead":"cecbb49f858c6e9cb50718483cea6c98b353f42f","scripts":{"demo":"node demo/server.js","lint":"ts-scripts lint","test":"ts-scripts test","bench":"vitest bench","build":"ts-scripts build","specs":"ts-scripts specs","format":"ts-scripts format","prepare":"ts-scripts install && npm run build"},"_npmUser":{"name":"blakeembrey","email":"hello@blakeembrey.com"},"repository":{"url":"git+https://github.com/jshttp/content-disposition.git","type":"git"},"ts-scripts":{"dist":["dist"],"project":["tsconfig.build.json"]},"_npmVersion":"11.13.0","description":"Create and parse Content-Disposition header","directories":{},"_nodeVersion":"26.1.0","_hasShrinkwrap":false,"devDependencies":{"vitest":"^3.2.4","typescript":"^5.9.3","@vitest/coverage-v8":"^3.2.4","@borderless/ts-scripts":"^0.15.0"},"_npmOperationalInternal":{"tmp":"tmp/content-disposition_2.0.0_1778516778111_0.9607236696642176","host":"s3://npm-registry-packages-npm-production"},"readme":"# content-disposition\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Node.js Version][node-version-image]][node-version-url]\n[![Build Status][github-actions-ci-image]][github-actions-ci-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n\nCreate and parse HTTP `Content-Disposition` header\n\n## Installation\n\n```sh\n$ npm install content-disposition\n```\n\n## API\n\n```js\nimport { create, parse, format } from 'content-disposition';\n```\n\n### create(filename, options)\n\nCreate an attachment `Content-Disposition` header value using the given file name,\nif supplied. The `filename` is optional and if no file name is desired, but you\nwant to specify `options`, set `filename` to `undefined`.\n\n```js\nres.setHeader('Content-Disposition', create('∫ maths.pdf'));\n```\n\n**note** HTTP headers are of the ISO-8859-1 character set. If you are writing this\nheader through a means different from `setHeader` in Node.js, you'll want to specify\nthe `'binary'` encoding in Node.js.\n\n#### Options\n\n`contentDisposition` accepts these properties in the options object.\n\n##### fallback\n\nIf the `filename` option is outside US-ASCII, then the file name is actually\nstored in a supplemental field for clients that support Unicode file names and\na US-ASCII version of the file name is automatically generated.\n\nThis specifies the US-ASCII file name to override the automatic generation or\ndisables the generation all together, defaults to `true`.\n\n- A string will specify the US-ASCII file name to use in place of automatic\n  generation.\n- `false` will disable including a US-ASCII file name and only include the\n  Unicode version (unless the file name is already US-ASCII).\n- `true` will enable automatic generation if the file name is outside US-ASCII.\n\nIf the `filename` option is US-ASCII and this option is specified and has a\ndifferent value, then the `filename` option is encoded in the extended field\nand this set as the fallback field, even though they are both US-ASCII.\n\n##### type\n\nSpecifies the disposition type, defaults to `\"attachment\"`. This can also be\n`\"inline\"`, or any other value (all values except inline are treated like\n`attachment`, but can convey additional information if both parties agree to\nit).\n\n### parse(string, options)\n\n```js\nconst disposition = parse(\n  'attachment; filename=\"EURO rates.txt\"; filename*=UTF-8\\'\\'%e2%82%ac%20rates.txt',\n);\n```\n\nParse a `Content-Disposition` header string. This automatically handles extended\n(\"Unicode\") parameters by decoding them and providing them under the standard\nparameter name. This will return an object with the following properties:\n\n- `type`: The disposition type (always lower case). Example: `'attachment'`\n\n- `parameters`: An object of the parameters in the disposition (name of parameter\n  always lower case and extended versions replace non-extended versions). Example:\n  `{filename: \"€ rates.txt\"}`\n\n#### Options\n\n##### multipart\n\nParse parameters using browser `multipart/form-data` behavior.\n\n```js\nparse('form-data; name=\"file\"; filename=\"the %22plans%22.pdf\"', {\n  multipart: true,\n});\n```\n\n##### extended\n\nParse RFC 5987 extended header parameters automatically when decoding\nparameters, defaults to `true`.\n\n### format(obj, options)\n\n```js\nconst disposition = format({\n  type: 'attachment',\n  parameters: {\n    filename: '€ rates.txt',\n  },\n});\n```\n\nFormats an object to a `Content-Disposition` header string. This automatically\nhandles extended (\"Unicode\") parameters and returns a string. Example:\n`'attachment; filename*=UTF-8''%E2%82%AC%20rates.txt'`\n\n#### Options\n\n##### multipart\n\nFormat parameters using browser `multipart/form-data` behavior. This quotes\nparameter values, escapes `\"` as `%22`, and writes Unicode values directly\ninstead of using extended parameters.\n\n```js\nformat(\n  {\n    type: 'form-data',\n    parameters: { name: 'file', filename: '€ rates.txt' },\n  },\n  { multipart: true },\n);\n```\n\n##### extended\n\nEncode Unicode parameter values using RFC 5987 extended header parameters,\ne.g. `filename*=`, defaults to `true`.\n\n## Examples\n\n### Send a file for download\n\n```js\nimport fs from 'node:fs';\nimport http from 'node:http';\nimport { create } from 'content-disposition';\nimport onFinished from 'on-finished';\n\nconst filePath = '/path/to/public/plans.pdf';\n\nhttp.createServer(function onRequest(req, res) {\n  // set headers\n  res.setHeader('Content-Type', 'application/pdf');\n  res.setHeader('Content-Disposition', create(filePath));\n\n  // send file\n  const stream = fs.createReadStream(filePath);\n  stream.pipe(res);\n  onFinished(res, function () {\n    stream.destroy();\n  });\n});\n```\n\n## Local demo\n\nRun the upload inspector locally:\n\n```sh\nnpm run demo\n```\n\nThen open `http://127.0.0.1:3000` in your browser. The demo lets you upload files, inspect the multipart upload part headers sent by the browser, and compare them with the download `Content-Disposition` header generated by this package.\n\n## Testing\n\n```sh\n$ npm test\n```\n\n## References\n\n- [RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1][rfc-2616]\n- [RFC 5987: Character Set and Language Encoding for Hypertext Transfer Protocol (HTTP) Header Field Parameters][rfc-5987]\n- [RFC 6266: Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)][rfc-6266]\n- [RFC 8187: Indicating Character Encoding and Language for HTTP Header Field Parameters][rfc-8187]\n- [HTML Living Standard: Multipart form data][html-form]\n- [Test Cases for HTTP Content-Disposition header field (RFC 6266) and the Encodings defined in RFCs 2047, 2231 and 5987][tc-2231]\n\n[rfc-2616]: https://datatracker.ietf.org/doc/html/rfc2616\n[rfc-5987]: https://datatracker.ietf.org/doc/html/rfc5987\n[rfc-6266]: https://datatracker.ietf.org/doc/html/rfc6266\n[rfc-8187]: https://datatracker.ietf.org/doc/html/rfc8187\n[html-form]: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data\n[tc-2231]: http://greenbytes.de/tech/tc2231/\n\n## License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/content-disposition\n[npm-url]: https://www.npmjs.com/package/content-disposition\n[node-version-image]: https://img.shields.io/node/v/content-disposition\n[node-version-url]: https://nodejs.org/en/download\n[coveralls-image]: https://img.shields.io/coverallsCoverage/github/jshttp/content-disposition\n[coveralls-url]: https://coveralls.io/github/jshttp/content-disposition?branch=master\n[downloads-image]: https://img.shields.io/npm/dm/content-disposition\n[downloads-url]: https://www.npmjs.com/package/content-disposition\n[github-actions-ci-image]: https://img.shields.io/github/actions/workflow/status/jshttp/content-disposition/ci.yml\n[github-actions-ci-url]: https://github.com/jshttp/content-disposition/actions/workflows/ci.yml\n","publish_time":1778516778261,"_cnpm_publish_time":1778516778261,"dist-tags":{"latest":"3.1.0","next":"1.0.0"}}