Browse Source

path: add platform specific path delimiter

Closes #3728
Closes #4071
v0.9.3-release
Paul Serby 12 years ago
committed by Bert Belder
parent
commit
41e53e5579
  1. 28
      doc/api/path.markdown
  2. 2
      lib/path.js
  3. 9
      test/simple/test-path.js

28
doc/api/path.markdown

@ -14,7 +14,7 @@ Normalize a string path, taking care of `'..'` and `'.'` parts.
When multiple slashes are found, they're replaced by a single one;
when the path contains a trailing slash, it is preserved.
On windows backslashes are used.
On Windows backslashes are used.
Example:
@ -143,14 +143,36 @@ an empty string. Examples:
The platform-specific file separator. `'\\'` or `'/'`.
An example on linux:
An example on *nix:
'foo/bar/baz'.split(path.sep)
// returns
['foo', 'bar', 'baz']
An example on windows:
An example on Windows:
'foo\\bar\\baz'.split(path.sep)
// returns
['foo', 'bar', 'baz']
## path.delimiter
The platform-specific path delimiter, `;` or `':'`.
An example on *nix:
console.log(process.env.PATH)
// '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'
process.env.PATH.split(path.delimiter)
// returns
['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin']
An example on Windows:
console.log(process.env.PATH)
// 'C:\Windows\system32;C:\Windows;C:\Program Files\nodejs\'
process.env.PATH.split(path.delimiter)
// returns
['C:\Windows\system32', 'C:\Windows', 'C:\Program Files\nodejs\']

2
lib/path.js

@ -262,6 +262,7 @@ if (isWindows) {
};
exports.sep = '\\';
exports.delimiter = ';';
} else /* posix */ {
@ -378,6 +379,7 @@ if (isWindows) {
};
exports.sep = '/';
exports.delimiter = ':';
}

9
test/simple/test-path.js

@ -283,3 +283,12 @@ if (isWindows) {
// posix
assert.equal(path.sep, '/');
}
// path.delimiter tests
if (isWindows) {
// windows
assert.equal(path.delimiter, ';');
} else {
// posix
assert.equal(path.delimiter, ':');
}

Loading…
Cancel
Save