Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add 'path.sep' to get the path separator. #3057

Closed
wants to merge 3 commits into from

3 participants

@npcode

This patch adds 'sep' property into path module, to get the path separator, like python's os.path.sep.

It will be useful to write a platform-independent code to parse a path.

posix:

'a/b/c'.split(require('path').sep) // => ['a', 'b', 'c']

win32:

'a\\b\\c'.split(require('path').sep) // => ['a', 'b', 'c']
@TooTallNate

Seems like an ok idea to me (though usually using the path module will do what you need). Needs tests and docs.

@npcode

Ok, I have done.

@bnoordhuis

Yi, I'll merge this but can you sign the CLA first? Thanks.

@npcode
@bnoordhuis

Thanks Yi, merged in 4bd54da.

@bnoordhuis bnoordhuis closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 2, 2012
  1. @npcode
Commits on Apr 3, 2012
  1. @npcode
  2. @npcode
This page is out of date. Refresh to see the latest.
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
16 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']
View
2  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 = '/';
}
View
8 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, '/');
+}
Something went wrong with that request. Please try again.