unpkg/modules/utils/getContentType.js

29 lines
500 B
JavaScript
Raw Normal View History

import path from 'path';
2019-01-06 00:50:05 +00:00
import mime from 'mime';
2019-01-06 00:50:05 +00:00
mime.define(
{
'text/plain': [
'authors',
'changes',
'license',
'makefile',
'patents',
'readme',
'ts',
'flow'
]
},
/* force */ true
);
const textFiles = /\/?(\.[a-z]*rc|\.git[a-z]*|\.[a-z]*ignore|\.lock)$/i;
2019-01-06 00:50:05 +00:00
export default function getContentType(file) {
const name = path.basename(file);
return textFiles.test(name)
? 'text/plain'
: mime.getType(name) || 'text/plain';
}