-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.js
38 lines (32 loc) · 1.06 KB
/
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
37
38
define(function (require, exports, module) {
'use strict';
var ProjectManager = brackets.getModule('project/ProjectManager');
// Transform a partial, relative, or full path into a full path.
function resolvePath(path) {
var i = 0,
parent = path[0] === '/' ? '' : ProjectManager.getProjectRoot().fullPath,
dirs = (parent + path).split('/');
while (i < dirs.length) {
switch (dirs[i]) {
case '':
// Leave a preceding or trailing slash.
if (i === 0 || i === dirs.length - 1) {
i++;
break;
}
case '.':
dirs.splice(i, 1);
break;
case '..':
dirs.splice(i - 1, 2);
i -= 1;
break;
default:
i++;
break;
}
}
return dirs.join('/');
}
exports.resolvePath = resolvePath;
});