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 ed1cc66
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 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
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('typeis(req, types)', function () {
assert.strictEqual(typeis(req, ['text/*']), 'text/html')
})

it.skip('should fail invalid type', function () {
it('should fail invalid type', function () {
var req = createRequest('text/html**')
assert.strictEqual(typeis(req, ['text/*']), false)
})
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('typeis.is(mediaType, types)', function () {
assert.strictEqual(typeis.is('text/HTML', ['text/*']), 'text/html')
})

it.skip('should fail invalid type', function () {
it('should fail invalid type', function () {
assert.strictEqual(typeis.is('text/html**', ['text/*']), false)
})

Expand Down

0 comments on commit ed1cc66

Please sign in to comment.