From 4bd54dad33722e93bae5a16f6b274d08944c24cc Mon Sep 17 00:00:00 2001 From: "Yi, EungJun" Date: Tue, 3 Apr 2012 01:31:21 +0900 Subject: [PATCH] path: add path.sep to get the path separator. --- doc/api/path.markdown | 16 ++++++++++++++++ lib/path.js | 2 ++ test/simple/test-path.js | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/doc/api/path.markdown b/doc/api/path.markdown index 5e0957d257..d178b53f1f 100644 --- a/doc/api/path.markdown +++ b/doc/api/path.markdown @@ -138,3 +138,19 @@ an empty string. Examples: path.extname('index') // returns '' + +## path.sep + +The platform-specific file separator. `'\\'` or `'/'`. + +An example on linux: + + 'foo/bar/baz'.split(path.sep) + // returns + ['foo', 'bar', 'baz'] + +An example on windows: + + 'foo\\bar\\baz'.split(path.sep) + // returns + ['foo', 'bar', 'baz'] diff --git a/lib/path.js b/lib/path.js index 148b2af9a1..ad8fd8d787 100644 --- a/lib/path.js +++ b/lib/path.js @@ -258,6 +258,7 @@ if (isWindows) { return outputParts.join('\\'); }; + exports.sep = '\\'; } else /* posix */ { @@ -373,6 +374,7 @@ if (isWindows) { return outputParts.join('/'); }; + exports.sep = '/'; } diff --git a/test/simple/test-path.js b/test/simple/test-path.js index caf86aa465..a5c7372d7d 100644 --- a/test/simple/test-path.js +++ b/test/simple/test-path.js @@ -273,3 +273,11 @@ relativeTests.forEach(function(test) { }); assert.equal(failures.length, 0, failures.join('')); +// path.sep tests +if (isWindows) { + // windows + assert.equal(path.sep, '\\'); +} else { + // posix + assert.equal(path.sep, '/'); +}