
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
fast-content-type-parse
Advanced tools
Parse HTTP Content-Type header according to RFC 7231.
$ npm install fast-content-type-parse
const fastContentTypeParse = require('fast-content-type-parse')
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 lowercase).
Example: 'application/json'
parameters
: An object of the parameters in the media type (name of parameter
always lowercase). Example: {charset: 'utf-8'}
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 lowercase).
Example: 'application/json'
parameters
: An object of the parameters in the media type (name of parameter
always lowercase). 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
.
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
Based on the npm package content-type
.
Licensed under MIT.
FAQs
Parse HTTP Content-Type header according to RFC 7231
The npm package fast-content-type-parse receives a total of 3,492,784 weekly downloads. As such, fast-content-type-parse popularity was classified as popular.
We found that fast-content-type-parse demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.