Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aed22d0

Browse filesBrowse files
eversojkMyles Borins
authored andcommitted
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 <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
1 parent 9702153 commit aed22d0
Copy full SHA for aed22d0

File tree

Expand file treeCollapse file tree

1 file changed

+27
-14
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+27
-14
lines changed
Open diff view settings
Collapse file

‎doc/api/path.markdown‎

Copy file name to clipboardExpand all lines: doc/api/path.markdown
+27-14Lines changed: 27 additions & 14 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.