unpkg/server/utils/getFileContentType.js

23 lines
392 B
JavaScript
Raw Normal View History

2018-02-18 02:00:56 +00:00
const mime = require("mime");
2017-08-18 19:57:42 +00:00
mime.define({
2018-02-18 02:00:56 +00:00
"text/plain": [
"authors",
"changes",
"license",
"makefile",
"patents",
"readme",
"ts",
"flow"
]
});
2017-08-18 19:57:42 +00:00
2018-02-18 02:00:56 +00:00
const TextFiles = /\/?(\.[a-z]*rc|\.git[a-z]*|\.[a-z]*ignore)$/i;
2017-08-18 19:57:42 +00:00
function getFileContentType(file) {
2018-02-18 02:00:56 +00:00
return TextFiles.test(file) ? "text/plain" : mime.lookup(file);
2017-08-18 19:57:42 +00:00
}
2018-02-18 02:00:56 +00:00
module.exports = getFileContentType;