Permalink
Browse files

Platform specific path.delimiter as requested #3728

  • Loading branch information...
serby committed Oct 1, 2012
1 parent 7ada4eb commit 03d93af48f622f2c35d351b647b37bb05043cf27
Showing with 37 additions and 4 deletions.
  1. +26 −4 doc/api/path.markdown
  2. +2 −0 lib/path.js
  3. +9 −0 test/simple/test-path.js
View
@@ -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:
@@ -44,7 +44,7 @@ Resolves `to` to an absolute path.
If `to` isn't already absolute `from` arguments are prepended in right to left
order, until an absolute path is found. If after using all `from` paths still
no absolute path is found, the current working directory is used as well. The
-resulting path is normalized, and trailing slashes are removed unless the path
+resulting path is normalized, and trailing slashes are removed unless the path
gets resolved to the root directory. Non-string arguments are ignored.
Another way to think of it is as a sequence of `cd` commands in a shell.
@@ -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);
+ // 'Path=C:\Windows\system32;C:\Windows;C:\ProgramFiles\nodejs\;'...
+
+ process.env.PATH.split(path.delimiter)
+ // returns
+ ['C:\Windows\system32', 'C:\Windows', 'C:\ProgramFiles\nodejs\']

This comment has been minimized.

Show comment Hide comment
@Mithgol

Mithgol Oct 4, 2012

A whitespace character between Program and Files is necessary for the example to become more correct.

@Mithgol

Mithgol Oct 4, 2012

A whitespace character between Program and Files is necessary for the example to become more correct.

This comment has been minimized.

Show comment Hide comment
@Mithgol

Mithgol Oct 4, 2012

However, I see now that space was added later, in nodejs/node-v0.x-archive@41e53e5.

@Mithgol

Mithgol Oct 4, 2012

However, I see now that space was added later, in nodejs/node-v0.x-archive@41e53e5.

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

0 comments on commit 03d93af

Please sign in to comment.