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 b8ae1b8

Browse filesBrowse files
eversojkMylesBorins
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 9293946 commit b8ae1b8
Copy full SHA for b8ae1b8

File tree

Expand file treeCollapse file tree

1 file changed

+32
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+32
-7
lines changed
Open diff view settings
Collapse file

‎doc/api/path.markdown‎

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