@@ -95,7 +95,7 @@ and the `base` property.
95
95
If the ` dir ` property is not supplied, the ` root ` property will be used as the
96
96
` dir ` property. However, it will be assumed that the ` root ` property already
97
97
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.
99
99
100
100
If both the ` dir ` and the ` root ` properties are not supplied, then the returned
101
101
string will be the contents of the ` base ` property.
@@ -105,28 +105,41 @@ and the `ext` property will be used as the `base` property.
105
105
106
106
Examples:
107
107
108
- An example on Posix systems :
108
+ Some Posix system examples :
109
109
110
110
``` js
111
+ // If `dir` and `base` are provided, `dir` + platform separator + `base`
112
+ // will be returned.
111
113
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'
117
116
});
118
117
// returns '/home/user/dir/file.txt'
119
118
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.
122
123
path .format ({
123
- root : " /" ,
124
- ext : " .txt" ,
125
- name : " file"
126
- })
124
+ root: ' /' ,
125
+ base: ' file.txt'
126
+ });
127
127
// returns '/file.txt'
128
- ```
129
128
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
+ ```
130
143
An example on Windows:
131
144
132
145
``` js
0 commit comments