Browse Source

doc: fix invalid path doc comments

The format of certain code comments in the `path` documentation results
in the code blocks being invalid. I also find it confusing at least as
formatted on the website. This change is intended to improve those
comments.

PR-URL: https://github.com/nodejs/node/pull/5797
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v4.x
Rich Trott 9 years ago
committed by Myles Borins
parent
commit
0943001563
  1. 97
      doc/api/path.markdown

97
doc/api/path.markdown

@ -16,12 +16,10 @@ Example:
```js ```js
path.basename('/foo/bar/baz/asdf/quux.html') path.basename('/foo/bar/baz/asdf/quux.html')
// returns // returns 'quux.html'
'quux.html'
path.basename('/foo/bar/baz/asdf/quux.html', '.html') path.basename('/foo/bar/baz/asdf/quux.html', '.html')
// returns // returns 'quux'
'quux'
``` ```
## path.delimiter ## path.delimiter
@ -35,8 +33,7 @@ console.log(process.env.PATH)
// '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin' // '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'
process.env.PATH.split(path.delimiter) process.env.PATH.split(path.delimiter)
// returns // returns ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin']
['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin']
``` ```
An example on Windows: An example on Windows:
@ -46,8 +43,7 @@ console.log(process.env.PATH)
// 'C:\Windows\system32;C:\Windows;C:\Program Files\node\' // 'C:\Windows\system32;C:\Windows;C:\Program Files\node\'
process.env.PATH.split(path.delimiter) process.env.PATH.split(path.delimiter)
// returns // returns ['C:\\Windows\\system32', 'C:\\Windows', 'C:\\Program Files\\node\\']
['C:\\Windows\\system32', 'C:\\Windows', 'C:\\Program Files\\node\\']
``` ```
## path.dirname(p) ## path.dirname(p)
@ -58,8 +54,7 @@ Example:
```js ```js
path.dirname('/foo/bar/baz/asdf/quux') path.dirname('/foo/bar/baz/asdf/quux')
// returns // returns '/foo/bar/baz/asdf'
'/foo/bar/baz/asdf'
``` ```
## path.extname(p) ## path.extname(p)
@ -71,24 +66,19 @@ an empty string. Examples:
```js ```js
path.extname('index.html') path.extname('index.html')
// returns // returns '.html'
'.html'
path.extname('index.coffee.md') path.extname('index.coffee.md')
// returns // returns '.md'
'.md'
path.extname('index.') path.extname('index.')
// returns // returns '.'
'.'
path.extname('index') path.extname('index')
// returns // returns ''
''
path.extname('.index') path.extname('.index')
// returns // returns ''
''
``` ```
## path.format(pathObject) ## path.format(pathObject)
@ -117,10 +107,19 @@ path.format({
base : "file.txt", base : "file.txt",
ext : ".txt", ext : ".txt",
name : "file" name : "file"
});
// 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
path.format({
root : "/",
ext : ".txt",
name : "file"
}) })
// returns // returns '/file.txt'
'/home/user/dir/file.txt'
``` ```
## path.isAbsolute(path) ## path.isAbsolute(path)
Determines whether `path` is an absolute path. An absolute path will always Determines whether `path` is an absolute path. An absolute path will always
@ -159,8 +158,7 @@ Example:
```js ```js
path.join('/foo', 'bar', 'baz/asdf', 'quux', '..') path.join('/foo', 'bar', 'baz/asdf', 'quux', '..')
// returns // returns '/foo/bar/baz/asdf'
'/foo/bar/baz/asdf'
path.join('foo', {}, 'bar') path.join('foo', {}, 'bar')
// throws exception // throws exception
@ -184,8 +182,7 @@ Example:
```js ```js
path.normalize('/foo/bar//baz/asdf/quux/..') path.normalize('/foo/bar//baz/asdf/quux/..')
// returns // returns '/foo/bar/baz/asdf'
'/foo/bar/baz/asdf'
``` ```
*Note:* If the path string passed as argument is a zero-length string then `'.'` *Note:* If the path string passed as argument is a zero-length string then `'.'`
@ -200,13 +197,13 @@ An example on \*nix:
```js ```js
path.parse('/home/user/dir/file.txt') path.parse('/home/user/dir/file.txt')
// returns // returns
{ // {
root : "/", // root : "/",
dir : "/home/user/dir", // dir : "/home/user/dir",
base : "file.txt", // base : "file.txt",
ext : ".txt", // ext : ".txt",
name : "file" // name : "file"
} // }
``` ```
An example on Windows: An example on Windows:
@ -214,13 +211,13 @@ An example on Windows:
```js ```js
path.parse('C:\\path\\dir\\index.html') path.parse('C:\\path\\dir\\index.html')
// returns // returns
{ // {
root : "C:\\", // root : "C:\\",
dir : "C:\\path\\dir", // dir : "C:\\path\\dir",
base : "index.html", // base : "index.html",
ext : ".html", // ext : ".html",
name : "index" // name : "index"
} // }
``` ```
## path.posix ## path.posix
@ -244,12 +241,10 @@ Examples:
```js ```js
path.relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb') path.relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb')
// returns // returns '..\\..\\impl\\bbb'
'..\\..\\impl\\bbb'
path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb') path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb')
// returns // returns '../../impl/bbb'
'../../impl/bbb'
``` ```
*Note:* If the arguments to `relative` have zero-length strings then the current *Note:* If the arguments to `relative` have zero-length strings then the current
@ -289,16 +284,14 @@ Examples:
```js ```js
path.resolve('/foo/bar', './baz') path.resolve('/foo/bar', './baz')
// returns // returns '/foo/bar/baz'
'/foo/bar/baz'
path.resolve('/foo/bar', '/tmp/file/') path.resolve('/foo/bar', '/tmp/file/')
// returns // returns '/tmp/file'
'/tmp/file'
path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif') path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif')
// if currently in /home/myself/node, it returns // if currently in /home/myself/node, it returns
'/home/myself/node/wwwroot/static_files/gif/image.gif' // '/home/myself/node/wwwroot/static_files/gif/image.gif'
``` ```
*Note:* If the arguments to `resolve` have zero-length strings then the current *Note:* If the arguments to `resolve` have zero-length strings then the current
@ -312,16 +305,14 @@ An example on \*nix:
```js ```js
'foo/bar/baz'.split(path.sep) 'foo/bar/baz'.split(path.sep)
// returns // returns ['foo', 'bar', 'baz']
['foo', 'bar', 'baz']
``` ```
An example on Windows: An example on Windows:
```js ```js
'foo\\bar\\baz'.split(path.sep) 'foo\\bar\\baz'.split(path.sep)
// returns // returns ['foo', 'bar', 'baz']
['foo', 'bar', 'baz']
``` ```
## path.win32 ## path.win32

Loading…
Cancel
Save