Skip to content

Commit aed22d0

Browse files
eversojkMyles Borins
authored and
Myles Borins
committed
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: #5838 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Roman Klauke <[email protected]>
1 parent 9702153 commit aed22d0

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

doc/api/path.markdown

+27-14
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ and the `base` property.
9292
If the `dir` property is not supplied, the `root` property will be used as the
9393
`dir` property. However, it will be assumed that the `root` property already
9494
ends with the platform-dependent path separator. In this case, the returned
95-
string will be the concatenation fo the `root` property and the `base` property.
95+
string will be the concatenation of the `root` property and the `base` property.
9696

9797
If both the `dir` and the `root` properties are not supplied, then the returned
9898
string will be the contents of the `base` property.
@@ -102,28 +102,41 @@ and the `ext` property will be used as the `base` property.
102102

103103
Examples:
104104

105-
An example on Posix systems:
105+
Some Posix system examples:
106106

107107
```js
108+
// If `dir` and `base` are provided, `dir` + platform separator + `base`
109+
// will be returned.
108110
path.format({
109-
root : "/",
110-
dir : "/home/user/dir",
111-
base : "file.txt",
112-
ext : ".txt",
113-
name : "file"
111+
dir: '/home/user/dir',
112+
base: 'file.txt'
114113
});
115114
// returns '/home/user/dir/file.txt'
116115

117-
// `root` will be used if `dir` is not specified and `name` + `ext` will be used
118-
// if `base` is not specified
116+
// `root` will be used if `dir` is not specified.
117+
// `name` + `ext` will be used if `base` is not specified.
118+
// If only `root` is provided or `dir` is equal to `root` then the
119+
// platform separator will not be included.
119120
path.format({
120-
root : "/",
121-
ext : ".txt",
122-
name : "file"
123-
})
121+
root: '/',
122+
base: 'file.txt'
123+
});
124124
// returns '/file.txt'
125-
```
126125

126+
path.format({
127+
dir: '/',
128+
root: '/',
129+
name: 'file',
130+
ext: '.txt'
131+
});
132+
// returns '/file.txt'
133+
134+
// `base` will be returned if `dir` or `root` are not provided.
135+
path.format({
136+
base: 'file.txt'
137+
});
138+
// returns 'file.txt'
139+
```
127140
An example on Windows:
128141

129142
```js

0 commit comments

Comments
 (0)