Documentation for path module
This commit is contained in:
parent
7342fecaec
commit
d6fe7fb4c3
67
doc/api.txt
67
doc/api.txt
@ -1464,6 +1464,73 @@ Expects +block+ to throw an error.
|
|||||||
+assert.doesNotThrow(block, error, message)+::
|
+assert.doesNotThrow(block, error, message)+::
|
||||||
Expects +block+ not to throw an error.
|
Expects +block+ not to throw an error.
|
||||||
|
|
||||||
|
|
||||||
|
=== Path Module
|
||||||
|
|
||||||
|
This module contains utilities for dealing with file paths. Use
|
||||||
|
+require('path')+ to use it. It provides the following methods:
|
||||||
|
|
||||||
|
+path.join(/* path1, path2, ... */)+::
|
||||||
|
Join all arguments together and resolve the resulting path. Example:
|
||||||
|
+
|
||||||
|
------------------------------------
|
||||||
|
node> require("path").join("/foo", "bar", "baz/asdf", "quux", "..")
|
||||||
|
"/foo/bar/baz/asdf"
|
||||||
|
------------------------------------
|
||||||
|
+
|
||||||
|
|
||||||
|
+path.normalizeArray(arr)+::
|
||||||
|
Normalize an array of path parts, taking care of +".."+ and +"."+ parts. Example:
|
||||||
|
+
|
||||||
|
------------------------------------
|
||||||
|
node> require("path").normalizeArray(["", "foo", "bar", "baz", "asdf", "quux", ".."])
|
||||||
|
[
|
||||||
|
"",
|
||||||
|
"foo",
|
||||||
|
"bar",
|
||||||
|
"baz",
|
||||||
|
"asdf"
|
||||||
|
]
|
||||||
|
------------------------------------
|
||||||
|
+
|
||||||
|
|
||||||
|
+path.normalize(p)+::
|
||||||
|
Normalize a string path, taking care of +".."+ and +"."+ parts. Example:
|
||||||
|
+
|
||||||
|
------------------------------------
|
||||||
|
node> require("path").normalize("/foo/bar/baz/asdf/quux/..")
|
||||||
|
"/foo/bar/baz/asdf"
|
||||||
|
------------------------------------
|
||||||
|
+
|
||||||
|
|
||||||
|
+path.dirname(p)+::
|
||||||
|
Return the directory name of a path. Similar to the Unix +dirname+ command. Example:
|
||||||
|
+
|
||||||
|
------------------------------------
|
||||||
|
node> require("path").dirname("/foo/bar/baz/asdf/quux")
|
||||||
|
"/foo/bar/baz/asdf"
|
||||||
|
------------------------------------
|
||||||
|
+
|
||||||
|
|
||||||
|
+path.filename(p)+::
|
||||||
|
Return the last portion of a path. Similar to the Unix +basename+ command. Example:
|
||||||
|
+
|
||||||
|
------------------------------------
|
||||||
|
node> require("path").filename("/foo/bar/baz/asdf/quux")
|
||||||
|
"quux"
|
||||||
|
------------------------------------
|
||||||
|
+
|
||||||
|
|
||||||
|
+path.exists(p, callback)+::
|
||||||
|
Test whether or not the given path exists. Then, call the +callback+ argument with either true or false. Example:
|
||||||
|
+
|
||||||
|
------------------------------------
|
||||||
|
require("path").exists("/etc/passwd", function (exists) {
|
||||||
|
require("sys").debug( exists ? "it's there" : "no passwd!" );
|
||||||
|
});
|
||||||
|
------------------------------------
|
||||||
|
|
||||||
|
|
||||||
== REPL
|
== REPL
|
||||||
|
|
||||||
A Read-Eval-Print-Loop is available both as a standalone program and easily
|
A Read-Eval-Print-Loop is available both as a standalone program and easily
|
||||||
|
Loading…
x
Reference in New Issue
Block a user