
Company News
Jerod Santo Joins Socket as Head of Media
Allow myself to introduce... myself.
content-type
Advanced tools
Create and parse HTTP Content-Type header.
npm install content-type
import * as contentType from "content-type";
const obj = contentType.parse("image/svg+xml; charset=utf-8");
Parse a Content-Type header. This will return an object with the following properties (examples are shown for the string 'image/svg+xml; charset=utf-8'):
type: The media type (always lower case). Example: 'image/svg+xml'.parameters: An object of the parameters in the media type (parameter name is always lower case). Example: {charset: 'utf-8'}.index: The index where parsing stopped. Example: 33.The parser is lenient and does not validate or throw on malformed input.
parameters (default: true): Set to false to skip parameters.comma (default: false): Set to true to stop on a comma. This can be used to parse the media range in an Accept header.start (default: 0): Set index to start parsing from.const str = contentType.format({
type: "image/svg+xml",
parameters: { charset: "utf-8" },
});
Format an object into a Content-Type header. This will return a string of the content type for the given object with the following properties (examples are shown that produce the string 'image/svg+xml; charset=utf-8'):
type: The media type. Example: 'image/svg+xml'.parameters: An optional object of the parameters in the media type. Example: {charset: 'utf-8'}.Throws a TypeError if the object contains an invalid type or parameter names.
This package exposes the validation functions used by format:
isTypeValid Validates the MIME type against RFC 9110.isTokenValid Validates a token against RFC 9110 (used for the parameter name).The mime-types package is similar to content-type as it provides the ability to look up the content-type based on a file extension and vice versa. It is more focused on the association between file extensions and mime types rather than parsing and formatting Content-Type headers.
The mime package is another alternative that allows you to map between MIME types and file extensions. It provides functionality to define custom mime type mappings and is more comprehensive in terms of the number of file types it supports compared to content-type.
Negotiator is an HTTP content negotiation library that goes beyond just handling Content-Type headers. It can be used to negotiate language, charset, encoding, etc., based on the Accept-* headers from the client. It is more complex and offers broader functionality for handling HTTP negotiations.
FAQs
Create and parse HTTP Content-Type header
The npm package content-type receives a total of 199,982,455 weekly downloads. As such, content-type popularity was classified as popular.
We found that content-type demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.

Company News
Allow myself to introduce... myself.

Research
/Security News
A Twitch browser extension on Chrome and Firefox forwards users’ live OAuth session tokens through proxies controlled by a Russian bot service.

Security News
Anthropic found biased reasoning and recklessness drove Claude Mythos 5 to publish malware on PyPI and compromise a security vendor.