Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: modernize and fix code examples in path.md #12296

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions doc/api/path.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ On Windows:

```js
path.format({
dir : "C:\\path\\dir",
base : "file.txt"
dir: 'C:\\path\\dir',
base: 'file.txt'
});
// Returns: 'C:\\path\\dir\\file.txt'
```
Expand Down Expand Up @@ -299,7 +299,7 @@ path.join('/foo', 'bar', 'baz/asdf', 'quux', '..')
// Returns: '/foo/bar/baz/asdf'

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.
Expand Down Expand Up @@ -332,7 +332,7 @@ path.normalize('/foo/bar//baz/asdf/quux/..')
On Windows:

```js
path.normalize('C:\\temp\\\\foo\\bar\\..\\');
path.normalize('C:\\temp\\\\foo\\bar\\..\\')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you delete the semicolon?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are sections where all semicolons are present, there are ones where all are omitted. In the most cases when examples are intended to run in REPL all the semicolon are omitted. In this section one is present and one is omitted. I've just tried to make it consistent and similar to others.

// Returns: 'C:\\temp\\foo\\'
```

Expand Down Expand Up @@ -362,13 +362,11 @@ For example on POSIX:
```js
path.parse('/home/user/dir/file.txt')
// Returns:
// {
// root : "/",
// dir : "/home/user/dir",
// base : "file.txt",
// ext : ".txt",
// name : "file"
// }
// { root: '/',
// dir: '/home/user/dir',
// base: 'file.txt',
// ext: '.txt',
// name: 'file' }
```

```text
Expand All @@ -386,13 +384,11 @@ On Windows:
```js
path.parse('C:\\path\\dir\\file.txt')
// Returns:
// {
// root : "C:\\",
// dir : "C:\\path\\dir",
// base : "file.txt",
// ext : ".txt",
// name : "file"
// }
// { root: 'C:\\',
// dir: 'C:\\path\\dir',
// base: 'file.txt',
// ext: '.txt',
// name: 'file' }
```

```text
Expand Down