๐Ÿ“ฆ EdwonLim / node-less

๐Ÿ“„ mime.js ยท 29 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29(function(module) {

    var Mime = {
        _types: {
            '.htm' : 'text/html',
            '.html': 'text/html',
            '.gif' : 'image/gif',
            '.jpg' : 'image/jpeg',
            '.jpeg': 'image/jpeg',
            '.png' : 'image/png'
        },
        lookup: function (filepath) {
            var ext = require('path').extname(filepath),
                type = Mime._types[ext];
            if (type === undefined) {
                throw new Error('Optional dependency "mime" is required for ' + ext);
            }
            return type;
        },
        charsets: {
            lookup: function (type) {
                return type && (/^text\//).test(type) ? 'UTF-8' : '';
            }
        }
    };

    module.exports = Mime;

})(module);