-
Notifications
You must be signed in to change notification settings - Fork 7
/
utils.js
36 lines (33 loc) · 868 Bytes
/
utils.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
var url = require('url');
var path = require('path');
var fs = require('fs');
var Utils = {
joinUri: function(absolute, relative) {
var parse = url.parse(absolute);
parse.pathname = path.join(parse.pathname, relative);
return url.format(parse);
},
getUriPath: function(uri, base) {
base = base || '';
var parse = url.parse(uri);
return path.relative('.', path.join(base, parse.pathname));
},
isAbsolute: function(uri) {
var parsed = url.parse(uri);
if (parsed.protocol) {
return true;
}
return false;
},
fileExists: function(file) {
try {
return fs.statSync(file).isFile();
} catch(e) {
return false;
}
},
localize: function(parentUri, childUri) {
return path.join(path.basename(parentUri, path.extname(parentUri)), path.basename(childUri));
}
};
module.exports = Utils;