blob: 32bec68a5c95bce8e0c323d6f83f562378139072 (
plain)
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
|
/*!
* Piwik - free/libre analytics platform
*
* path related functions
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
exports.join = function () {
return Array.prototype.join.call(arguments, "/").replace(/[\\\/]{2,}/g, "/");
};
exports.dirname = function (path) {
var lastSeparator = path.lastIndexOf("/");
return lastSeparator == -1 ? path : path.substring(0, lastSeparator);
};
exports.basename = function (path) {
var lastSeparator = path.lastIndexOf("/");
return lastSeparator == -1 ? path : path.substring(lastSeparator + 1);
};
exports.resolve = function (path) {
if (path.charAt(0) != '/') {
path = exports.join(__dirname, path);
}
var path_split = path.split('/'),
result = [];
for (var i = 0; i != path_split.length; ++i) {
if (path_split[i] == '.') {
continue;
} else if (path_split[i] == '..') {
result.pop();
} else {
result.push(path_split[i]);
}
}
return exports.join.apply(exports, result);
};
|