UNPKG

850 BJavaScriptView Raw
1'use strict'
2
3let mime
4
5try {
6 mime = require('mime')
7} catch (e) {}
8
9const app = 'application'
10const html = 'text/html'
11const jpeg = 'image/jpeg'
12const text = 'text/plain'
13
14const types = {
15 bin: `${app}/octet-stream`,
16 css: 'text/css',
17 gif: 'image/gif',
18 html,
19 htm: html,
20 jpeg,
21 jpg: jpeg,
22 js: `${app}/javascript`,
23 mp4: 'video/mp4',
24 pdf: `${app}/pdf`,
25 png: 'image/png',
26 svg: 'image/svg+xml',
27 text,
28 txt: text,
29 xml: `${app}/xml`
30}
31
32if (mime && !mime.getType && mime.lookup) {
33 const mimeV1 = mime
34 mime = {
35 getType: extension => mimeV1.lookup(extension)
36 }
37}
38
39if (mime) {
40 module.exports = extension => mime.getType(extension) || types.bin
41} else {
42 module.exports = extension => {
43 if (extension.charAt(0) === '.') {
44 extension = extension.substring(1)
45 }
46 return types[extension] || types.bin
47 }
48}