Skip to content

Commit

Permalink
Use content-type and media-typer for type validation
Browse files Browse the repository at this point in the history
closes #39
  • Loading branch information
dougwilson authored and wesleytodd committed Aug 31, 2024
1 parent 3700a79 commit 6e8863f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ unreleased
==========

* Drop node <18
* deps: replace media-typer with content-type
* Use `content-type` and `media-typer` for type validation
- No behavior changes, upgrades `media-typer`
* deps: mime-types@^3.0.0
- Add `application/toml` with extension `.toml`
- Add `application/ubjson` with extension `.ubj`
Expand Down
13 changes: 7 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
* @private
*/

var typer = require('content-type')
var contentType = require('content-type')
var mime = require('mime-types')
var typer = require('media-typer')

/**
* Module exports.
Expand Down Expand Up @@ -237,13 +238,13 @@ function mimeMatch (expected, actual) {

function normalizeType (value) {
// parse the type
var type = typer.parse(value)
var type = contentType.parse(value).type

// remove the parameters
type.parameters = undefined
if (!typer.test(type)) {
return null
}

// reformat it
return typer.format(type)
return type
}

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"repository": "jshttp/type-is",
"dependencies": {
"content-type": "^1.0.5",
"media-typer": "~1.1.0",
"mime-types": "^3.0.0"
},
"devDependencies": {
Expand Down

0 comments on commit 6e8863f

Please sign in to comment.