Skip to content

Commit

Permalink
Add common MIME types from MDN (#4)
Browse files Browse the repository at this point in the history
* Add application/* types

* Add audio/* types

* Add image/* types

* Add text/* types

* Add video/* types
  • Loading branch information
markwhitaker authored Jan 5, 2023
1 parent 2772129 commit 3762615
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 7 deletions.
47 changes: 43 additions & 4 deletions src/mime-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ const MimeTypes = Object.freeze({
AtomXml: prefix + "atom+xml",
AtomcatXml: prefix + "atomcat+xml",
Ecmascript: prefix + "ecmascript",
EpubZip: prefix + "epub+zip",
Gzip: prefix + "gzip",
JavaArchive: prefix + "java-archive",
Javascript: prefix + "javascript",
Json: prefix + "json",
LdJson: prefix + "ld+json",
Mp4: prefix + "mp4",
Msword: prefix + "msword",
OctetStream: prefix + "octet-stream",
Ogg: prefix + "ogg",
Pdf: prefix + "pdf",
Pkcs10: prefix + "pkcs10",
Pkcs7Mime: prefix + "pkcs7-mime",
Expand All @@ -18,14 +23,38 @@ const MimeTypes = Object.freeze({
RssXml: prefix + "rss+xml",
Rtf: prefix + "rtf",
SmilXml: prefix + "smil+xml",
VndAmazonEbook: prefix + "vnd.amazon.ebook",
VndAppleInstallerXml: prefix + "vnd.apple.installer+xml",
VndMozillaXulXml: prefix + "vnd.mozilla.xul+xml",
VndMsExcel: prefix + "vnd.ms-excel",
VndMsFontobject: prefix + "vnd.ms-fontobject",
VndMsPowerpoint: prefix + "vnd.ms-powerpoint",
VndOasisOpendocumentPresentation: prefix + "vnd.oasis.opendocument.presentation",
VndOasisOpendocumentSpreadsheet: prefix + "vnd.oasis.opendocument.spreadsheet",
VndOasisOpendocumentText: prefix + "vnd.oasis.opendocument.text",
VndOpenxmlformatsOfficedocumentPresentationmlPresentation: prefix + "vnd.openxmlformats-officedocument.presentationml.presentation",
VndOpenxmlformatsOfficedocumentSpreadsheetmlSheet: prefix + "vnd.openxmlformats-officedocument.spreadsheetml.sheet",
VndOpenxmlformatsOfficedocumentWordprocessingmlDocument: prefix + "vnd.openxmlformats-officedocument.wordprocessingml.document",
VndRar: prefix + "vnd.rar",
VndVisio: prefix + "vnd.visio",
X7zCompressed: prefix + "x-7z-compressed",
XAbiword: prefix + "x-abiword",
XBzip: prefix + "x-bzip",
XBzip2: prefix + "x-bzip2",
XCdf: prefix + "x-cdf",
XCsh: prefix + "x-csh",
XFontOff: prefix + "x-font-off",
XPkcs12: prefix + "x-pkcs12",
XShockwaveFlash: prefix + "x-shockwave-flash",
XSilverlightApp: prefix + "x-silverlight-app",
XFreearc: prefix + "x-freearc",
XhtmlXml: prefix + "xhtml+xml",
XHttpdPhp: prefix + "x-httpd-php",
Xml: prefix + "xml",
XmlDtd: prefix + "xml-dtd",
XPkcs12: prefix + "x-pkcs12",
XSh: prefix + "x-sh",
XShockwaveFlash: prefix + "x-shockwave-flash",
XSilverlightApp: prefix + "x-silverlight-app",
XsltXml: prefix + "xslt+xml",
XTar: prefix + "x-tar",
XWwwFormUrlencoded: prefix + "x-www-form-urlencoded",
Zip: prefix + "zip"
}))("application/"),
Expand All @@ -35,10 +64,14 @@ const MimeTypes = Object.freeze({
Mp4: prefix + "mp4",
Mpeg: prefix + "mpeg",
Ogg: prefix + "ogg",
Opus: prefix + "opus",
Threegpp: prefix + "3gpp",
Threegpp2: prefix + "3gpp2",
Wav: prefix + "wav",
Webm: prefix + "webm",
XAac: prefix + "x-aac",
XAiff: prefix + "x-aiff",
XMidi: prefix + "x-midi",
XMpegurl: prefix + "x-mpegurl",
XMsWma: prefix + "x-ms-wma",
XWav: prefix + "x-wav"
Expand All @@ -54,12 +87,14 @@ const MimeTypes = Object.freeze({
}))("font/"),

Image: (prefix => Object.freeze({
Avif: prefix + "avif",
Bmp: prefix + "bmp",
Gif: prefix + "gif",
Jpeg: prefix + "jpeg",
Png: prefix + "png",
SvgXml: prefix + "svg+xml",
Tiff: prefix + "tiff",
VndMicrosoftIcon: prefix + "vnd.microsoft.icon",
Webp: prefix + "webp"
}))("image/"),

Expand All @@ -71,6 +106,7 @@ const MimeTypes = Object.freeze({
}))("multipart/"),

Text: (prefix => Object.freeze({
Calendar: prefix + "calendar",
Css: prefix + "css",
Csv: prefix + "csv",
Html: prefix + "html",
Expand All @@ -84,12 +120,15 @@ const MimeTypes = Object.freeze({

Video: (prefix => Object.freeze({
H264: prefix + "h264",
Mp2t: prefix + "mp2t",
Mp4: prefix + "mp4",
Mpeg: prefix + "mpeg",
Ogg: prefix + "ogg",
Quicktime: prefix + "quicktime",
ThreeGpp: prefix + "3gpp",
Webm: prefix + "webm"
ThreeGpp2: prefix + "3gpp2",
Webm: prefix + "webm",
XMsvideo: prefix + "x-msvideo"
}))("video/")
});

Expand Down
45 changes: 42 additions & 3 deletions test/mime-types-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ QUnit.module("MimeTypes");
assertEqual("application/atom+xml", MimeTypes.Application.AtomXml);
assertEqual("application/atomcat+xml", MimeTypes.Application.AtomcatXml);
assertEqual("application/ecmascript", MimeTypes.Application.Ecmascript);
assertEqual("application/epub+zip", MimeTypes.Application.EpubZip);
assertEqual("application/gzip", MimeTypes.Application.Gzip);
assertEqual("application/java-archive", MimeTypes.Application.JavaArchive);
assertEqual("application/javascript", MimeTypes.Application.Javascript);
assertEqual("application/json", MimeTypes.Application.Json);
assertEqual("application/ld+json", MimeTypes.Application.LdJson);
assertEqual("application/mp4", MimeTypes.Application.Mp4);
assertEqual("application/msword", MimeTypes.Application.Msword);
assertEqual("application/octet-stream", MimeTypes.Application.OctetStream);
assertEqual("application/ogg", MimeTypes.Application.Ogg);
assertEqual("application/pdf", MimeTypes.Application.Pdf);
assertEqual("application/pkcs10", MimeTypes.Application.Pkcs10);
assertEqual("application/pkcs7-mime", MimeTypes.Application.Pkcs7Mime);
Expand All @@ -22,25 +27,53 @@ assertEqual("application/rdf+xml", MimeTypes.Application.RdfXml);
assertEqual("application/rss+xml", MimeTypes.Application.RssXml);
assertEqual("application/rtf", MimeTypes.Application.Rtf);
assertEqual("application/smil+xml", MimeTypes.Application.SmilXml);
assertEqual("application/vnd.amazon.ebook", MimeTypes.Application.VndAmazonEbook);
assertEqual("application/vnd.apple.installer+xml", MimeTypes.Application.VndAppleInstallerXml);
assertEqual("application/vnd.mozilla.xul+xml", MimeTypes.Application.VndMozillaXulXml);
assertEqual("application/vnd.ms-excel", MimeTypes.Application.VndMsExcel);
assertEqual("application/vnd.ms-fontobject", MimeTypes.Application.VndMsFontobject);
assertEqual("application/vnd.ms-powerpoint", MimeTypes.Application.VndMsPowerpoint);
assertEqual("application/vnd.oasis.opendocument.presentation", MimeTypes.Application.VndOasisOpendocumentPresentation);
assertEqual("application/vnd.oasis.opendocument.spreadsheet", MimeTypes.Application.VndOasisOpendocumentSpreadsheet);
assertEqual("application/vnd.oasis.opendocument.text", MimeTypes.Application.VndOasisOpendocumentText);
assertEqual("application/vnd.openxmlformats-officedocument.presentationml.presentation", MimeTypes.Application.VndOpenxmlformatsOfficedocumentPresentationmlPresentation);
assertEqual("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", MimeTypes.Application.VndOpenxmlformatsOfficedocumentSpreadsheetmlSheet);
assertEqual("application/vnd.openxmlformats-officedocument.wordprocessingml.document", MimeTypes.Application.VndOpenxmlformatsOfficedocumentWordprocessingmlDocument);
assertEqual("application/vnd.rar", MimeTypes.Application.VndRar);
assertEqual("application/vnd.visio", MimeTypes.Application.VndVisio);
assertEqual("application/x-7z-compressed", MimeTypes.Application.X7zCompressed);
assertEqual("application/x-abiword", MimeTypes.Application.XAbiword);
assertEqual("application/x-bzip", MimeTypes.Application.XBzip);
assertEqual("application/x-bzip2", MimeTypes.Application.XBzip2);
assertEqual("application/x-cdf", MimeTypes.Application.XCdf);
assertEqual("application/x-csh", MimeTypes.Application.XCsh);
assertEqual("application/x-font-off", MimeTypes.Application.XFontOff);
assertEqual("application/x-pkcs12", MimeTypes.Application.XPkcs12);
assertEqual("application/x-shockwave-flash", MimeTypes.Application.XShockwaveFlash);
assertEqual("application/x-silverlight-app", MimeTypes.Application.XSilverlightApp);
assertEqual("application/x-freearc", MimeTypes.Application.XFreearc);
assertEqual("application/xhtml+xml", MimeTypes.Application.XhtmlXml);
assertEqual("application/x-httpd-php", MimeTypes.Application.XHttpdPhp);
assertEqual("application/xml", MimeTypes.Application.Xml);
assertEqual("application/xml-dtd", MimeTypes.Application.XmlDtd);
assertEqual("application/x-pkcs12", MimeTypes.Application.XPkcs12);
assertEqual("application/x-shockwave-flash", MimeTypes.Application.XShockwaveFlash);
assertEqual("application/x-sh", MimeTypes.Application.XSh);
assertEqual("application/x-silverlight-app", MimeTypes.Application.XSilverlightApp);
assertEqual("application/xslt+xml", MimeTypes.Application.XsltXml);
assertEqual("application/x-tar", MimeTypes.Application.XTar);
assertEqual("application/x-www-form-urlencoded", MimeTypes.Application.XWwwFormUrlencoded);
assertEqual("application/zip", MimeTypes.Application.Zip);

assertEqual("audio/midi", MimeTypes.Audio.Midi);
assertEqual("audio/mp4", MimeTypes.Audio.Mp4);
assertEqual("audio/mpeg", MimeTypes.Audio.Mpeg);
assertEqual("audio/ogg", MimeTypes.Audio.Ogg);
assertEqual("audio/opus", MimeTypes.Audio.Opus);
assertEqual("audio/3gpp", MimeTypes.Audio.Threegpp);
assertEqual("audio/3gpp2", MimeTypes.Audio.Threegpp2);
assertEqual("audio/wav", MimeTypes.Audio.Wav);
assertEqual("audio/webm", MimeTypes.Audio.Webm);
assertEqual("audio/x-aac", MimeTypes.Audio.XAac);
assertEqual("audio/x-aiff", MimeTypes.Audio.XAiff);
assertEqual("audio/x-midi", MimeTypes.Audio.XMidi);
assertEqual("audio/x-mpegurl", MimeTypes.Audio.XMpegurl);
assertEqual("audio/x-ms-wma", MimeTypes.Audio.XMsWma);
assertEqual("audio/x-wav", MimeTypes.Audio.XWav);
Expand All @@ -52,19 +85,22 @@ assertEqual("font/ttf", MimeTypes.Font.Ttf);
assertEqual("font/woff", MimeTypes.Font.Woff);
assertEqual("font/woff2", MimeTypes.Font.Woff2);

assertEqual("image/avif", MimeTypes.Image.Avif);
assertEqual("image/bmp", MimeTypes.Image.Bmp);
assertEqual("image/gif", MimeTypes.Image.Gif);
assertEqual("image/jpeg", MimeTypes.Image.Jpeg);
assertEqual("image/png", MimeTypes.Image.Png);
assertEqual("image/svg+xml", MimeTypes.Image.SvgXml);
assertEqual("image/tiff", MimeTypes.Image.Tiff);
assertEqual("image/vnd.microsoft.icon", MimeTypes.Image.VndMicrosoftIcon);
assertEqual("image/webp", MimeTypes.Image.Webp);

assertEqual("multipart/byteranges", MimeTypes.Multipart.Byteranges);
assertEqual("multipart/encrypted", MimeTypes.Multipart.Encrypted);
assertEqual("multipart/form-data", MimeTypes.Multipart.FormData);
assertEqual("multipart/related", MimeTypes.Multipart.Related);

assertEqual("text/calendar", MimeTypes.Text.Calendar);
assertEqual("text/css", MimeTypes.Text.Css);
assertEqual("text/csv", MimeTypes.Text.Csv);
assertEqual("text/html", MimeTypes.Text.Html);
Expand All @@ -76,12 +112,15 @@ assertEqual("text/xml", MimeTypes.Text.Xml);
assertEqual("text/yaml", MimeTypes.Text.Yaml);

assertEqual("video/h264", MimeTypes.Video.H264);
assertEqual("video/mp2t", MimeTypes.Video.Mp2t);
assertEqual("video/mp4", MimeTypes.Video.Mp4);
assertEqual("video/mpeg", MimeTypes.Video.Mpeg);
assertEqual("video/ogg", MimeTypes.Video.Ogg);
assertEqual("video/quicktime", MimeTypes.Video.Quicktime);
assertEqual("video/3gpp", MimeTypes.Video.ThreeGpp);
assertEqual("video/3gpp2", MimeTypes.Video.ThreeGpp2);
assertEqual("video/webm", MimeTypes.Video.Webm);
assertEqual("video/x-msvideo", MimeTypes.Video.XMsvideo);

function assertEqual(expected, actual) {
QUnit.test("Test " + expected, (assert) => assert.equal(expected, actual));
Expand Down

0 comments on commit 3762615

Please sign in to comment.