{"_id":"content-disposition@3.1.0","bugs":{"url":"https://github.com/jshttp/content-disposition/issues"},"dist":{"shasum":"ebccfaec43b927a9c046c4bbdd636578ab2418dc","tarball":"http://registry-npm.ywwl.com/content-disposition/download/content-disposition-3.1.0.tgz","integrity":"sha512-6lwVDK9bsenmMu7hxcLuUiu+FzFBDAdfQR1LKbE+SCo7/Qfpm2NG8X9f8AJgumfoVID/4r1stSxcmCeiT7pfkQ==","fileCount":6,"unpackedSize":60184,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/content-disposition@3.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDPnQ5sliJXpktVxsKXe2PFtfaJqT480ytkshmQMeLHyAIgHTe65Y2Z3ooB6eZ4bZxF0vsPy6JThiaXptxpe61ZCzg="}],"size":15691,"noattachment":false,"key":"/content-disposition/-/content-disposition-3.1.0.tgz"},"main":"./dist/index.js","name":"content-disposition","type":"module","types":"./dist/index.d.ts","author":{"name":"Douglas Christopher Wilson","email":"doug@somethingdoug.com"},"engines":{"node":">=22"},"exports":"./dist/index.js","funding":{"url":"https://opencollective.com/express","type":"opencollective"},"gitHead":"01734c246fd5988db939e0a41083b17987126655","license":"MIT","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"},"version":"3.1.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"99aed8be-b5f1-43a9-a86f-345979d3956d"},"approver":{"name":"blakeembrey","email":"hello@blakeembrey.com"}},"homepage":"https://github.com/jshttp/content-disposition#readme","keywords":["content-disposition","http","rfc6266","res"],"repository":{"url":"git+https://github.com/jshttp/content-disposition.git","type":"git"},"ts-scripts":{"dist":["dist"],"project":["tsconfig.build.json"]},"_npmVersion":"12.2.2","description":"Create and parse Content-Disposition header","directories":{},"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"}],"_nodeVersion":"27.0.0-alpha.0.1.1","devDependencies":{"vitest":"^4.1.10","typescript":"^7.0.2","@vitest/coverage-v8":"^4.1.10","@borderless/ts-scripts":"^0.15.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/content-disposition_3.1.0_1795030195483_0.06561091348231873"},"_hasShrinkwrap":false,"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** The `filename` is used as given; it is not reduced to its base name.\nPass only the file name (e.g. using `path.basename`) rather than a full path,\notherwise the path is sent to the client and exposes your directory structure.\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`create` 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 path from 'node:path';\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(path.basename(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":1795030195565,"_cnpm_publish_time":1795030195565,"dist-tags":{"latest":"3.1.0","next":"1.0.0"}}