Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
path: add path.sep to get the path separator.
Browse files Browse the repository at this point in the history
  • Loading branch information
eungjun-yi authored and bnoordhuis committed May 1, 2012
1 parent 6ba3e68 commit 4bd54da
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions doc/api/path.markdown
Expand Up @@ -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']
2 changes: 2 additions & 0 deletions lib/path.js
Expand Up @@ -258,6 +258,7 @@ if (isWindows) {
return outputParts.join('\\');
};

exports.sep = '\\';

} else /* posix */ {

Expand Down Expand Up @@ -373,6 +374,7 @@ if (isWindows) {
return outputParts.join('/');
};

exports.sep = '/';
}


Expand Down
8 changes: 8 additions & 0 deletions test/simple/test-path.js
Expand Up @@ -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.