@@ -16,12 +16,10 @@ Example:
16
16
17
17
``` js
18
18
path .basename (' /foo/bar/baz/asdf/quux.html' )
19
- // returns
20
- ' quux.html'
19
+ // returns 'quux.html'
21
20
22
21
path .basename (' /foo/bar/baz/asdf/quux.html' , ' .html' )
23
- // returns
24
- ' quux'
22
+ // returns 'quux'
25
23
```
26
24
27
25
## path.delimiter
@@ -35,8 +33,7 @@ console.log(process.env.PATH)
35
33
// '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'
36
34
37
35
process .env .PATH .split (path .delimiter )
38
- // returns
39
- [' /usr/bin' , ' /bin' , ' /usr/sbin' , ' /sbin' , ' /usr/local/bin' ]
36
+ // returns ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin']
40
37
```
41
38
42
39
An example on Windows:
@@ -46,8 +43,7 @@ console.log(process.env.PATH)
46
43
// 'C:\Windows\system32;C:\Windows;C:\Program Files\node\'
47
44
48
45
process .env .PATH .split (path .delimiter )
49
- // returns
50
- [' C:\\ Windows\\ system32' , ' C:\\ Windows' , ' C:\\ Program Files\\ node\\ ' ]
46
+ // returns ['C:\\Windows\\system32', 'C:\\Windows', 'C:\\Program Files\\node\\']
51
47
```
52
48
53
49
## path.dirname(p)
@@ -58,8 +54,7 @@ Example:
58
54
59
55
``` js
60
56
path .dirname (' /foo/bar/baz/asdf/quux' )
61
- // returns
62
- ' /foo/bar/baz/asdf'
57
+ // returns '/foo/bar/baz/asdf'
63
58
```
64
59
65
60
## path.extname(p)
@@ -71,24 +66,19 @@ an empty string. Examples:
71
66
72
67
``` js
73
68
path .extname (' index.html' )
74
- // returns
75
- ' .html'
69
+ // returns '.html'
76
70
77
71
path .extname (' index.coffee.md' )
78
- // returns
79
- ' .md'
72
+ // returns '.md'
80
73
81
74
path .extname (' index.' )
82
- // returns
83
- ' .'
75
+ // returns '.'
84
76
85
77
path .extname (' index' )
86
- // returns
87
- ' '
78
+ // returns ''
88
79
89
80
path .extname (' .index' )
90
- // returns
91
- ' '
81
+ // returns ''
92
82
```
93
83
94
84
## path.format(pathObject)
@@ -117,10 +107,19 @@ path.format({
117
107
base : " file.txt" ,
118
108
ext : " .txt" ,
119
109
name : " file"
110
+ });
111
+ // returns '/home/user/dir/file.txt'
112
+
113
+ // `root` will be used if `dir` is not specified and `name` + `ext` will be used
114
+ // if `base` is not specified
115
+ path .format ({
116
+ root : " /" ,
117
+ ext : " .txt" ,
118
+ name : " file"
120
119
})
121
- // returns
122
- ' /home/user/dir/file.txt'
120
+ // returns '/file.txt'
123
121
```
122
+
124
123
## path.isAbsolute(path)
125
124
126
125
Determines whether ` path ` is an absolute path. An absolute path will always
@@ -159,8 +158,7 @@ Example:
159
158
160
159
``` js
161
160
path .join (' /foo' , ' bar' , ' baz/asdf' , ' quux' , ' ..' )
162
- // returns
163
- ' /foo/bar/baz/asdf'
161
+ // returns '/foo/bar/baz/asdf'
164
162
165
163
path .join (' foo' , {}, ' bar' )
166
164
// throws exception
@@ -184,8 +182,7 @@ Example:
184
182
185
183
``` js
186
184
path .normalize (' /foo/bar//baz/asdf/quux/..' )
187
- // returns
188
- ' /foo/bar/baz/asdf'
185
+ // returns '/foo/bar/baz/asdf'
189
186
```
190
187
191
188
* Note:* If the path string passed as argument is a zero-length string then ` '.' `
@@ -200,27 +197,27 @@ An example on \*nix:
200
197
``` js
201
198
path .parse (' /home/user/dir/file.txt' )
202
199
// returns
203
- {
204
- root : " /" ,
205
- dir : " /home/user/dir" ,
206
- base : " file.txt" ,
207
- ext : " .txt" ,
208
- name : " file"
209
- }
200
+ // {
201
+ // root : "/",
202
+ // dir : "/home/user/dir",
203
+ // base : "file.txt",
204
+ // ext : ".txt",
205
+ // name : "file"
206
+ // }
210
207
```
211
208
212
209
An example on Windows:
213
210
214
211
``` js
215
212
path .parse (' C:\\ path\\ dir\\ index.html' )
216
213
// returns
217
- {
218
- root : " C:\\ " ,
219
- dir : " C:\\ path\\ dir" ,
220
- base : " index.html" ,
221
- ext : " .html" ,
222
- name : " index"
223
- }
214
+ // {
215
+ // root : "C:\\",
216
+ // dir : "C:\\path\\dir",
217
+ // base : "index.html",
218
+ // ext : ".html",
219
+ // name : "index"
220
+ // }
224
221
```
225
222
226
223
## path.posix
@@ -244,12 +241,10 @@ Examples:
244
241
245
242
``` js
246
243
path .relative (' C:\\ orandea\\ test\\ aaa' , ' C:\\ orandea\\ impl\\ bbb' )
247
- // returns
248
- ' ..\\ ..\\ impl\\ bbb'
244
+ // returns '..\\..\\impl\\bbb'
249
245
250
246
path .relative (' /data/orandea/test/aaa' , ' /data/orandea/impl/bbb' )
251
- // returns
252
- ' ../../impl/bbb'
247
+ // returns '../../impl/bbb'
253
248
```
254
249
255
250
* Note:* If the arguments to ` relative ` have zero-length strings then the current
@@ -289,16 +284,14 @@ Examples:
289
284
290
285
``` js
291
286
path .resolve (' /foo/bar' , ' ./baz' )
292
- // returns
293
- ' /foo/bar/baz'
287
+ // returns '/foo/bar/baz'
294
288
295
289
path .resolve (' /foo/bar' , ' /tmp/file/' )
296
- // returns
297
- ' /tmp/file'
290
+ // returns '/tmp/file'
298
291
299
292
path .resolve (' wwwroot' , ' static_files/png/' , ' ../gif/image.gif' )
300
293
// if currently in /home/myself/node, it returns
301
- ' /home/myself/node/wwwroot/static_files/gif/image.gif'
294
+ // '/home/myself/node/wwwroot/static_files/gif/image.gif'
302
295
```
303
296
304
297
* Note:* If the arguments to ` resolve ` have zero-length strings then the current
@@ -312,16 +305,14 @@ An example on \*nix:
312
305
313
306
``` js
314
307
' foo/bar/baz' .split (path .sep )
315
- // returns
316
- [' foo' , ' bar' , ' baz' ]
308
+ // returns ['foo', 'bar', 'baz']
317
309
```
318
310
319
311
An example on Windows:
320
312
321
313
``` js
322
314
' foo\\ bar\\ baz' .split (path .sep )
323
- // returns
324
- [' foo' , ' bar' , ' baz' ]
315
+ // returns ['foo', 'bar', 'baz']
325
316
```
326
317
327
318
## path.win32
0 commit comments