diff options
author | Ryan Doenges <rhdoenges@gmail.com> | 2013-04-14 12:44:40 -0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-04-19 10:15:22 -0700 |
commit | 90266750617adb1ce1ca4ce43fe48f9b0fa11343 (patch) | |
tree | 16dcbbefbf4b0d9f8fab8a5fcd8fec9873f39d76 /lib/path.js | |
parent | e4406b76dfc024cf5a4051dc73018fc447b3dc7f (diff) | |
download | android-node-v8-90266750617adb1ce1ca4ce43fe48f9b0fa11343.tar.gz android-node-v8-90266750617adb1ce1ca4ce43fe48f9b0fa11343.tar.bz2 android-node-v8-90266750617adb1ce1ca4ce43fe48f9b0fa11343.zip |
path: add path.isAbsolute(path)
An absolute path will always open the same location regardless of your
current working directory. For posix, this just means path.charAt(0) ===
'/', but on Windows it's a little more complicated.
Fixes joyent/node#5299.
Diffstat (limited to 'lib/path.js')
-rw-r--r-- | lib/path.js | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/path.js b/lib/path.js index db0cdea2dd..5cef72fac7 100644 --- a/lib/path.js +++ b/lib/path.js @@ -121,7 +121,7 @@ if (isWindows) { var result = splitDeviceRe.exec(path), device = result[1] || '', isUnc = device && device.charAt(1) !== ':', - isAbsolute = !!result[2] || isUnc, // UNC paths are always absolute + isAbsolute = exports.isAbsolute(path), tail = result[3]; if (device && @@ -172,7 +172,7 @@ if (isWindows) { var result = splitDeviceRe.exec(path), device = result[1] || '', isUnc = device && device.charAt(1) !== ':', - isAbsolute = !!result[2] || isUnc, // UNC paths are always absolute + isAbsolute = exports.isAbsolute(path), tail = result[3], trailingSlash = /[\\\/]$/.test(tail); @@ -203,6 +203,15 @@ if (isWindows) { }; // windows version + exports.isAbsolute = function(path) { + var result = splitDeviceRe.exec(path), + device = result[1] || '', + isUnc = device && device.charAt(1) !== ':'; + // UNC paths are always absolute + return !!result[2] || isUnc; + }; + + // windows version exports.join = function() { function f(p) { if (typeof p !== 'string') { @@ -338,7 +347,7 @@ if (isWindows) { // path.normalize(path) // posix version exports.normalize = function(path) { - var isAbsolute = path.charAt(0) === '/', + var isAbsolute = exports.isAbsolute(path), trailingSlash = path.substr(-1) === '/'; // Normalize the path @@ -356,6 +365,10 @@ if (isWindows) { return (isAbsolute ? '/' : '') + path; }; + // posix version + exports.isAbsolute = function(path) { + return path.charAt(0) === '/'; + }; // posix version exports.join = function() { @@ -416,7 +429,6 @@ if (isWindows) { exports.delimiter = ':'; } - exports.dirname = function(path) { var result = splitPath(path), root = result[0], |