UNPKG

720 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 json: `${app}/json`,
24 mp4: 'video/mp4',
25 pdf: `${app}/pdf`,
26 png: 'image/png',
27 svg: 'image/svg+xml',
28 text,
29 txt: text,
30 xml: `${app}/xml`
31}
32
33if (mime && !mime.getType && mime.lookup) {
34 const mimeV1 = mime
35 mime = {
36 getType: extension => mimeV1.lookup(extension)
37 }
38}
39
40if (mime) {
41 module.exports = mime.getType
42} else {
43 module.exports = extension => types[extension]
44}