Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-content-type-parse

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-content-type-parse

Parse HTTP Content-Type header according to RFC 7231

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3M
decreased by-20.19%
Maintainers
0
Weekly downloads
 
Created
Source

fast-content-type-parse

Parse HTTP Content-Type header according to RFC 7231

NPM version NPM downloads Build Status js-standard-style Security Responsible Disclosure

Installation

$ npm install fast-content-type-parse

Usage

const fastContentTypeParse = require('fast-content-type-parse')

fastContentTypeParse.parse(string)

const contentType = fastContentTypeParse.parse('application/json; charset=utf-8')

Parse a Content-Type header. Throws a TypeError if the string is invalid.

It will return an object with the following properties (examples are shown for the string 'application/json; charset=utf-8'):

  • type: The media type (the type and subtype, always lower case). Example: 'application/json'

  • parameters: An object of the parameters in the media type (name of parameter always lower case). Example: {charset: 'utf-8'}

fastContentTypeParse.safeParse(string)

const contentType = fastContentTypeParse.safeParse('application/json; charset=utf-8')

Parse a Content-Type header. It will not throw an Error if the header is invalid.

This will return an object with the following properties (examples are shown for the string 'application/json; charset=utf-8'):

  • type: The media type (the type and subtype, always lower case). Example: 'application/json'

  • parameters: An object of the parameters in the media type (name of parameter always lower case). Example: {charset: 'utf-8'}

In case the header is invalid, it will return an object with an empty string '' as type and an empty Object for parameters.

Benchmarks

node benchmarks/index.js
util#MIMEType x 1,206,781 ops/sec ±0.22% (96 runs sampled)
fast-content-type-parse#parse x 3,752,236 ops/sec ±0.42% (96 runs sampled)
fast-content-type-parse#safeParse x 3,675,645 ops/sec ±1.09% (94 runs sampled)
content-type#parse x 1,452,582 ops/sec ±0.37% (95 runs sampled)
busboy#parseContentType x 924,306 ops/sec ±0.43% (94 runs sampled)
Fastest is fast-content-type-parse#parse

Credits

Based on the npm package content-type

Keywords

FAQs

Package last updated on 13 Jul 2024

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc