Skip to content

Commit 6e8863f

Browse files
dougwilsonwesleytodd
authored andcommitted
Use content-type and media-typer for type validation
closes #39
1 parent 3700a79 commit 6e8863f

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

HISTORY.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ unreleased
22
==========
33

44
* Drop node <18
5-
* deps: replace media-typer with content-type
5+
* Use `content-type` and `media-typer` for type validation
6+
- No behavior changes, upgrades `media-typer`
67
* deps: mime-types@^3.0.0
78
- Add `application/toml` with extension `.toml`
89
- Add `application/ubjson` with extension `.ubj`

index.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
* @private
1313
*/
1414

15-
var typer = require('content-type')
15+
var contentType = require('content-type')
1616
var mime = require('mime-types')
17+
var typer = require('media-typer')
1718

1819
/**
1920
* Module exports.
@@ -237,13 +238,13 @@ function mimeMatch (expected, actual) {
237238

238239
function normalizeType (value) {
239240
// parse the type
240-
var type = typer.parse(value)
241+
var type = contentType.parse(value).type
241242

242-
// remove the parameters
243-
type.parameters = undefined
243+
if (!typer.test(type)) {
244+
return null
245+
}
244246

245-
// reformat it
246-
return typer.format(type)
247+
return type
247248
}
248249

249250
/**

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"repository": "jshttp/type-is",
1111
"dependencies": {
1212
"content-type": "^1.0.5",
13+
"media-typer": "~1.1.0",
1314
"mime-types": "^3.0.0"
1415
},
1516
"devDependencies": {

0 commit comments

Comments
 (0)