Socket
Book a DemoInstallSign in
Socket

content-disposition-attachment

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

content-disposition-attachment

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

0.3.1
latest
Source
npmnpm
Version published
Weekly downloads
4.4K
3.8%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

content-disposition

FAQs

Package last updated on 09 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.