Comparing version
@@ -0,1 +1,4 @@ | ||
2.0.1 / 2025-03-27 | ||
========== | ||
2.0.0 / 2024-08-31 | ||
@@ -2,0 +5,0 @@ ========== |
46
index.js
@@ -119,4 +119,5 @@ /*! | ||
* | ||
* @param {String|Array} types... | ||
* @return {String|false|null} | ||
* @param {Object} req | ||
* @param {(String|Array)} types... | ||
* @return {(String|false|null)} | ||
* @public | ||
@@ -126,17 +127,8 @@ */ | ||
function typeofrequest (req, types_) { | ||
var types = types_ | ||
// no body | ||
if (!hasbody(req)) { | ||
return null | ||
} | ||
if (!hasbody(req)) return null | ||
// support flattened arguments | ||
if (arguments.length > 2) { | ||
types = new Array(arguments.length - 1) | ||
for (var i = 0; i < types.length; i++) { | ||
types[i] = arguments[i + 1] | ||
} | ||
} | ||
var types = arguments.length > 2 | ||
? Array.prototype.slice.call(arguments, 1) | ||
: types_ | ||
// request content type | ||
@@ -220,5 +212,5 @@ var value = req.headers['content-type'] | ||
// validate suffix wildcard | ||
if (expectedParts[1].substr(0, 2) === '*+') { | ||
if (expectedParts[1].slice(0, 2) === '*+') { | ||
return expectedParts[1].length <= actualParts[1].length + 1 && | ||
expectedParts[1].substr(1) === actualParts[1].substr(1 - expectedParts[1].length) | ||
expectedParts[1].slice(1) === actualParts[1].slice(1 - expectedParts[1].length) | ||
} | ||
@@ -238,15 +230,10 @@ | ||
* @param {string} value | ||
* @return {string} | ||
* @return {(string|null)} | ||
* @private | ||
*/ | ||
function normalizeType (value) { | ||
// parse the type | ||
// Parse the type | ||
var type = contentType.parse(value).type | ||
if (!typer.test(type)) { | ||
return null | ||
} | ||
return type | ||
return typer.test(type) ? type : null | ||
} | ||
@@ -258,13 +245,8 @@ | ||
* @param {string} value | ||
* @return {string} | ||
* @return {(string|null)} | ||
* @private | ||
*/ | ||
function tryNormalizeType (value) { | ||
if (!value) { | ||
return null | ||
} | ||
try { | ||
return normalizeType(value) | ||
return value ? normalizeType(value) : null | ||
} catch (err) { | ||
@@ -271,0 +253,0 @@ return null |
{ | ||
"name": "type-is", | ||
"description": "Infer the content-type of a request.", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"contributors": [ | ||
@@ -6,0 +6,0 @@ "Douglas Christopher Wilson <doug@somethingdoug.com>", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
21269
-0.37%216
-4.85%