diff options
Diffstat (limited to 'lib/path.js')
-rw-r--r-- | lib/path.js | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/lib/path.js b/lib/path.js index 694cd38425..0a2c0d6bce 100644 --- a/lib/path.js +++ b/lib/path.js @@ -361,21 +361,13 @@ win32.format = function(pathObject) { ); } - var root = pathObject.root || ''; - - if (typeof root !== 'string') { - throw new TypeError( - '"pathObject.root" must be a string or undefined, not ' + - typeof pathObject.root - ); - } - - var dir = pathObject.dir; - var base = pathObject.base || ''; + var dir = pathObject.dir || pathObject.root; + var base = pathObject.base || + ((pathObject.name || '') + (pathObject.ext || '')); if (!dir) { return base; } - if (dir[dir.length - 1] === win32.sep) { + if (dir === pathObject.root) { return dir + base; } return dir + win32.sep + base; @@ -570,18 +562,16 @@ posix.format = function(pathObject) { ); } - var root = pathObject.root || ''; - - if (typeof root !== 'string') { - throw new TypeError( - '"pathObject.root" must be a string or undefined, not ' + - typeof pathObject.root - ); + var dir = pathObject.dir || pathObject.root; + var base = pathObject.base || + ((pathObject.name || '') + (pathObject.ext || '')); + if (!dir) { + return base; } - - var dir = pathObject.dir ? pathObject.dir + posix.sep : ''; - var base = pathObject.base || ''; - return dir + base; + if (dir === pathObject.root) { + return dir + base; + } + return dir + posix.sep + base; }; |