forked from ionteamza/redexutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaths.js
62 lines (57 loc) · 1.59 KB
/
Paths.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2015, Evan Summers (twitter.com/evanxsummers)
// ISC license, see http://github.com/evanx/redexutil/LICENSE
import path from 'path';
import lodash from 'lodash';
const logger = Loggers.create(__filename, 'info');
const mimeTypes = {
md: 'text/x-markdown',
html: 'text/html',
txt: 'text/plain',
json: 'application/json',
js: 'text/javascript',
css: 'text/css',
ico: 'image/x-icon',
jpeg: 'image/jpeg',
jpg: 'image/jpeg',
png: 'image/png',
svg: 'image/svg+xml',
otf: 'application/font-sfnt',
ttf: 'application/font-sfnt',
eot: 'application/vnd.ms-fontobject',
woff: 'application/font-woff',
woff2: 'font/font-woff2'
};
const defaultContentType = 'application/octet-stream';
module.exports = {
defaultContentType: defaultContentType,
getContentType(uri) {
if (!lodash.isEmpty(uri)) {
let ext = path.extname(uri);
if (ext) {
ext = ext.substring(1);
ext = ext.toLowerCase();
if (mimeTypes.hasOwnProperty(ext)) {
return mimeTypes[ext];
}
}
}
return defaultContentType;
},
join(dir, file) {
if (lodash.endsWith(dir, '/') && lodash.startsWith(file, '/')) {
return dir + file.substring(1);
} else if (lodash.endsWith(dir, '/') || lodash.startsWith(file, '/')) {
return dir + file;
} else {
return dir + '/' + file;
}
},
basename(file) {
var matcher = file.match(/([^\/]+)\.[a-z]+$/);
if (matcher) {
return matcher[1];
} else {
return file;
}
}
};