Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piscisaureus/768988 to your computer and use it in GitHub Desktop.
Save piscisaureus/768988 to your computer and use it in GitHub Desktop.
From bf31046523791e4e9e0c26707db62a32b39e2c79 Mon Sep 17 00:00:00 2001
From: Bert Belder <bertbelder@gmail.com>
Date: Fri, 7 Jan 2011 02:55:25 +0100
Subject: [PATCH] Improve path.resolve documentation
---
doc/api/path.markdown | 31 +++++++++++++++++++++----------
1 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/doc/api/path.markdown b/doc/api/path.markdown
index 5f65554..732fd94 100644
--- a/doc/api/path.markdown
+++ b/doc/api/path.markdown
@@ -29,16 +29,27 @@ Example:
### path.resolve([from ...], to)
-Resolves `to` to an absolute path name and normalizes it.
-
-One ore more `from` arguments may be provided to specify the the starting
-point from where the path will be resolved. `resolve` will prepend `from`
-arguments from right to left until an absolute path is found. If no `from`
-arguments are specified, or after prepending them still no absolute path is
-found, the current working directory will be prepended eventually.
-
-Trailing slashes are removed unless the path gets resolved to the root
-directory.
+Resolves `to` to an absolute path.
+
+One or more `from` arguments may be provided to specify the starting
+point from where the path will be resolved. If `to` isn't already
+absolute `resolve` will prepend `from` arguments in right to left order
+until an absolute path is found. If after using all `from` arguments the
+resulting path is still relative, the current working directory is also
+prepended. The resulting path is normalized, and trailing slashes are removed
+unless the path gets resolved to the root directory.
+
+Another way to think of it is as a sequence of `cd` commands in a shell.
+`path.resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile')` is like:
+
+ cd foo/bar
+ cd /tmp/file/
+ cd ..
+ cd a/../subfile
+ pwd
+
+The difference is that the different paths don't need to exist and may also be
+files.
Examples:
--
1.7.3.1.msysgit.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment