-
Notifications
You must be signed in to change notification settings - Fork 2
/
proper_path.js
31 lines (25 loc) · 1 KB
/
proper_path.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
var _DEBUG = false;
module.exports = function (resource_path, open_head) {
if (typeof resource_path != 'string'){
throw new Error('proper_path:: bad path %s', util.inspect(resource_path));
}
if (_DEBUG) console.log('proper pathing %s', resource_path);
if (resource_path == ''){
if (open_head){
return '';
} else {
return '/';
}
} else if (resource_path == '/'){
// console.log('root %s returning "/"', resource_path);
return '/';
} else if ((!open_head) && (resource_path.substring(0, 1) != '/')) { // insisting on first "/" being present
resource_path = '/' + resource_path;
}
if (resource_path.substr(-1) == '/') { // insisting on NOT ending in "/";
// console.log('removing trailing "/" from %s', resource_path);
resource_path = resource_path.substring(0, resource_path.length - 1);
}
// console.log('proper_path - pathing returning %s', resource_path);
return resource_path;
}