-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnode-api-path.txt
381 lines (271 loc) · 10.9 KB
/
node-api-path.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
*node-api-path.txt* For Node.js module `Path` version v3.3.0.
Node.js Documentation
https://nodejs.org
==============================================================================
CONTENTS *node-api-contents*
1. Intro |node-api-path|
2. Methods |node-api-path-methods|
2.1. path.normalize(p) |node-api-path.normalize()|
2.2. path.join([path1][, path2][, ...]) |node-api-path.join()|
2.3. path.resolve([from ...], to) |node-api-path.resolve()|
2.4. path.isAbsolute(path) |node-api-path.isAbsolute()|
2.5. path.relative(from, to) |node-api-path.relative()|
2.6. path.dirname(p) |node-api-path.dirname()|
2.7. path.basename(p[, ext]) |node-api-path.basename()|
2.8. path.extname(p) |node-api-path.extname()|
2.9. path.parse(pathString) |node-api-path.parse()|
2.10. path.format(pathObject) |node-api-path.format()|
3. Properties |node-api-path-properties|
3.1. path.sep |node-api-path.sep|
3.2. path.delimiter |node-api-path.delimiter|
3.3. path.posix |node-api-path.posix|
3.4. path.win32 |node-api-path.win32|
==============================================================================
INTRO *node-api-path*
Stability: 2 - Stable
This module contains utilities for handling and transforming file
paths. Almost all these methods perform only string transformations.
The file system is not consulted to check whether paths are valid.
Use `require('path')` to use this module. The following methods are provided:
==============================================================================
METHODS *node-api-path-methods*
------------------------------------------------------------------------------
path.normalize(p) *node-api-path.normalize()*
Normalize a string path, taking care of `'..'` and `'.'` parts.
When multiple slashes are found, they're replaced by a single one;
when the path contains a trailing slash, it is preserved.
On Windows backslashes are used.
Example:
>
path.normalize('/foo/bar//baz/asdf/quux/..')
// returns
'/foo/bar/baz/asdf'
<
__Note:__ If the path string passed as argument is a zero-length string then `'.'`
will be returned, which represents the current working directory.
------------------------------------------------------------------------------
path.join([path1][, path2][, ...]) *node-api-path.join()*
Join all arguments together and normalize the resulting path.
Arguments must be strings. In v0.8, non-string arguments were
silently ignored. In v0.10 and up, an exception is thrown.
Example:
>
path.join('/foo', 'bar', 'baz/asdf', 'quux', '..')
// returns
'/foo/bar/baz/asdf'
path.join('foo', {}, 'bar')
// throws exception
TypeError: Arguments to path.join must be strings
<
__Note:__ If the arguments to `join` have zero-length strings, unlike other path
module functions, they will be ignored. If the joined path string is a
zero-length string then `'.'` will be returned, which represents the
current working directory.
------------------------------------------------------------------------------
path.resolve([from ...], to) *node-api-path.resolve()*
Resolves `to` to an absolute path.
If `to` isn't already absolute `from` arguments are prepended in right to left
order, until an absolute path is found. If after using all `from` paths still
no absolute path is found, the current working directory is used as well. The
resulting path is normalized, and trailing slashes are removed unless the path
gets resolved to the root directory. Non-string `from` arguments are ignored.
Another way to think of it is as a sequence of `cd` commands in a shell.
>
path.resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile')
<
Is similar to:
>
cd foo/bar
cd /tmp/file/
cd ..
cd a/../subfile
pwd
<
The difference is that the different paths don't need to exist and may also be
files.
Examples:
>
path.resolve('/foo/bar', './baz')
// returns
'/foo/bar/baz'
path.resolve('/foo/bar', '/tmp/file/')
// returns
'/tmp/file'
path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif')
// if currently in /home/myself/iojs, it returns
'/home/myself/iojs/wwwroot/static_files/gif/image.gif'
<
__Note:__ If the arguments to `resolve` have zero-length strings then the current
working directory will be used instead of them.
------------------------------------------------------------------------------
path.isAbsolute(path) *node-api-path.isAbsolute()*
Determines whether `path` is an absolute path. An absolute path will always
resolve to the same location, regardless of the working directory.
Posix examples:
>
path.isAbsolute('/foo/bar') // true
path.isAbsolute('/baz/..') // true
path.isAbsolute('qux/') // false
path.isAbsolute('.') // false
<
Windows examples:
>
path.isAbsolute('//server') // true
path.isAbsolute('C:/foo/..') // true
path.isAbsolute('bar\\baz') // false
path.isAbsolute('.') // false
<
__Note:__ If the path string passed as parameter is a zero-length string, unlike
other path module functions, it will be used as-is and `false` will be
returned.
------------------------------------------------------------------------------
path.relative(from, to) *node-api-path.relative()*
Solve the relative path from `from` to `to`.
At times we have two absolute paths, and we need to derive the relative
path from one to the other. This is actually the reverse transform of
`path.resolve`, which means we see that:
>
path.resolve(from, path.relative(from, to)) == path.resolve(to)
<
Examples:
>
path.relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb')
// returns
'..\\..\\impl\\bbb'
path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb')
// returns
'../../impl/bbb'
<
__Note:__ If the arguments to `relative` have zero-length strings then the current
working directory will be used instead of the zero-length strings. If
both the paths are the same then a zero-length string will be returned.
------------------------------------------------------------------------------
path.dirname(p) *node-api-path.dirname()*
Return the directory name of a path. Similar to the Unix `dirname` command.
Example:
>
path.dirname('/foo/bar/baz/asdf/quux')
// returns
'/foo/bar/baz/asdf'
<
------------------------------------------------------------------------------
path.basename(p[, ext]) *node-api-path.basename()*
Return the last portion of a path. Similar to the Unix `basename` command.
Example:
>
path.basename('/foo/bar/baz/asdf/quux.html')
// returns
'quux.html'
path.basename('/foo/bar/baz/asdf/quux.html', '.html')
// returns
'quux'
<
------------------------------------------------------------------------------
path.extname(p) *node-api-path.extname()*
Return the extension of the path, from the last '.' to end of string
in the last portion of the path. If there is no '.' in the last portion
of the path or the first character of it is '.', then it returns
an empty string. Examples:
>
path.extname('index.html')
// returns
'.html'
path.extname('index.coffee.md')
// returns
'.md'
path.extname('index.')
// returns
'.'
path.extname('index')
// returns
''
path.extname('.index')
// returns
''
<
------------------------------------------------------------------------------
path.parse(pathString) *node-api-path.parse()*
Returns an object from a path string.
An example on *nix:
>
path.parse('/home/user/dir/file.txt')
// returns
{
root : "/",
dir : "/home/user/dir",
base : "file.txt",
ext : ".txt",
name : "file"
}
<
An example on Windows:
>
path.parse('C:\\path\\dir\\index.html')
// returns
{
root : "C:\\",
dir : "C:\\path\\dir",
base : "index.html",
ext : ".html",
name : "index"
}
<
------------------------------------------------------------------------------
path.format(pathObject) *node-api-path.format()*
Returns a path string from an object, the opposite of `path.parse` above.
>
path.format({
root : "/",
dir : "/home/user/dir",
base : "file.txt",
ext : ".txt",
name : "file"
})
// returns
'/home/user/dir/file.txt'
<
==============================================================================
PROPERTIES *node-api-path-properties*
------------------------------------------------------------------------------
path.sep *node-api-path.sep*
The platform-specific file separator. `'\\'` or `'/'`.
An example on *nix:
>
'foo/bar/baz'.split(path.sep)
// returns
['foo', 'bar', 'baz']
<
An example on Windows:
>
'foo\\bar\\baz'.split(path.sep)
// returns
['foo', 'bar', 'baz']
<
------------------------------------------------------------------------------
path.delimiter *node-api-path.delimiter*
The platform-specific path delimiter, `;` or `':'`.
An example on *nix:
>
console.log(process.env.PATH)
// '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'
process.env.PATH.split(path.delimiter)
// returns
['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin']
<
An example on Windows:
>
console.log(process.env.PATH)
// 'C:\Windows\system32;C:\Windows;C:\Program Files\iojs\'
process.env.PATH.split(path.delimiter)
// returns
['C:\\Windows\\system32', 'C:\\Windows', 'C:\\Program Files\\iojs\\']
<
------------------------------------------------------------------------------
path.posix *node-api-path.posix*
Provide access to aforementioned `path` methods but always interact in a posix
compatible way.
------------------------------------------------------------------------------
path.win32 *node-api-path.win32*
Provide access to aforementioned `path` methods but always interact in a win32
compatible way.
vim:tw=78:ts=8:ft=help