Skip to content

Commit d66d883

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 9856b80 commit d66d883

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

doc/api/path.markdown

+32-7
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,50 @@ 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.
9999

100100
If the `base` property is not supplied, a concatenation of the `name` property
101101
and the `ext` property will be used as the `base` property.
102102

103-
An example on Posix systems:
103+
Examples:
104+
105+
Some Posix system examples:
104106

105107
```js
108+
// If `dir` and `base` are provided, `dir` + platform separator + `base`
109+
// will be returned.
106110
path.format({
107-
root : "/",
108-
dir : "/home/user/dir",
109-
base : "file.txt",
110-
ext : ".txt",
111-
name : "file"
111+
dir: '/home/user/dir',
112+
base: 'file.txt'
112113
});
113114
// returns '/home/user/dir/file.txt'
115+
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.
120+
path.format({
121+
root: '/',
122+
base: 'file.txt'
123+
});
124+
// returns '/file.txt'
125+
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'
114139
```
115140

116141
An example on Windows:

0 commit comments

Comments
 (0)