@platform/util.mimetype
Advanced tools
Comparing version 0.1.48 to 0.1.51
@@ -15,3 +15,12 @@ "use strict"; | ||
Mime.isJson = function (mimetype) { | ||
return isIncluded(mimetype, ['application/json']); | ||
var parts = (mimetype || '') | ||
.trim() | ||
.split(';') | ||
.map(function (part) { return part.trim(); }) | ||
.filter(Boolean); | ||
return parts.some(function (part) { | ||
if (!part.startsWith('application/')) | ||
return false; | ||
return part.endsWith('/json') || part.endsWith('+json'); | ||
}); | ||
}; | ||
@@ -22,5 +31,5 @@ Mime.toType = toMimetype_1.toMimetype; | ||
exports.Mime = Mime; | ||
function isIncluded(mimetype, values) { | ||
function isIncluded(mimetype, match) { | ||
mimetype = (mimetype || '').trim(); | ||
return values.some(function (item) { return mimetype.includes(item); }); | ||
return match.some(function (item) { return mimetype.includes(item); }); | ||
} |
@@ -10,40 +10,34 @@ "use strict"; | ||
input = (input || '').trim(); | ||
if (input.endsWith('.js')) { | ||
if (input.endsWith('.js')) | ||
return 'application/javascript'; | ||
} | ||
if (input.endsWith('.json')) { | ||
if (input.endsWith('.wasm')) | ||
return 'application/wasm'; | ||
if (input.endsWith('.json')) | ||
return 'application/json'; | ||
} | ||
if (input.endsWith('.yaml') || input.endsWith('.yml')) { | ||
return 'text/plain'; | ||
} | ||
if (input.endsWith('.txt')) { | ||
return 'text/plain'; | ||
} | ||
if (input.endsWith('.html') || input.endsWith('.htm')) { | ||
return 'text/html'; | ||
} | ||
if (input.endsWith('.css')) { | ||
if (input.endsWith('.css')) | ||
return 'text/css'; | ||
} | ||
if (input.endsWith('.png')) { | ||
if (input.endsWith('.png')) | ||
return 'image/png'; | ||
} | ||
if (input.endsWith('.jpg') || input.endsWith('.jpeg')) { | ||
if (input.endsWith('.jpg') || input.endsWith('.jpeg')) | ||
return 'image/jpeg'; | ||
} | ||
if (input.endsWith('.gif')) { | ||
if (input.endsWith('.svg')) | ||
return 'image/svg+xml'; | ||
if (input.endsWith('.gif')) | ||
return 'image/gif'; | ||
} | ||
if (input.endsWith('.zip')) { | ||
if (input.endsWith('.webm')) | ||
return 'video/webm'; | ||
if (input.endsWith('.pdf')) | ||
return 'application/pdf'; | ||
if (input.endsWith('.yaml') || input.endsWith('.yml')) | ||
return 'text/plain'; | ||
if (input.endsWith('.txt')) | ||
return 'text/plain'; | ||
if (input.endsWith('.html') || input.endsWith('.htm')) | ||
return 'text/html'; | ||
if (input.endsWith('.zip')) | ||
return 'application/zip'; | ||
} | ||
if (input.endsWith('.pdf')) { | ||
return 'application/pdf'; | ||
} | ||
if (input.endsWith('.csv') || input.endsWith('.tsv')) { | ||
if (input.endsWith('.csv') || input.endsWith('.tsv')) | ||
return 'text/csv'; | ||
} | ||
return defaultType; | ||
}; | ||
exports.toMimetype = toMimetype; |
{ | ||
"name": "@platform/util.mimetype", | ||
"version": "0.1.48", | ||
"version": "0.1.51", | ||
"description": "Helpers for generating media-types.", | ||
@@ -9,3 +9,2 @@ "main": "lib/index", | ||
"test": "ts test", | ||
"tdd": "ts test --watch", | ||
"lint": "ts lint", | ||
@@ -17,4 +16,4 @@ "build": "ts build --no-esm", | ||
"devDependencies": { | ||
"@platform/test": "0.2.10", | ||
"@platform/ts": "4.1.23" | ||
"@platform/test": "0.3.2", | ||
"@platform/ts": "4.7.7" | ||
}, | ||
@@ -21,0 +20,0 @@ "files": [ |
8543
18
196