From 6e8863fb3abcae15f83bdd4c274e7204cb39a5ec Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 25 Apr 2019 22:48:31 -0400 Subject: [PATCH] Use content-type and media-typer for type validation closes #39 --- HISTORY.md | 3 ++- index.js | 13 +++++++------ package.json | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 4631e06..51e28e1 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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` diff --git a/index.js b/index.js index 792ea88..a5f1109 100644 --- a/index.js +++ b/index.js @@ -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. @@ -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 } /** diff --git a/package.json b/package.json index 67d27cf..fe9d654 100644 --- a/package.json +++ b/package.json @@ -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": {