modern-valhalla
Version:
Private npm repository server
32 lines (27 loc) • 668 B
JavaScript
const path = require('path');
// TODO: use mime-type package?
function getMimeType(extension) {
return {
'.js': 'application/javascript',
'.css': 'text/css',
'.map': 'application/json',
'.gif': 'image/gif',
'.jpg': 'image/jpeg',
'.png': 'image/png',
'.svg': 'image/svg+xml',
'.tgz': 'application/gzip',
'.gz': 'application/gzip',
}[extension];
}
function getFileInfo(filePath) {
let ext = path.extname(filePath).toLowerCase();
let isGzipped = ext === '.gz' || ext === '.tgz' || ext === '.zip';
return {
gzip: isGzipped,
extname: ext,
mimeType: getMimeType(ext),
};
}
module.exports = {
getFileInfo,
};