@tinyhttp/type-is
Advanced tools
Comparing version 2.2.2 to 2.2.3
@@ -9,4 +9,3 @@ import * as typer from "@tinyhttp/content-type"; | ||
function tryNormalizeType(value) { | ||
if (!value) | ||
return null; | ||
if (!value) return null; | ||
try { | ||
@@ -19,19 +18,14 @@ return normalizeType(value); | ||
function mimeMatch(expected, actual) { | ||
if (expected === false) | ||
return false; | ||
if (expected === false) return false; | ||
const actualParts = actual.split("/"); | ||
const expectedParts = expected.split("/"); | ||
if (actualParts.length !== 2 || expectedParts.length !== 2) | ||
return false; | ||
if (expectedParts[0] !== "*" && expectedParts[0] !== actualParts[0]) | ||
return false; | ||
if (actualParts.length !== 2 || expectedParts.length !== 2) return false; | ||
if (expectedParts[0] !== "*" && expectedParts[0] !== actualParts[0]) return false; | ||
if (expectedParts[1].slice(0, 2) === "*+") | ||
return expectedParts[1].length <= actualParts[1].length + 1 && expectedParts[1].slice(1) === actualParts[1].slice(1 - expectedParts[1].length); | ||
if (expectedParts[1] !== "*" && expectedParts[1] !== actualParts[1]) | ||
return false; | ||
if (expectedParts[1] !== "*" && expectedParts[1] !== actualParts[1]) return false; | ||
return true; | ||
} | ||
function normalize(type) { | ||
if (typeof type !== "string") | ||
return false; | ||
if (typeof type !== "string") return false; | ||
switch (type) { | ||
@@ -43,4 +37,3 @@ case "urlencoded": | ||
} | ||
if (type[0] === "+") | ||
return "*/*" + type; | ||
if (type[0] === "+") return `*/*${type}`; | ||
return type.indexOf("/") === -1 ? mime.getType(type) : type; | ||
@@ -51,6 +44,4 @@ } | ||
const val = tryNormalizeType(value); | ||
if (!val) | ||
return false; | ||
if (!types || !types.length) | ||
return val; | ||
if (!val) return false; | ||
if (!types || !types.length) return val; | ||
let type; | ||
@@ -57,0 +48,0 @@ for (i = 0; i < types.length; i++) { |
{ | ||
"name": "@tinyhttp/type-is", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"type": "module", | ||
@@ -34,5 +34,2 @@ "description": "TypeScript rewrite of type-is with CJS and ESM targets", | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
@@ -39,0 +36,0 @@ "dev": "vite", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8135
8
64