unpkg/modules/utils/getContentType.js
Michael Jackson 34baab07ab New "browse" UI
Also, separated out browse, ?meta, and ?module request handlers.

Fixes #82
2019-07-26 15:31:46 -07:00

29 lines
500 B
JavaScript

import path from 'path';
import mime from 'mime';
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;
export default function getContentType(file) {
const name = path.basename(file);
return textFiles.test(name)
? 'text/plain'
: mime.getType(name) || 'text/plain';
}