Browse Source

doc: modernize and fix code examples in path.md

Unify spaces, quotes, and semicolons. Update output examples.

PR-URL: https://github.com/nodejs/node/pull/12296
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6
Vse Mozhet Byt 8 years ago
parent
commit
a91242569a
  1. 32
      doc/api/path.md

32
doc/api/path.md

@ -236,8 +236,8 @@ On Windows:
```js ```js
path.format({ path.format({
dir : "C:\\path\\dir", dir: 'C:\\path\\dir',
base : "file.txt" base: 'file.txt'
}); });
// Returns: 'C:\\path\\dir\\file.txt' // Returns: 'C:\\path\\dir\\file.txt'
``` ```
@ -299,7 +299,7 @@ path.join('/foo', 'bar', 'baz/asdf', 'quux', '..')
// Returns: '/foo/bar/baz/asdf' // Returns: '/foo/bar/baz/asdf'
path.join('foo', {}, 'bar') path.join('foo', {}, 'bar')
// throws TypeError: Arguments to path.join must be strings // throws 'TypeError: Path must be a string. Received {}'
``` ```
A [`TypeError`][] is thrown if any of the path segments is not a string. A [`TypeError`][] is thrown if any of the path segments is not a string.
@ -332,7 +332,7 @@ path.normalize('/foo/bar//baz/asdf/quux/..')
On Windows: On Windows:
```js ```js
path.normalize('C:\\temp\\\\foo\\bar\\..\\'); path.normalize('C:\\temp\\\\foo\\bar\\..\\')
// Returns: 'C:\\temp\\foo\\' // Returns: 'C:\\temp\\foo\\'
``` ```
@ -362,13 +362,11 @@ For example on POSIX:
```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"
// }
``` ```
```text ```text
@ -386,13 +384,11 @@ On Windows:
```js ```js
path.parse('C:\\path\\dir\\file.txt') path.parse('C:\\path\\dir\\file.txt')
// Returns: // Returns:
// { // { root: 'C:\\',
// root : "C:\\", // dir: 'C:\\path\\dir',
// dir : "C:\\path\\dir", // base: 'file.txt',
// base : "file.txt", // ext: '.txt',
// ext : ".txt", // name: 'file' }
// name : "file"
// }
``` ```
```text ```text

Loading…
Cancel
Save