@@ -182,37 +182,32 @@ added: v0.11.15
182182The ` path.format() ` method returns a path string from an object. This is the
183183opposite of [ ` path.parse() ` ] [ ] .
184184
185- The following process is used when constructing the path string:
186-
187- * ` output ` is set to an empty string.
188- * If ` pathObject.dir ` is specified, ` pathObject.dir ` is appended to ` output `
189- followed by the value of ` path.sep ` ;
190- * Otherwise, if ` pathObject.root ` is specified, ` pathObject.root ` is appended
191- to ` output ` .
192- * If ` pathObject.base ` is specified, ` pathObject.base ` is appended to ` output ` ;
193- * Otherwise:
194- * If ` pathObject.name ` is specified, ` pathObject.name ` is appended to ` output `
195- * If ` pathObject.ext ` is specified, ` pathObject.ext ` is appended to ` output ` .
196- * Return ` output `
185+ When providing properties to the ` pathObject ` remember that there are
186+ combinations where one property has priority over another:
187+
188+ * ` pathObject.root ` is ignored if ` pathObject.dir ` is provided
189+ * ` pathObject.ext ` and ` pathObject.name ` are ignored if ` pathObject.base ` exists
197190
198191For example, on POSIX:
199192
200193``` js
201- // If `dir` and `base` are provided,
194+ // If `dir`, `root` and `base` are provided,
202195// `${dir}${path.sep}${base}`
203- // will be returned.
196+ // will be returned. `root` is ignored.
204197path .format ({
198+ root: ' /ignored' ,
205199 dir: ' /home/user/dir' ,
206200 base: ' file.txt'
207201});
208202// Returns: '/home/user/dir/file.txt'
209203
210204// `root` will be used if `dir` is not specified.
211205// If only `root` is provided or `dir` is equal to `root` then the
212- // platform separator will not be included.
206+ // platform separator will not be included. `ext` will be ignored.
213207path .format ({
214208 root: ' /' ,
215- base: ' file.txt'
209+ base: ' file.txt' ,
210+ ext: ' ignored'
216211});
217212// Returns: '/file.txt'
218213
@@ -223,23 +218,14 @@ path.format({
223218 ext: ' .txt'
224219});
225220// Returns: '/file.txt'
226-
227- // `base` will be returned if `dir` or `root` are not provided.
228- path .format ({
229- base: ' file.txt'
230- });
231- // Returns: 'file.txt'
232221```
233222
234223On Windows:
235224
236225``` js
237226path .format ({
238- root : " C:\\ " ,
239- dir : " C:\\ path\\ dir" ,
240- base : " file.txt" ,
241- ext : " .txt" ,
242- name : " file"
227+ dir : " C:\\ path\\ dir" ,
228+ base : " file.txt"
243229});
244230// Returns: 'C:\\path\\dir\\file.txt'
245231```
0 commit comments