Skip to content

Commit 724b87d

Browse files
TrottFishrock123
authored andcommitted
doc: explain path.format() algorithm
PR-URL: #5688 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Claudio Rodriguez <[email protected]> Reviewed-By: James M Snell <[email protected]> Fixes: #2305
1 parent f34a00c commit 724b87d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

doc/api/path.markdown

+16-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,22 @@ path.extname('.index')
9393

9494
## path.format(pathObject)
9595

96-
Returns a path string from an object, the opposite of [`path.parse`][].
96+
Returns a path string from an object. This is the opposite of [`path.parse`][].
97+
98+
If `pathObject` has all expected properties, the returned string will be a
99+
concatenation of the `dir` property, the platform-dependent path separator, and
100+
the `base` property.
101+
102+
If the `dir` property is not supplied, the `root` property will be used as the
103+
`dir` property. However, it will be assumed that the `root` property already
104+
ends with the platform-dependent path separator. In this case, the returned
105+
string will be the concatenation fo the `root` property and the `base` property.
106+
107+
If both the `dir` and the `root` properties are not supplied, then the returned
108+
string will be the contents of the `base` property.
109+
110+
If the `base` property is not supplied, a concatenation of the `name` property
111+
and the `ext` property will be used as the `base` property.
97112

98113
```js
99114
path.format({

0 commit comments

Comments
 (0)