Skip to content

Commit d6fe7fb

Browse files
isaacsry
authored andcommitted
Documentation for path module
1 parent 7342fec commit d6fe7fb

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

doc/api.txt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,73 @@ Expects +block+ to throw an error.
14641464
+assert.doesNotThrow(block, error, message)+::
14651465
Expects +block+ not to throw an error.
14661466

1467+
1468+
=== Path Module
1469+
1470+
This module contains utilities for dealing with file paths. Use
1471+
+require('path')+ to use it. It provides the following methods:
1472+
1473+
+path.join(/* path1, path2, ... */)+::
1474+
Join all arguments together and resolve the resulting path. Example:
1475+
+
1476+
------------------------------------
1477+
node> require("path").join("/foo", "bar", "baz/asdf", "quux", "..")
1478+
"/foo/bar/baz/asdf"
1479+
------------------------------------
1480+
+
1481+
1482+
+path.normalizeArray(arr)+::
1483+
Normalize an array of path parts, taking care of +".."+ and +"."+ parts. Example:
1484+
+
1485+
------------------------------------
1486+
node> require("path").normalizeArray(["", "foo", "bar", "baz", "asdf", "quux", ".."])
1487+
[
1488+
"",
1489+
"foo",
1490+
"bar",
1491+
"baz",
1492+
"asdf"
1493+
]
1494+
------------------------------------
1495+
+
1496+
1497+
+path.normalize(p)+::
1498+
Normalize a string path, taking care of +".."+ and +"."+ parts. Example:
1499+
+
1500+
------------------------------------
1501+
node> require("path").normalize("/foo/bar/baz/asdf/quux/..")
1502+
"/foo/bar/baz/asdf"
1503+
------------------------------------
1504+
+
1505+
1506+
+path.dirname(p)+::
1507+
Return the directory name of a path. Similar to the Unix +dirname+ command. Example:
1508+
+
1509+
------------------------------------
1510+
node> require("path").dirname("/foo/bar/baz/asdf/quux")
1511+
"/foo/bar/baz/asdf"
1512+
------------------------------------
1513+
+
1514+
1515+
+path.filename(p)+::
1516+
Return the last portion of a path. Similar to the Unix +basename+ command. Example:
1517+
+
1518+
------------------------------------
1519+
node> require("path").filename("/foo/bar/baz/asdf/quux")
1520+
"quux"
1521+
------------------------------------
1522+
+
1523+
1524+
+path.exists(p, callback)+::
1525+
Test whether or not the given path exists. Then, call the +callback+ argument with either true or false. Example:
1526+
+
1527+
------------------------------------
1528+
require("path").exists("/etc/passwd", function (exists) {
1529+
require("sys").debug( exists ? "it's there" : "no passwd!" );
1530+
});
1531+
------------------------------------
1532+
1533+
14671534
== REPL
14681535

14691536
A Read-Eval-Print-Loop is available both as a standalone program and easily

0 commit comments

Comments
 (0)