UNPKG

624 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 pdf: `${app}/pdf`,
24 png: 'image/png',
25 svg: 'image/svg+xml',
26 text,
27 txt: text,
28 xml: `${app}/xml`
29}
30
31module.exports = mime || {
32 getType: extension => {
33 if (extension.charAt(0) === '.') {
34 extension = extension.substring(1)
35 }
36 return types[extension] || types.bin
37 }
38}