diff options
author | John Eversole <eversojk@gmail.com> | 2016-03-21 18:20:16 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-04-08 17:39:35 -0700 |
commit | 820844d6732a471ff0bff5ff477dec70133bdd3d (patch) | |
tree | c9cac4360de813be44c8b5717560b6d43a070a62 /doc | |
parent | eaab17c6a79462da5f3ac037722719ad1606e8cf (diff) | |
download | android-node-v8-820844d6732a471ff0bff5ff477dec70133bdd3d.tar.gz android-node-v8-820844d6732a471ff0bff5ff477dec70133bdd3d.tar.bz2 android-node-v8-820844d6732a471ff0bff5ff477dec70133bdd3d.zip |
doc: path.format provide more examples
This change was to add upon the algorithm description of path.format
by adding examples for unix systems that clarified behavior in
various scenarios.
PR-URL: https://github.com/nodejs/node/pull/5838
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api/path.markdown | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/doc/api/path.markdown b/doc/api/path.markdown index 3711dd42a1..9188e042d8 100644 --- a/doc/api/path.markdown +++ b/doc/api/path.markdown @@ -95,7 +95,7 @@ and the `base` property. If the `dir` property is not supplied, the `root` property will be used as the `dir` property. However, it will be assumed that the `root` property already ends with the platform-dependent path separator. In this case, the returned -string will be the concatenation fo the `root` property and the `base` property. +string will be the concatenation of the `root` property and the `base` property. If both the `dir` and the `root` properties are not supplied, then the returned string will be the contents of the `base` property. @@ -105,28 +105,41 @@ and the `ext` property will be used as the `base` property. Examples: -An example on Posix systems: +Some Posix system examples: ```js +// If `dir` and `base` are provided, `dir` + platform separator + `base` +// will be returned. path.format({ - root : "/", - dir : "/home/user/dir", - base : "file.txt", - ext : ".txt", - name : "file" + dir: '/home/user/dir', + base: 'file.txt' }); // returns '/home/user/dir/file.txt' -// `root` will be used if `dir` is not specified and `name` + `ext` will be used -// if `base` is not specified +// `root` will be used if `dir` is not specified. +// `name` + `ext` will be used if `base` is not specified. +// If only `root` is provided or `dir` is equal to `root` then the +// platform separator will not be included. path.format({ - root : "/", - ext : ".txt", - name : "file" -}) + root: '/', + base: 'file.txt' +}); // returns '/file.txt' -``` +path.format({ + dir: '/', + root: '/', + name: 'file', + ext: '.txt' +}); +// returns '/file.txt' + +// `base` will be returned if `dir` or `root` are not provided. +path.format({ + base: 'file.txt' +}); +// returns 'file.txt' +``` An example on Windows: ```js |