diff options
Diffstat (limited to 'lib/path.js')
-rw-r--r-- | lib/path.js | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/lib/path.js b/lib/path.js index 64e34ecde66..b42889ebfc7 100644 --- a/lib/path.js +++ b/lib/path.js @@ -140,6 +140,18 @@ function normalizeStringPosix(path, allowAboveRoot) { return res; } +function _format(sep, pathObject) { + const dir = pathObject.dir || pathObject.root; + const base = pathObject.base || + ((pathObject.name || '') + (pathObject.ext || '')); + if (!dir) { + return base; + } + if (dir === pathObject.root) { + return dir + base; + } + return dir + sep + base; +} const win32 = { // path.resolve([from ...], to) @@ -970,20 +982,10 @@ const win32 = { format: function format(pathObject) { if (pathObject === null || typeof pathObject !== 'object') { throw new TypeError( - 'Parameter "pathObject" must be an object, not ' + typeof pathObject + `Parameter "pathObject" must be an object, not ${typeof pathObject}` ); } - - var dir = pathObject.dir || pathObject.root; - var base = pathObject.base || - ((pathObject.name || '') + (pathObject.ext || '')); - if (!dir) { - return base; - } - if (dir === pathObject.root) { - return dir + base; - } - return dir + win32.sep + base; + return _format('\\', pathObject); }, @@ -1525,20 +1527,10 @@ const posix = { format: function format(pathObject) { if (pathObject === null || typeof pathObject !== 'object') { throw new TypeError( - 'Parameter "pathObject" must be an object, not ' + typeof pathObject + `Parameter "pathObject" must be an object, not ${typeof pathObject}` ); } - - var dir = pathObject.dir || pathObject.root; - var base = pathObject.base || - ((pathObject.name || '') + (pathObject.ext || '')); - if (!dir) { - return base; - } - if (dir === pathObject.root) { - return dir + base; - } - return dir + posix.sep + base; + return _format('/', pathObject); }, |