New "browse" UI
Also, separated out browse, ?meta, and ?module request handlers. Fixes #82
This commit is contained in:
36
modules/utils/getLanguageName.js
Normal file
36
modules/utils/getLanguageName.js
Normal file
@ -0,0 +1,36 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user