Improve path.resolve documentation

v0.7.4-release
Bert Belder 2011-01-11 02:57:25 +01:00 committed by Ryan Dahl
parent 320a56b89d
commit 01148265cb
1 changed files with 23 additions and 15 deletions

View File

@ -29,34 +29,42 @@ Example:
### path.resolve([from ...], to)
Resolves `to` to an absolute path name and normalizes it.
Resolves `to` to an absolute path.
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.
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
gets resolved to the root directory.
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 similar to:
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:
path.resolve('index.html')
// returns
'/home/tank/index.html'
path.resolve('/foo/bar', './baz')
// returns
'/foo/baz/baz'
'/foo/bar/baz'
path.resolve('/foo/bar', '/tmp/file/')
// returns
'/tmp/file'
path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif')
// returns
'/home/tank/wwwroot/static_files/gif/image.gif'
// if currently in /home/myself/node, it returns
'/home/myself/node/wwwroot/static_files/gif/image.gif'
### path.dirname(p)