forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpath.js
31 lines (26 loc) · 1.01 KB
/
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
'use strict';
module.exports = {
/**
Returns a relative parent path string using the path provided
@method getRelativeParentPath
@param {String} path The path to relatively get to.
@return {String} the relative path string.
*/
getRelativeParentPath: function getRelativeParentPath(path, offset, slash) {
var offsetValue = offset || 0;
var trailingSlash = typeof slash === 'undefined' ? true : slash;
var outputPath = new Array(path.split('/').length + 1 - offsetValue).join('../');
return trailingSlash ? outputPath : outputPath.substr(0, outputPath.length - 1);
},
/**
Returns a relative path string using the path provided
@method getRelativePath
@param {String} path The path to relatively get to.
@return {String} the relative path string.
*/
getRelativePath: function getRelativePath(path, offset) {
var offsetValue = offset || 0;
var relativePath = new Array(path.split('/').length - offsetValue).join('../');
return relativePath || './';
}
};