Comparing version 1.0.0 to 1.1.0
@@ -5,8 +5,9 @@ var path = require('path'), | ||
function caroot(caretedPath, currentPath) { | ||
function caroot(caretedPath, currentPath, rootSubDirectory) { | ||
if(caretedPath.charAt(0) === '^') { | ||
var filePath = caretedPath.slice(1), | ||
root = findRoot(currentPath), | ||
x = path.relative(path.dirname(currentPath), root), | ||
result = path.join(x, filePath); | ||
rootBase = findRoot(currentPath), | ||
root = rootSubDirectory ? path.join(rootBase, rootSubDirectory) : rootBase, | ||
relativePath = path.relative(path.dirname(currentPath), root), | ||
result = path.join(relativePath, filePath); | ||
@@ -13,0 +14,0 @@ if(result.match(relativeRegex)){ |
{ | ||
"name": "caroot", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Replaces a caret with the root path", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,2 +7,4 @@ # caroot | ||
caroot(caretedPath, currentPath[, rootSubDirectory]) | ||
```javascript | ||
@@ -18,2 +20,9 @@ | ||
// also takes an optional root sub directory | ||
caroot('^foo', __dirname, './scripts'); | ||
// returns '../foo' | ||
``` |
@@ -5,6 +5,5 @@ var test = require('tape'), | ||
function resolve(caretedPath, currentPath){ | ||
function resolve(caretedPath, currentPath, subDirectory){ | ||
var directory = path.resolve(__dirname, currentPath); | ||
return caroot(caretedPath, directory); | ||
return caroot(caretedPath, directory, subDirectory); | ||
} | ||
@@ -112,1 +111,11 @@ | ||
}); | ||
test('root sub directory', function(t) { | ||
t.plan(1); | ||
t.equal( | ||
resolve('^things/stuff', './foo/bar/things/stuff/majigger', './tests/foo/bar/'), | ||
'../../things/stuff', | ||
'Resolves correctly' | ||
); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5643
111
27