all files / blackbird/modules/utils/ getMimeType.js

100% Statements 11/11
100% Branches 4/4
100% Functions 3/3
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19   75× 103×         110× 110×      
const MimeTypes = require("../MimeTypes");
const ExtTypes = {};
 
Object.keys(MimeTypes).forEach(function (type) {
    MimeTypes[type].forEach(function (ext) {
        ExtTypes[ext] = type;
    });
});
 
const DEFAULT_TYPE = "application/octet-stream";
const EXT_MATCHER = /\.(\w+)$/;
 
function getMimeType(file, defaultType) {
    const match = file.match(EXT_MATCHER);
    return match && ExtTypes[match[1]] || defaultType || DEFAULT_TYPE;
}
 
module.exports = getMimeType;