https://github.com/lujjjh/content-disposition-attachment
A library to parse "attachment"s in Content-Disposition.
https://github.com/lujjjh/content-disposition-attachment
content-disposition parser
Last synced: 4 months ago
JSON representation
A library to parse "attachment"s in Content-Disposition.
- Host: GitHub
- URL: https://github.com/lujjjh/content-disposition-attachment
- Owner: lujjjh
- License: mit
- Created: 2018-02-05T13:06:41.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-06-16T09:51:35.000Z (over 1 year ago)
- Last Synced: 2025-06-02T07:08:54.639Z (5 months ago)
- Topics: content-disposition, parser
- Language: JavaScript
- Homepage:
- Size: 515 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# content-disposition-attachment
[](https://www.npmjs.com/package/content-disposition-attachment)


> A library to parse "attachment"s in Content-Disposition.
## Getting started
### Install via npm
```sh
npm install content-disposition-attachment
```
#### ESM
```js
import { parse } from 'content-disposition-attachment';
console.log(parse('attachment; filename=foo.html'));
// => { attachment: true, filename: 'foo.html' }
```
#### CommonJS
```js
const { parse } = require('content-disposition-attachment');
console.log(parse('attachment; filename=foo.html'));
// => { attachment: true, filename: 'foo.html' }
```
### Import from CDN
#### UMD
```html
console.log(ContentDispositionAttachment.parse('attachment; filename="foo.html"'));
// => { attachment: true, filename: 'foo.html' }
```
#### ESM
```html
import { parse } from 'https://unpkg.com/content-disposition-attachment@0.3?module';
console.log(parse('attachment; filename=foo.html'));
// => { attachment: true, filename: 'foo.html' }
```
## API references
### parse
> Parse a Content-Disposition.
If Content-Disposition is not "attachment", it returns `{ attachment: false }`;
otherwise, it returns `{ attachment: true }` along with parsed parameters.
If errors occur when parsing parameters, a `ParseError` will be thrown.
**Examples**
```js
import { parse } from 'content-disposition-attachment';
parse('inline');
// => { attachment: false }
parse('attachment; filename=foo.html; foo=bar');
// => { attachment: true, filename: 'foo.html', foo: 'bar' }
parse('attachment; foo');
// => ParseError: expect '='
```
You can find more examples in the [unit tests](test/parse.js).