Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ module.exports.match = mimeMatch
*/

function typeis (value, types_) {
// Backward compatibility. TODO: Remove.
if (value && typeof value === 'object') {
value = value.headers['content-type']
}

var i
var types = types_

// remove parameters and normalize
var val = tryNormalizeType(value)
var val = normalizeType(value)

// no type or invalid
if (!val) {
Expand Down Expand Up @@ -228,23 +233,8 @@ function mimeMatch (expected, actual) {
* @private
*/
function normalizeType (value) {
// Parse the type
var type = contentType.parse(value).type
if (!value) return null
var type = contentType.parse(value, { parameters: false }).type

return typer.test(type) ? type : null
}

/**
* Try to normalize a type and remove parameters.
*
* @param {string} value
* @return {(string|null)}
* @private
*/
function tryNormalizeType (value) {
try {
return value ? normalizeType(value) : null
} catch (err) {
return null
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"url": "https://opencollective.com/express"
},
"dependencies": {
"content-type": "^1.0.5",
"content-type": "^2.0.0",
"media-typer": "^1.1.0",
"mime-types": "^3.0.0"
},
Expand All @@ -29,7 +29,7 @@
"nyc": "15.1.0"
},
"engines": {
"node": ">= 0.6"
"node": ">= 18"
},
"files": [
"LICENSE",
Expand Down
Loading