mime.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. var each = require('./each');
  2. var exts = {
  3. 'image/jpeg': ['jpeg', 'jpg'],
  4. 'image/png': ['png'],
  5. 'image/gif': ['gif'],
  6. 'image/webp': ['webp'],
  7. 'image/tiff': ['tif', 'tiff'],
  8. 'image/bmp': ['bmp'],
  9. 'image/vnd.adobe.photoshop': ['psd'],
  10. 'image/svg+xml': ['svg'],
  11. 'audio/mp4': ['m4a', 'mp4a'],
  12. 'audio/midi': ['midi'],
  13. 'audio/mpeg': ['mpga', 'mp2', 'mp2a', 'mp3', 'm2a', 'm3a'],
  14. 'audio/ogg': ['ogg'],
  15. 'audio/wav': ['wav'],
  16. 'video/mp4': ['mp4', 'mp4v', 'mpg4'],
  17. 'video/x-matroska': ['mkv'],
  18. 'video/webm': ['webm'],
  19. 'video/x-msvideo': ['avi'],
  20. 'video/quicktime': ['qt', 'mov'],
  21. 'video/mpeg': ['mpeg', 'mpg', 'mpe', 'm1v', 'm2v'],
  22. 'video/3gpp': ['3gp', '3gpp'],
  23. 'text/css': ['css'],
  24. 'text/html': ['html', 'htm', 'shtml'],
  25. 'text/yaml': ['yaml', 'yml'],
  26. 'text/csv': ['csv'],
  27. 'text/markdown': ['markdown', 'md'],
  28. 'text/plain': ['txt', 'text', 'conf', 'log', 'ini'],
  29. 'font/ttf': ['ttf'],
  30. 'font/woff': ['woff'],
  31. 'font/woff2': ['woff2'],
  32. 'application/zip': ['zip'],
  33. 'application/x-tar': ['tar'],
  34. 'application/x-rar-compressed': ['rar'],
  35. 'application/gzip': ['gz'],
  36. 'application/x-7z-compressed': ['7z'],
  37. 'application/octet-stream': [
  38. 'bin',
  39. 'so',
  40. 'exe',
  41. 'dll',
  42. 'dmg',
  43. 'iso',
  44. 'msi'
  45. ],
  46. 'application/epub+zip': ['epub'],
  47. 'application/javascript': ['js'],
  48. 'application/json': ['json'],
  49. 'application/msword': ['doc', 'docx', 'dot', 'dotx'],
  50. 'application/vnd.ms-excel': ['xls', 'xlsx', 'xla', 'xlt'],
  51. 'application/vnd.ms-powerpoint': ['ppt', 'pptx', 'pps', 'pot'],
  52. 'application/pdf': ['pdf'],
  53. 'application/wasm': ['wasm'],
  54. 'application/xml': ['xml'],
  55. 'application/xml-dtd': ['dtd']
  56. };
  57. var mimeTypes = {};
  58. each(exts, function(ext, mimeType) {
  59. each(ext, function(e) {
  60. mimeTypes[e] = mimeType;
  61. });
  62. });
  63. exports = function(name) {
  64. return (isMimeType(name) ? getExt(name) : getType(name)) || undefined;
  65. };
  66. function getType(name) {
  67. return mimeTypes[name];
  68. }
  69. function getExt(name) {
  70. if (exts[name]) {
  71. return exts[name][0];
  72. }
  73. }
  74. function isMimeType(name) {
  75. return name.indexOf('/') > -1;
  76. }
  77. module.exports = exports;