Skip to content

Commit

Permalink
break: bump mime-db version;
Browse files Browse the repository at this point in the history
- Changes: asc, js, mjs, rtf, xml
- Removes: es
- Closes #8
  • Loading branch information
lukeed committed Dec 20, 2023
1 parent f071512 commit 30fb901
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 23 deletions.
35 changes: 21 additions & 14 deletions bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,33 @@ function write(file: string, data: string) {
// iana > mimedb > apache > nginx
// https://github.com/jshttp/mime-types/blob/master/index.js#L156
const SOURCES = {
nginx: 1,
apache: 2,
iana: 4,
apache: 2,
//
nginx: 1,
};

// font > application > text
// const TYPES = {
// font: 3,
// application: 2,
// text: 1,
// };

// let [p1] = prev.split('/', 1);
// let [p2] = next.split('/', 1);
// let t1 = TYPES[p1] || 0;
// let t2 = TYPES[p2] || 0;

function compare(prev: string, next: string): string {
let [p1] = prev.split('/', 1);
let [p2] = next.split('/', 1);

if (p1 !== p2) {
// font > application > text
if (p1 === 'font') return prev;
if (p2 === 'font') return next;
if (p1 === 'application') return prev;
if (p2 === 'application') return next;
}
// compare sources
let s1 = SOURCES[DB[prev].source] || 3;
let s2 = SOURCES[DB[next].source] || 3;
if (s1 !== s2) return s2 > s1 ? next : prev;

if (s2 !== s1) {
return s2 > s1 ? next : prev;
}

// prefer shorter
return prev.length >= next.length ? next : prev;
}

Expand Down
2 changes: 1 addition & 1 deletion bin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"private": true,
"devDependencies": {
"@types/node": "20.10.5",
"mime-db": "1.49.0"
"mime-db": "git://github.com/jshttp/mime-db.git#a76e5a8"
}
}
40 changes: 34 additions & 6 deletions deno/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,34 @@ const mimes: Record<string, string> = {
"3gp": "video/3gpp",
"3gpp": "video/3gpp",
"3mf": "model/3mf",
"aac": "audio/aac",
"ac": "application/pkix-attr-cert",
"adp": "audio/adpcm",
"adts": "audio/aac",
"ai": "application/postscript",
"aml": "application/automationml-aml+xml",
"amlx": "application/automationml-amlx+zip",
"amr": "audio/amr",
"apng": "image/apng",
"appcache": "text/cache-manifest",
"asc": "application/pgp-signature",
"appinstaller": "application/appinstaller",
"appx": "application/appx",
"appxbundle": "application/appxbundle",
"asc": "application/pgp-keys",
"atom": "application/atom+xml",
"atomcat": "application/atomcat+xml",
"atomdeleted": "application/atomdeleted+xml",
"atomsvc": "application/atomsvc+xml",
"au": "audio/basic",
"avci": "image/avci",
"avcs": "image/avcs",
"avif": "image/avif",
"aw": "application/applixware",
"bdoc": "application/bdoc",
"bin": "application/octet-stream",
"bmp": "image/bmp",
"bpk": "application/octet-stream",
"btf": "image/prs.btif",
"btif": "image/prs.btif",
"buffer": "application/octet-stream",
"ccxml": "application/ccxml+xml",
Expand All @@ -36,17 +46,20 @@ const mimes: Record<string, string> = {
"class": "application/java-vm",
"coffee": "text/coffeescript",
"conf": "text/plain",
"cpl": "application/cpl+xml",
"cpt": "application/mac-compactpro",
"crl": "application/pkix-crl",
"css": "text/css",
"csv": "text/csv",
"cu": "application/cu-seeme",
"cwl": "application/cwl",
"cww": "application/prs.cww",
"davmount": "application/davmount+xml",
"dbk": "application/docbook+xml",
"deb": "application/octet-stream",
"def": "text/plain",
"deploy": "application/octet-stream",
"dib": "image/bmp",
"disposition-notification": "message/disposition-notification",
"dist": "application/octet-stream",
"distz": "application/octet-stream",
Expand All @@ -55,6 +68,7 @@ const mimes: Record<string, string> = {
"dms": "application/octet-stream",
"doc": "application/msword",
"dot": "application/msword",
"dpx": "image/dpx",
"drle": "image/dicom-rle",
"dsc": "text/prs.lines.tag",
"dssc": "application/dssc+der",
Expand All @@ -70,11 +84,12 @@ const mimes: Record<string, string> = {
"emotionml": "application/emotionml+xml",
"eps": "application/postscript",
"epub": "application/epub+zip",
"es": "application/ecmascript",
"exe": "application/octet-stream",
"exi": "application/exi",
"exp": "application/express",
"exr": "image/aces",
"ez": "application/andrew-inset",
"fdf": "application/fdf",
"fdt": "application/fdt+xml",
"fits": "image/fits",
"g3": "image/g3fax",
Expand Down Expand Up @@ -132,12 +147,13 @@ const mimes: Record<string, string> = {
"jph": "image/jph",
"jpm": "image/jpm",
"jpx": "image/jpx",
"js": "application/javascript",
"js": "text/javascript",
"json": "application/json",
"json5": "application/json5",
"jsonld": "application/ld+json",
"jsonml": "application/jsonml+json",
"jsx": "text/jsx",
"jt": "model/jt",
"jxr": "image/jxr",
"jxra": "image/jxra",
"jxrs": "image/jxrs",
Expand Down Expand Up @@ -187,7 +203,7 @@ const mimes: Record<string, string> = {
"mime": "message/rfc822",
"mj2": "video/mj2",
"mjp2": "video/mj2",
"mjs": "application/javascript",
"mjs": "text/javascript",
"mml": "text/mathml",
"mods": "application/mods+xml",
"mov": "video/quicktime",
Expand All @@ -202,15 +218,19 @@ const mimes: Record<string, string> = {
"mpd": "application/dash+xml",
"mpe": "video/mpeg",
"mpeg": "video/mpeg",
"mpf": "application/media-policy-dataset+xml",
"mpg": "video/mpeg",
"mpg4": "video/mp4",
"mpga": "audio/mpeg",
"mpp": "application/dash-patch+xml",
"mrc": "application/marc",
"mrcx": "application/marcxml+xml",
"ms": "text/troff",
"mscml": "application/mediaservercontrol+xml",
"msh": "model/mesh",
"msi": "application/octet-stream",
"msix": "application/msix",
"msixbundle": "application/msixbundle",
"msm": "application/octet-stream",
"msp": "application/octet-stream",
"mtl": "model/mtl",
Expand Down Expand Up @@ -251,6 +271,7 @@ const mimes: Record<string, string> = {
"pkipath": "application/pkix-pkipath",
"pls": "application/pls+xml",
"png": "image/png",
"prc": "model/prc",
"prf": "application/pics-rules",
"provx": "application/provenance+xml",
"ps": "application/postscript",
Expand All @@ -275,7 +296,7 @@ const mimes: Record<string, string> = {
"rsd": "application/rsd+xml",
"rsheet": "application/urc-ressheet+xml",
"rss": "application/rss+xml",
"rtf": "application/rtf",
"rtf": "text/rtf",
"rtx": "text/richtext",
"rusd": "application/route-usd+xml",
"s3m": "audio/s3m",
Expand Down Expand Up @@ -310,12 +331,14 @@ const mimes: Record<string, string> = {
"spp": "application/scvp-vp-response",
"spq": "application/scvp-vp-request",
"spx": "audio/ogg",
"sql": "application/sql",
"sru": "application/sru+xml",
"srx": "application/sparql-results+xml",
"ssdl": "application/ssdl+xml",
"ssml": "application/ssml+xml",
"stk": "application/hyperstudio",
"stl": "model/stl",
"stpx": "model/step+xml",
"stpxz": "model/step-xml+zip",
"stpz": "model/step+zip",
"styl": "text/stylus",
Expand Down Expand Up @@ -344,6 +367,7 @@ const mimes: Record<string, string> = {
"ttl": "text/turtle",
"ttml": "application/ttml+xml",
"txt": "text/plain",
"u3d": "model/u3d",
"u8dsn": "message/global-delivery-status",
"u8hdr": "message/global-headers",
"u8mdn": "message/global-disposition-notification",
Expand All @@ -363,7 +387,9 @@ const mimes: Record<string, string> = {
"webm": "video/webm",
"webmanifest": "application/manifest+json",
"webp": "image/webp",
"wgsl": "text/wgsl",
"wgt": "application/widget",
"wif": "application/watcherinfo+xml",
"wmf": "image/wmf",
"woff": "font/woff",
"woff2": "font/woff2",
Expand All @@ -385,16 +411,18 @@ const mimes: Record<string, string> = {
"xel": "application/xcap-el+xml",
"xenc": "application/xenc+xml",
"xer": "application/patch-ops-error+xml",
"xfdf": "application/xfdf",
"xht": "application/xhtml+xml",
"xhtml": "application/xhtml+xml",
"xhvml": "application/xv+xml",
"xlf": "application/xliff+xml",
"xm": "audio/xm",
"xml": "application/xml",
"xml": "text/xml",
"xns": "application/xcap-ns+xml",
"xop": "application/xop+xml",
"xpl": "application/xproc+xml",
"xsd": "application/xml",
"xsf": "application/prs.xsf+xml",
"xsl": "application/xml",
"xslt": "application/xml",
"xspf": "application/xspf+xml",
Expand Down
8 changes: 6 additions & 2 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ mimes('overrides', () => {
assert.is(mimer.lookup('wav'), 'audio/wav');
assert.is(mimer.lookup('x3db'), 'model/x3d+fastinfoset');
assert.is(mimer.lookup('x3dv'), 'model/x3d-vrml');
assert.is(mimer.lookup('rtf'), 'application/rtf');
assert.is(mimer.lookup('xml'), 'application/xml');
assert.is(mimer.lookup('rtf'), 'text/rtf');
assert.is(mimer.lookup('xml'), 'text/xml');
assert.is(mimer.lookup('3gpp'), 'video/3gpp');
assert.is(mimer.lookup('jpm'), 'image/jpm');
//
assert.is(mimer.lookup('js'), 'text/javascript');
assert.is(mimer.lookup('mjs'), 'text/javascript');
assert.is(mimer.lookup('mp4'), 'video/mp4');
});

mimes.run();

0 comments on commit 30fb901

Please sign in to comment.