Gathering detailed insights and metrics for type-is
Gathering detailed insights and metrics for type-is
Gathering detailed insights and metrics for type-is
Gathering detailed insights and metrics for type-is
npm install type-is
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99
Supply Chain
99.5
Quality
83
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
7,280,402,499
Last Day
2,446,589
Last Week
38,924,369
Last Month
170,848,410
Last Year
1,590,695,914
MIT License
228 Stars
351 Commits
34 Forks
16 Watchers
3 Branches
34 Contributors
Updated on Jun 03, 2025
Minified
Minified + Gzipped
Latest Version
2.0.1
Package Id
type-is@2.0.1
Unpacked Size
20.77 kB
Size
6.54 kB
File Count
5
NPM Version
10.9.0
Node Version
22.10.0
Published on
Mar 27, 2025
Cumulative downloads
Total Downloads
Last Day
-1.8%
2,446,589
Compared to previous day
Last Week
-6.8%
38,924,369
Compared to previous week
Last Month
13.8%
170,848,410
Compared to previous month
Last Year
15.8%
1,590,695,914
Compared to previous year
Infer the content-type of a request.
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
1$ npm install type-is
1var http = require('http') 2var typeis = require('type-is') 3 4http.createServer(function (req, res) { 5 var istext = typeis(req, ['text/*']) 6 res.end('you ' + (istext ? 'sent' : 'did not send') + ' me text') 7})
Checks if the request
is one of the types
. If the request has no body,
even if there is a Content-Type
header, then null
is returned. If the
Content-Type
header is invalid or does not matches any of the types
, then
false
is returned. Otherwise, a string of the type that matched is returned.
The request
argument is expected to be a Node.js HTTP request. The types
argument is an array of type strings.
Each type in the types
array can be one of the following:
json
. This name will be returned if matched.application/json
.*/*
or */json
or application/*
.
The full mime type will be returned if matched.+json
. This can be combined with a wildcard such as
*/vnd+json
or application/*+json
. The full mime type will be returned
if matched.Some examples to illustrate the inputs and returned value:
1// req.headers.content-type = 'application/json' 2 3typeis(req, ['json']) // => 'json' 4typeis(req, ['html', 'json']) // => 'json' 5typeis(req, ['application/*']) // => 'application/json' 6typeis(req, ['application/json']) // => 'application/json' 7 8typeis(req, ['html']) // => false
Returns a Boolean if the given request
has a body, regardless of the
Content-Type
header.
Having a body has no relation to how large the body is (it may be 0 bytes). This is similar to how file existence works. If a body does exist, then this indicates that there is data to read from the Node.js request stream.
1if (typeis.hasBody(req)) { 2 // read the body, since there is one 3 4 req.on('data', function (chunk) { 5 // ... 6 }) 7}
Checks if the mediaType
is one of the types
. If the mediaType
is invalid
or does not matches any of the types
, then false
is returned. Otherwise, a
string of the type that matched is returned.
The mediaType
argument is expected to be a
media type string. The types
argument
is an array of type strings.
Each type in the types
array can be one of the following:
json
. This name will be returned if matched.application/json
.*/*
or */json
or application/*
.
The full mime type will be returned if matched.+json
. This can be combined with a wildcard such as
*/vnd+json
or application/*+json
. The full mime type will be returned
if matched.Some examples to illustrate the inputs and returned value:
1var mediaType = 'application/json' 2 3typeis.is(mediaType, ['json']) // => 'json' 4typeis.is(mediaType, ['html', 'json']) // => 'json' 5typeis.is(mediaType, ['application/*']) // => 'application/json' 6typeis.is(mediaType, ['application/json']) // => 'application/json' 7 8typeis.is(mediaType, ['html']) // => false
Match the type string expected
with actual
, taking in to account wildcards.
A wildcard can only be in the type of the subtype part of a media type and only
in the expected
value (as actual
should be the real media type to match). A
suffix can still be included even with a wildcard subtype. If an input is
malformed, false
will be returned.
1typeis.match('text/html', 'text/html') // => true 2typeis.match('*/html', 'text/html') // => true 3typeis.match('text/*', 'text/html') // => true 4typeis.match('*/*', 'text/html') // => true 5typeis.match('*/*+json', 'application/x-custom+json') // => true
Normalize a type
string. This works by performing the following:
type
is not a string, false
is returned.+
(so it is a +suffix
shorthand like +json
),
then it is expanded to contain the complete wildcard notation of */*+suffix
./
, then it is returned as the type.false
is there is no mapping.This includes two special mappings:
'multipart'
-> 'multipart/*'
'urlencoded'
-> 'application/x-www-form-urlencoded'
1var express = require('express') 2var typeis = require('type-is') 3 4var app = express() 5 6app.use(function bodyParser (req, res, next) { 7 if (!typeis.hasBody(req)) { 8 return next() 9 } 10 11 switch (typeis(req, ['urlencoded', 'json', 'multipart'])) { 12 case 'urlencoded': 13 // parse urlencoded body 14 throw new Error('implement urlencoded body parsing') 15 case 'json': 16 // parse json body 17 throw new Error('implement json body parsing') 18 case 'multipart': 19 // parse multipart body 20 throw new Error('implement multipart body parsing') 21 default: 22 // 415 error code 23 res.statusCode = 415 24 res.end() 25 break 26 } 27})
No vulnerabilities found.
Reason
update tool detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
project has 24 contributing companies or organizations
Details
Reason
security policy file detected
Details
Reason
13 out of 16 merged PRs checked by a CI test -- score normalized to 8
Reason
SAST tool detected but not run on all commits
Details
Reason
Found 9/18 approved changesets -- score normalized to 5
Reason
7 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-06-30T21:32:16Z
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More