
Research
/Security News
Coruna Respawned: Compromised art-template npm Package Leads to iOS Browser Exploit Kit
Compromised npm package art-template delivered a Coruna-like iOS Safari exploit framework through a watering-hole attack.
content-type
Advanced tools
Create and parse HTTP Content-Type header.
npm install content-type
const contentType = require("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. Example: 'image/svg+xml'.parameters: An object of the parameters in the media type (parameter name is always lower case). Example: {charset: 'utf-8'}.The parser is lenient and does not error. You should validate type and parameters before trusting them.
parameters (default: true): Set to false to skip parameters.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.
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 82,437,399 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.
Did you know?

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.

Research
/Security News
Compromised npm package art-template delivered a Coruna-like iOS Safari exploit framework through a watering-hole attack.

Company News
As AI accelerates how code is written and shipped, Socket is scaling to protect the software supply chain from the growing wave of attacks targeting open source dependencies.

Company News
Socket is scaling to defend open source against supply chain attacks as AI accelerates software development.