37 lines
1.0 KiB
JavaScript
37 lines
1.0 KiB
JavaScript
import getContentType from './getContentType.js';
|
|
|
|
const contentTypeNames = {
|
|
'application/javascript': 'JavaScript',
|
|
'application/json': 'JSON',
|
|
'application/octet-stream': 'Binary',
|
|
'application/vnd.ms-fontobject': 'Embedded OpenType',
|
|
'application/xml': 'XML',
|
|
'image/svg+xml': 'SVG',
|
|
'font/ttf': 'TrueType Font',
|
|
'font/woff': 'WOFF',
|
|
'font/woff2': 'WOFF2',
|
|
'text/css': 'CSS',
|
|
'text/html': 'HTML',
|
|
'text/jsx': 'JSX',
|
|
'text/markdown': 'Markdown',
|
|
'text/plain': 'Plain Text',
|
|
'text/x-scss': 'SCSS',
|
|
'text/yaml': 'YAML'
|
|
};
|
|
|
|
/**
|
|
* Gets a human-friendly name for whatever is in the given file.
|
|
*/
|
|
export default function getLanguageName(file) {
|
|
// Content-Type is text/plain, but we can be more descriptive.
|
|
if (/\.flow$/.test(file)) return 'Flow';
|
|
if (/\.(d\.ts|tsx)$/.test(file)) return 'TypeScript';
|
|
|
|
// Content-Type is application/json, but we can be more descriptive.
|
|
if (/\.map$/.test(file)) return 'Source Map (JSON)';
|
|
|
|
const contentType = getContentType(file);
|
|
|
|
return contentTypeNames[contentType] || contentType;
|
|
}
|