0.3.1 • Published 1 year ago

content-disposition-attachment v0.3.1

Weekly downloads
384
License
MIT
Repository
github
Last release
1 year ago

content-disposition-attachment

Build Status

A library to parse "attachment"s in Content-Disposition.

Getting started

Install via npm

npm install content-disposition-attachment

ESM

import { parse } from 'content-disposition-attachment';

console.log(parse('attachment; filename=foo.html'));
// => { attachment: true, filename: 'foo.html' }

CommonJS

const { parse } = require('content-disposition-attachment');

console.log(parse('attachment; filename=foo.html'));
// => { attachment: true, filename: 'foo.html' }

Import from CDN

UMD

<script src="https://unpkg.com/content-disposition-attachment@0.3"></script>
<script>
  console.log(ContentDispositionAttachment.parse('attachment; filename="foo.html"'));
  // => { attachment: true, filename: 'foo.html' }
</script>

ESM

<script type="module">
  import { parse } from 'https://unpkg.com/content-disposition-attachment@0.3?module';

  console.log(parse('attachment; filename=foo.html'));
  // => { attachment: true, filename: 'foo.html' }
</script>

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

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.

0.3.0

1 year ago

0.3.1

1 year ago

0.2.0

3 years ago

0.1.2

4 years ago

0.1.1

6 years ago

0.1.0

6 years ago