Permalink
Browse files

path: add path.sep to get the path separator.

  • Loading branch information...
1 parent 6ba3e68 commit 4bd54dad33722e93bae5a16f6b274d08944c24cc @npcode npcode committed with bnoordhuis Apr 2, 2012
Showing with 26 additions and 0 deletions.
  1. +16 −0 doc/api/path.markdown
  2. +2 −0 lib/path.js
  3. +8 −0 test/simple/test-path.js
View
@@ -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']
View
@@ -258,6 +258,7 @@ if (isWindows) {
return outputParts.join('\\');
};
+ exports.sep = '\\';
} else /* posix */ {
@@ -373,6 +374,7 @@ if (isWindows) {
return outputParts.join('/');
};
+ exports.sep = '/';
}
@@ -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, '/');
+}

0 comments on commit 4bd54da

Please sign in to comment.