mime-detect
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -12,1 +12,9 @@ /// <reference types="node" /> | ||
export declare function detectBufferMime(buffer: Buffer): Promise<string>; | ||
/** | ||
* @description return file extension name without dot | ||
* e.g. "audio/mp4" -> "m4a" | ||
* e.g. "video/x-matroska" -> "mkv" | ||
* e.g. "image/jpeg" -> "jpg" | ||
* e.g. "application/octet-stream" -> "bin" | ||
*/ | ||
export declare function mimeToExt(mime: string): string; |
27
index.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.detectBufferMime = exports.detectFilenameMime = exports.detectFileMime = exports.enableTypescriptMime = void 0; | ||
exports.mimeToExt = exports.detectBufferMime = exports.detectFilenameMime = exports.detectFileMime = exports.enableTypescriptMime = void 0; | ||
const mime_types_1 = require("./mime.types"); | ||
const mime_ext_1 = require("./mime.ext"); | ||
function enableTypescriptMime(mime = 'text/typescript') { | ||
@@ -94,2 +95,26 @@ mime_types_1.ext_to_mime.ts = mime; | ||
exports.detectBufferMime = detectBufferMime; | ||
/** | ||
* @description return file extension name without dot | ||
* e.g. "audio/mp4" -> "m4a" | ||
* e.g. "video/x-matroska" -> "mkv" | ||
* e.g. "image/jpeg" -> "jpg" | ||
* e.g. "application/octet-stream" -> "bin" | ||
*/ | ||
function mimeToExt(mime) { | ||
mime = mime.split(';')[0]; | ||
let ext = mime_ext_1.mime_to_ext[mime]; | ||
if (ext) | ||
return ext; | ||
let exts = Object.entries(mime_types_1.ext_to_mime) | ||
.filter(([key, value]) => value == mime) | ||
.map(([key]) => key); | ||
if (exts.length > 1) { | ||
console.warn(`multiple extensions matched:`, { mime, exts }); | ||
} | ||
if (exts.length == 1) { | ||
return exts[0]; | ||
} | ||
return mime.split('/').pop(); | ||
} | ||
exports.mimeToExt = mimeToExt; | ||
// using eval to avoid error when bundling with esbuild | ||
@@ -96,0 +121,0 @@ // at least detectFilenameMime() is usable in browser |
export declare let ext_to_mime: { | ||
"123": string; | ||
ez: string; | ||
appinstaller: string; | ||
aw: string; | ||
appx: string; | ||
appxbundle: string; | ||
atom: string; | ||
@@ -12,2 +15,4 @@ atomcat: string; | ||
rsat: string; | ||
aml: string; | ||
amlx: string; | ||
bdoc: string; | ||
@@ -24,2 +29,3 @@ xcs: string; | ||
cu: string; | ||
cwl: string; | ||
mpd: string; | ||
@@ -31,3 +37,2 @@ mpp: string; | ||
xdssc: string; | ||
es: string; | ||
ecma: string; | ||
@@ -39,2 +44,3 @@ emma: string; | ||
exp: string; | ||
fdf: string; | ||
fdt: string; | ||
@@ -59,3 +65,2 @@ pfr: string; | ||
js: string; | ||
mjs: string; | ||
json: string; | ||
@@ -89,4 +94,8 @@ map: string; | ||
mp21: string; | ||
mp4: string; | ||
mpg4: string; | ||
mp4s: string; | ||
m4p: string; | ||
msix: string; | ||
msixbundle: string; | ||
doc: string; | ||
@@ -152,2 +161,3 @@ dot: string; | ||
cww: string; | ||
xsf: string; | ||
pskcxml: string; | ||
@@ -188,2 +198,3 @@ raml: string; | ||
srx: string; | ||
sql: string; | ||
gram: string; | ||
@@ -305,3 +316,2 @@ grxml: string; | ||
ez3: string; | ||
fdf: string; | ||
mseed: string; | ||
@@ -330,2 +340,3 @@ seed: string; | ||
ggb: string; | ||
ggs: string; | ||
ggt: string; | ||
@@ -343,2 +354,3 @@ gex: string; | ||
kmz: string; | ||
xdcf: string; | ||
gqf: string; | ||
@@ -480,2 +492,3 @@ gqs: string; | ||
taglet: string; | ||
bdo: string; | ||
nlu: string; | ||
@@ -541,2 +554,3 @@ ntf: string; | ||
ptid: string; | ||
xhtm: string; | ||
qxd: string; | ||
@@ -618,2 +632,3 @@ qxt: string; | ||
uoml: string; | ||
uo: string; | ||
vcx: string; | ||
@@ -773,3 +788,2 @@ vsd: string; | ||
xap: string; | ||
sql: string; | ||
sit: string; | ||
@@ -842,2 +856,4 @@ sitx: string; | ||
"3gpp": string; | ||
adts: string; | ||
aac: string; | ||
adp: string; | ||
@@ -880,3 +896,2 @@ amr: string; | ||
weba: string; | ||
aac: string; | ||
aif: string; | ||
@@ -912,4 +927,6 @@ aiff: string; | ||
bmp: string; | ||
dib: string; | ||
cgm: string; | ||
drle: string; | ||
dpx: string; | ||
fits: string; | ||
@@ -934,4 +951,6 @@ g3: string; | ||
jpm: string; | ||
jpgm: string; | ||
jpx: string; | ||
jpf: string; | ||
jxl: string; | ||
jxr: string; | ||
@@ -948,2 +967,3 @@ jxra: string; | ||
btif: string; | ||
btf: string; | ||
pti: string; | ||
@@ -1019,2 +1039,3 @@ sgi: string; | ||
iges: string; | ||
jt: string; | ||
msh: string; | ||
@@ -1027,2 +1048,5 @@ mesh: string; | ||
stpxz: string; | ||
u3d: string; | ||
bary: string; | ||
cld: string; | ||
dae: string; | ||
@@ -1036,3 +1060,6 @@ dwf: string; | ||
x_t: string; | ||
pyo: string; | ||
pyox: string; | ||
vds: string; | ||
usda: string; | ||
usdz: string; | ||
@@ -1061,6 +1088,7 @@ bsp: string; | ||
jade: string; | ||
mjs: string; | ||
jsx: string; | ||
less: string; | ||
md: string; | ||
markdown: string; | ||
md: string; | ||
mml: string; | ||
@@ -1113,2 +1141,3 @@ mdx: string; | ||
vtt: string; | ||
wgsl: string; | ||
s: string; | ||
@@ -1154,9 +1183,8 @@ asm: string; | ||
jpgv: string; | ||
jpgm: string; | ||
mj2: string; | ||
mjp2: string; | ||
ts: string; | ||
mp4: string; | ||
m2t: string; | ||
m2ts: string; | ||
mp4v: string; | ||
mpg4: string; | ||
mpeg: string; | ||
@@ -1163,0 +1191,0 @@ mpg: string; |
@@ -7,3 +7,6 @@ "use strict"; | ||
"ez": "application/andrew-inset", | ||
"appinstaller": "application/appinstaller", | ||
"aw": "application/applixware", | ||
"appx": "application/appx", | ||
"appxbundle": "application/appxbundle", | ||
"atom": "application/atom+xml", | ||
@@ -16,2 +19,4 @@ "atomcat": "application/atomcat+xml", | ||
"rsat": "application/atsc-rsat+xml", | ||
"aml": "application/automationml-aml+xml", | ||
"amlx": "application/automationml-amlx+zip", | ||
"bdoc": "application/x-bdoc", | ||
@@ -28,2 +33,3 @@ "xcs": "application/calendar+xml", | ||
"cu": "application/cu-seeme", | ||
"cwl": "application/cwl", | ||
"mpd": "application/dash+xml", | ||
@@ -35,3 +41,2 @@ "mpp": "application/vnd.ms-project", | ||
"xdssc": "application/dssc+xml", | ||
"es": "application/ecmascript", | ||
"ecma": "application/ecmascript", | ||
@@ -43,2 +48,3 @@ "emma": "application/emma+xml", | ||
"exp": "application/express", | ||
"fdf": "application/vnd.fdf", | ||
"fdt": "application/fdt+xml", | ||
@@ -62,4 +68,3 @@ "pfr": "application/font-tdpfr", | ||
"class": "application/java-vm", | ||
"js": "application/javascript", | ||
"mjs": "application/javascript", | ||
"js": "text/javascript", | ||
"json": "application/json", | ||
@@ -93,4 +98,8 @@ "map": "application/json", | ||
"mp21": "application/mp21", | ||
"mp4": "video/mp4", | ||
"mpg4": "video/mp4", | ||
"mp4s": "application/mp4", | ||
"m4p": "application/mp4", | ||
"msix": "application/msix", | ||
"msixbundle": "application/msixbundle", | ||
"doc": "application/msword", | ||
@@ -156,2 +165,3 @@ "dot": "application/msword", | ||
"cww": "application/prs.cww", | ||
"xsf": "application/prs.xsf+xml", | ||
"pskcxml": "application/pskc+xml", | ||
@@ -192,2 +202,3 @@ "raml": "application/raml+yaml", | ||
"srx": "application/sparql-results+xml", | ||
"sql": "application/x-sql", | ||
"gram": "application/srgs", | ||
@@ -225,3 +236,3 @@ "grxml": "application/srgs+xml", | ||
"xdp": "application/vnd.adobe.xdp+xml", | ||
"xfdf": "application/vnd.adobe.xfdf", | ||
"xfdf": "application/xfdf", | ||
"age": "application/vnd.age", | ||
@@ -310,3 +321,2 @@ "ahead": "application/vnd.ahead.space", | ||
"ez3": "application/vnd.ezpix-package", | ||
"fdf": "application/vnd.fdf", | ||
"mseed": "application/vnd.fdsn.mseed", | ||
@@ -335,2 +345,3 @@ "seed": "application/vnd.fdsn.seed", | ||
"ggb": "application/vnd.geogebra.file", | ||
"ggs": "application/vnd.geogebra.slides", | ||
"ggt": "application/vnd.geogebra.tool", | ||
@@ -348,2 +359,3 @@ "gex": "application/vnd.geometry-explorer", | ||
"kmz": "application/vnd.google-earth.kmz", | ||
"xdcf": "application/vnd.gov.sk.xmldatacontainer+xml", | ||
"gqf": "application/vnd.grafeq", | ||
@@ -485,2 +497,3 @@ "gqs": "application/vnd.grafeq", | ||
"taglet": "application/vnd.mynfc", | ||
"bdo": "application/vnd.nato.bindingdataobject+xml", | ||
"nlu": "application/vnd.neurolanguage.nlu", | ||
@@ -546,2 +559,3 @@ "ntf": "application/vnd.nitf", | ||
"ptid": "application/vnd.pvi.ptid1", | ||
"xhtm": "application/vnd.pwg-xhtml-print+xml", | ||
"qxd": "application/vnd.quark.quarkxpress", | ||
@@ -623,2 +637,3 @@ "qxt": "application/vnd.quark.quarkxpress", | ||
"uoml": "application/vnd.uoml+xml", | ||
"uo": "application/vnd.uoml+xml", | ||
"vcx": "application/vnd.vcx", | ||
@@ -736,3 +751,3 @@ "vsd": "application/vnd.visio", | ||
"mie": "application/x-mie", | ||
"prc": "application/x-pilot", | ||
"prc": "model/prc", | ||
"mobi": "application/x-mobipocket-ebook", | ||
@@ -779,3 +794,2 @@ "application": "application/x-ms-application", | ||
"xap": "application/x-silverlight-app", | ||
"sql": "application/x-sql", | ||
"sit": "application/x-stuffit", | ||
@@ -848,2 +862,4 @@ "sitx": "application/x-stuffitx", | ||
"3gpp": "video/3gpp", | ||
"adts": "audio/aac", | ||
"aac": "audio/x-aac", | ||
"adp": "audio/adpcm", | ||
@@ -886,3 +902,2 @@ "amr": "audio/amr", | ||
"weba": "audio/webm", | ||
"aac": "audio/x-aac", | ||
"aif": "audio/x-aiff", | ||
@@ -918,4 +933,6 @@ "aiff": "audio/x-aiff", | ||
"bmp": "image/x-ms-bmp", | ||
"dib": "image/bmp", | ||
"cgm": "image/cgm", | ||
"drle": "image/dicom-rle", | ||
"dpx": "image/dpx", | ||
"fits": "image/fits", | ||
@@ -940,4 +957,6 @@ "g3": "image/g3fax", | ||
"jpm": "video/jpm", | ||
"jpgm": "video/jpm", | ||
"jpx": "image/jpx", | ||
"jpf": "image/jpx", | ||
"jxl": "image/jxl", | ||
"jxr": "image/jxr", | ||
@@ -954,2 +973,3 @@ "jxra": "image/jxra", | ||
"btif": "image/prs.btif", | ||
"btf": "image/prs.btif", | ||
"pti": "image/prs.pti", | ||
@@ -1025,2 +1045,3 @@ "sgi": "image/sgi", | ||
"iges": "model/iges", | ||
"jt": "model/jt", | ||
"msh": "model/mesh", | ||
@@ -1033,2 +1054,5 @@ "mesh": "model/mesh", | ||
"stpxz": "model/step-xml+zip", | ||
"u3d": "model/u3d", | ||
"bary": "model/vnd.bary", | ||
"cld": "model/vnd.cld", | ||
"dae": "model/vnd.collada+xml", | ||
@@ -1038,7 +1062,10 @@ "dwf": "model/vnd.dwf", | ||
"gtw": "model/vnd.gtw", | ||
"mts": "model/vnd.mts", | ||
"mts": "video/mp2t", | ||
"ogex": "model/vnd.opengex", | ||
"x_b": "model/vnd.parasolid.transmit.binary", | ||
"x_t": "model/vnd.parasolid.transmit.text", | ||
"pyo": "model/vnd.pytha.pyox", | ||
"pyox": "model/vnd.pytha.pyox", | ||
"vds": "model/vnd.sap.vds", | ||
"usda": "model/vnd.usda", | ||
"usdz": "model/vnd.usdz+zip", | ||
@@ -1067,6 +1094,7 @@ "bsp": "model/vnd.valve.source.compiled-map", | ||
"jade": "text/jade", | ||
"mjs": "text/javascript", | ||
"jsx": "text/jsx", | ||
"less": "text/less", | ||
"md": "text/markdown", | ||
"markdown": "text/markdown", | ||
"md": "text/markdown", | ||
"mml": "text/mathml", | ||
@@ -1119,2 +1147,3 @@ "mdx": "text/mdx", | ||
"vtt": "text/vtt", | ||
"wgsl": "text/wgsl", | ||
"s": "text/x-asm", | ||
@@ -1160,9 +1189,8 @@ "asm": "text/x-asm", | ||
"jpgv": "video/jpeg", | ||
"jpgm": "video/jpm", | ||
"mj2": "video/mj2", | ||
"mjp2": "video/mj2", | ||
"ts": "video/mp2t", | ||
"mp4": "video/mp4", | ||
"m2t": "video/mp2t", | ||
"m2ts": "video/mp2t", | ||
"mp4v": "video/mp4", | ||
"mpg4": "video/mp4", | ||
"mpeg": "video/mpeg", | ||
@@ -1169,0 +1197,0 @@ "mpg": "video/mpeg", |
{ | ||
"name": "mime-detect", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Detect mime type and encoding (aka Content-Type) from buffer, file content and filename.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -64,2 +64,9 @@ # mime-detect | ||
} | ||
/** | ||
* @description return file extension name without dot | ||
* e.g. "audio/mp4" -> "m4a" | ||
* e.g. "video/x-matroska" -> "mkv" | ||
*/ | ||
export function mimeToExt(mime: string): string | ||
``` | ||
@@ -66,0 +73,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
77929
2565
83
1