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: path.format provide more examples #5838

Closed
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
41 changes: 27 additions & 14 deletions doc/api/path.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down