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

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions doc/api/path.markdown
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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, '/');
}