Skip to content

Commit 1cea17f

Browse files
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.
1 parent 997a3be commit 1cea17f

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
@@ -95,7 +95,7 @@ and the `base` property.
9595
If the `dir` property is not supplied, the `root` property will be used as the
9696
`dir` property. However, it will be assumed that the `root` property already
9797
ends with the platform-dependent path separator. In this case, the returned
98-
string will be the concatenation fo the `root` property and the `base` property.
98+
string will be the concatenation of the `root` property and the `base` property.
9999

100100
If both the `dir` and the `root` properties are not supplied, then the returned
101101
string will be the contents of the `base` property.
@@ -105,28 +105,41 @@ and the `ext` property will be used as the `base` property.
105105

106106
Examples:
107107

108-
An example on Posix systems:
108+
Some Posix system examples:
109109

110110
```js
111+
// If `dir` and `base` are provided, `dir` + platform separator + `base`
112+
// will be returned.
111113
path.format({
112-
root : "/",
113-
dir : "/home/user/dir",
114-
base : "file.txt",
115-
ext : ".txt",
116-
name : "file"
114+
dir: '/home/user/dir',
115+
base: 'file.txt'
117116
});
118117
// returns '/home/user/dir/file.txt'
119118

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

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

132145
```js

0 commit comments

Comments
 (0)