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

content-type-parser

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

content-type-parser

Parse the value of the Content-Type header

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is content-type-parser?

The content-type-parser npm package is used to parse and handle Content-Type headers in HTTP requests and responses. It helps in extracting the media type, parameters, and other relevant information from Content-Type strings.

What are content-type-parser's main functionalities?

Parsing Content-Type

This feature allows you to parse a Content-Type string and extract the media type and parameters. In the example, the Content-Type 'application/json; charset=utf-8' is parsed to extract the type 'application/json' and the charset parameter 'utf-8'.

const contentTypeParser = require('content-type-parser');
const parsed = contentTypeParser('application/json; charset=utf-8');
console.log(parsed.type); // 'application/json'
console.log(parsed.parameters.charset); // 'utf-8'

Handling Invalid Content-Type

This feature demonstrates how the package handles invalid Content-Type strings. If the Content-Type string is invalid, an error is thrown, which can be caught and handled appropriately.

const contentTypeParser = require('content-type-parser');
try {
  const parsed = contentTypeParser('invalid-content-type');
} catch (error) {
  console.error('Invalid Content-Type:', error.message);
}

Comparing Media Types

This feature allows you to compare two parsed Content-Type objects to check if they represent the same media type. In the example, 'application/json' and 'application/json; charset=utf-8' are considered equal.

const contentTypeParser = require('content-type-parser');
const parsed1 = contentTypeParser('application/json');
const parsed2 = contentTypeParser('application/json; charset=utf-8');
console.log(parsed1.isEqual(parsed2)); // true

Other packages similar to content-type-parser

Keywords

FAQs

Package last updated on 23 Oct 2017

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