@@ -38,45 +38,56 @@ function normalizeStringPosix(path, allowAboveRoot) {
38
38
var dots = 0 ;
39
39
var code ;
40
40
for ( var i = 0 ; i <= path . length ; ++ i ) {
41
- if ( i < path . length ) code = path . charCodeAt ( i ) ; else if ( code === 47 /*/*/ ) break ; else code = 47 /*/*/ ;
41
+ if ( i < path . length )
42
+ code = path . charCodeAt ( i ) ;
43
+ else if ( code === 47 /*/*/ )
44
+ break ;
45
+ else
46
+ code = 47 /*/*/ ;
42
47
if ( code === 47 /*/*/ ) {
43
- if ( lastSlash === i - 1 || dots === 1 ) {
44
- // NOOP
45
- } else if ( lastSlash !== i - 1 && dots === 2 ) {
46
- if ( res . length < 2 || lastSegmentLength !== 2 || res . charCodeAt ( res . length - 1 ) !== 46 /*.*/ || res . charCodeAt ( res . length - 2 ) !== 46 /*.*/ ) {
47
- if ( res . length > 2 ) {
48
- var lastSlashIndex = res . lastIndexOf ( '/' ) ;
49
- if ( lastSlashIndex !== res . length - 1 ) {
50
- if ( lastSlashIndex === - 1 ) {
51
- res = '' ;
52
- lastSegmentLength = 0 ;
53
- } else {
54
- res = res . slice ( 0 , lastSlashIndex ) ;
55
- lastSegmentLength = res . length - 1 - res . lastIndexOf ( '/' ) ;
56
- }
57
- lastSlash = i ;
58
- dots = 0 ;
59
- continue ;
60
- }
61
- } else if ( res . length === 2 || res . length === 1 ) {
48
+ if ( lastSlash === i - 1 || dots === 1 ) {
49
+ // NOOP
50
+ } else if ( lastSlash !== i - 1 && dots === 2 ) {
51
+ if ( res . length < 2 || lastSegmentLength !== 2 || res . charCodeAt ( res . length - 1 ) !== 46 /*.*/ || res . charCodeAt ( res . length - 2 ) !== 46 /*.*/ ) {
52
+ if ( res . length > 2 ) {
53
+ var lastSlashIndex = res . lastIndexOf ( '/' ) ;
54
+ if ( lastSlashIndex !== res . length - 1 ) {
55
+ if ( lastSlashIndex === - 1 ) {
62
56
res = '' ;
63
57
lastSegmentLength = 0 ;
64
- lastSlash = i ;
65
- dots = 0 ;
66
- continue ;
58
+ } else {
59
+ res = res . slice ( 0 , lastSlashIndex ) ;
60
+ lastSegmentLength = res . length - 1 - res . lastIndexOf ( '/' ) ;
67
61
}
62
+ lastSlash = i ;
63
+ dots = 0 ;
64
+ continue ;
68
65
}
69
- if ( allowAboveRoot ) {
70
- if ( res . length > 0 ) res += '/..' ; else res = '..' ;
71
- lastSegmentLength = 2 ;
66
+ } else if ( res . length === 2 || res . length === 1 ) {
67
+ res = '' ;
68
+ lastSegmentLength = 0 ;
69
+ lastSlash = i ;
70
+ dots = 0 ;
71
+ continue ;
72
72
}
73
- } else {
74
- if ( res . length > 0 ) res += '/' + path . slice ( lastSlash + 1 , i ) ; else res = path . slice ( lastSlash + 1 , i ) ;
75
- lastSegmentLength = i - lastSlash - 1 ;
76
73
}
77
- lastSlash = i ;
78
- dots = 0 ;
79
- } else if ( code === 46 /*.*/ && dots !== - 1 ) {
74
+ if ( allowAboveRoot ) {
75
+ if ( res . length > 0 )
76
+ res += '/..' ;
77
+ else
78
+ res = '..' ;
79
+ lastSegmentLength = 2 ;
80
+ }
81
+ } else {
82
+ if ( res . length > 0 )
83
+ res += '/' + path . slice ( lastSlash + 1 , i ) ;
84
+ else
85
+ res = path . slice ( lastSlash + 1 , i ) ;
86
+ lastSegmentLength = i - lastSlash - 1 ;
87
+ }
88
+ lastSlash = i ;
89
+ dots = 0 ;
90
+ } else if ( code === 46 /*.*/ && dots !== - 1 ) {
80
91
++ dots ;
81
92
} else {
82
93
dots = - 1 ;
@@ -106,8 +117,11 @@ var posix = {
106
117
107
118
for ( var i = arguments . length - 1 ; i >= - 1 && ! resolvedAbsolute ; i -- ) {
108
119
var path ;
109
- if ( i >= 0 ) path = arguments [ i ] ; else {
110
- if ( cwd === undefined ) cwd = process . cwd ( ) ;
120
+ if ( i >= 0 )
121
+ path = arguments [ i ] ;
122
+ else {
123
+ if ( cwd === undefined )
124
+ cwd = process . cwd ( ) ;
111
125
path = cwd ;
112
126
}
113
127
@@ -129,7 +143,10 @@ var posix = {
129
143
resolvedPath = normalizeStringPosix ( resolvedPath , ! resolvedAbsolute ) ;
130
144
131
145
if ( resolvedAbsolute ) {
132
- if ( resolvedPath . length > 0 ) return '/' + resolvedPath ; else return '/' ;
146
+ if ( resolvedPath . length > 0 )
147
+ return '/' + resolvedPath ;
148
+ else
149
+ return '/' ;
133
150
} else if ( resolvedPath . length > 0 ) {
134
151
return resolvedPath ;
135
152
} else {
@@ -161,16 +178,21 @@ var posix = {
161
178
} ,
162
179
163
180
join : function join ( ) {
164
- if ( arguments . length === 0 ) return '.' ;
181
+ if ( arguments . length === 0 )
182
+ return '.' ;
165
183
var joined ;
166
184
for ( var i = 0 ; i < arguments . length ; ++ i ) {
167
185
var arg = arguments [ i ] ;
168
186
assertPath ( arg ) ;
169
187
if ( arg . length > 0 ) {
170
- if ( joined === undefined ) joined = arg ; else joined += '/' + arg ;
188
+ if ( joined === undefined )
189
+ joined = arg ;
190
+ else
191
+ joined += '/' + arg ;
171
192
}
172
193
}
173
- if ( joined === undefined ) return '.' ;
194
+ if ( joined === undefined )
195
+ return '.' ;
174
196
return posix . normalize ( joined ) ;
175
197
} ,
176
198
@@ -188,15 +210,17 @@ var posix = {
188
210
// Trim any leading backslashes
189
211
var fromStart = 1 ;
190
212
for ( ; fromStart < from . length ; ++ fromStart ) {
191
- if ( from . charCodeAt ( fromStart ) !== 47 /*/*/ ) break ;
213
+ if ( from . charCodeAt ( fromStart ) !== 47 /*/*/ )
214
+ break ;
192
215
}
193
216
var fromEnd = from . length ;
194
217
var fromLen = fromEnd - fromStart ;
195
218
196
219
// Trim any leading backslashes
197
220
var toStart = 1 ;
198
221
for ( ; toStart < to . length ; ++ toStart ) {
199
- if ( to . charCodeAt ( toStart ) !== 47 /*/*/ ) break ;
222
+ if ( to . charCodeAt ( toStart ) !== 47 /*/*/ )
223
+ break ;
200
224
}
201
225
var toEnd = to . length ;
202
226
var toLen = toEnd - toStart ;
@@ -209,20 +233,20 @@ var posix = {
209
233
if ( i === length ) {
210
234
if ( toLen > length ) {
211
235
if ( to . charCodeAt ( toStart + i ) === 47 /*/*/ ) {
212
- // We get here if `from` is the exact base path for `to`.
213
- // For example: from='/foo/bar'; to='/foo/bar/baz'
214
- return to . slice ( toStart + i + 1 ) ;
215
- } else if ( i === 0 ) {
236
+ // We get here if `from` is the exact base path for `to`.
237
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
238
+ return to . slice ( toStart + i + 1 ) ;
239
+ } else if ( i === 0 ) {
216
240
// We get here if `from` is the root
217
241
// For example: from='/'; to='/foo'
218
242
return to . slice ( toStart + i ) ;
219
243
}
220
244
} else if ( fromLen > length ) {
221
245
if ( from . charCodeAt ( fromStart + i ) === 47 /*/*/ ) {
222
- // We get here if `to` is the exact base path for `from`.
223
- // For example: from='/foo/bar/baz'; to='/foo/bar'
224
- lastCommonSep = i ;
225
- } else if ( i === 0 ) {
246
+ // We get here if `to` is the exact base path for `from`.
247
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
248
+ lastCommonSep = i ;
249
+ } else if ( i === 0 ) {
226
250
// We get here if `to` is the root.
227
251
// For example: from='/foo'; to='/'
228
252
lastCommonSep = 0 ;
@@ -232,23 +256,32 @@ var posix = {
232
256
}
233
257
var fromCode = from . charCodeAt ( fromStart + i ) ;
234
258
var toCode = to . charCodeAt ( toStart + i ) ;
235
- if ( fromCode !== toCode ) break ; else if ( fromCode === 47 /*/*/ ) lastCommonSep = i ;
259
+ if ( fromCode !== toCode )
260
+ break ;
261
+ else if ( fromCode === 47 /*/*/ )
262
+ lastCommonSep = i ;
236
263
}
237
264
238
265
var out = '' ;
239
266
// Generate the relative path based on the path difference between `to`
240
267
// and `from`
241
268
for ( i = fromStart + lastCommonSep + 1 ; i <= fromEnd ; ++ i ) {
242
269
if ( i === fromEnd || from . charCodeAt ( i ) === 47 /*/*/ ) {
243
- if ( out . length === 0 ) out += '..' ; else out += '/..' ;
244
- }
270
+ if ( out . length === 0 )
271
+ out += '..' ;
272
+ else
273
+ out += '/..' ;
274
+ }
245
275
}
246
276
247
277
// Lastly, append the rest of the destination (`to`) path that comes after
248
278
// the common path parts
249
- if ( out . length > 0 ) return out + to . slice ( toStart + lastCommonSep ) ; else {
279
+ if ( out . length > 0 )
280
+ return out + to . slice ( toStart + lastCommonSep ) ;
281
+ else {
250
282
toStart += lastCommonSep ;
251
- if ( to . charCodeAt ( toStart ) === 47 /*/*/ ) ++ toStart ;
283
+ if ( to . charCodeAt ( toStart ) === 47 /*/*/ )
284
+ ++ toStart ;
252
285
return to . slice ( toStart ) ;
253
286
}
254
287
} ,
@@ -381,27 +414,30 @@ var posix = {
381
414
}
382
415
if ( code === 46 /*.*/ ) {
383
416
// If this is our first dot, mark it as the start of our extension
384
- if ( startDot === - 1 ) startDot = i ; else if ( preDotState !== 1 ) preDotState = 1 ;
385
- } else if ( startDot !== - 1 ) {
417
+ if ( startDot === - 1 )
418
+ startDot = i ;
419
+ else if ( preDotState !== 1 )
420
+ preDotState = 1 ;
421
+ } else if ( startDot !== - 1 ) {
386
422
// We saw a non-dot and non-path separator before our dot, so we should
387
423
// have a good chance at having a non-empty extension
388
424
preDotState = - 1 ;
389
425
}
390
426
}
391
427
392
428
if ( startDot === - 1 || end === - 1 ||
393
- // We saw a non-dot character immediately before the dot
394
- preDotState === 0 ||
395
- // The (right-most) trimmed path component is exactly '..'
396
- preDotState === 1 && startDot === end - 1 && startDot === startPart + 1 ) {
429
+ // We saw a non-dot character immediately before the dot
430
+ preDotState === 0 ||
431
+ // The (right-most) trimmed path component is exactly '..'
432
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1 ) {
397
433
return '' ;
398
434
}
399
435
return path . slice ( startDot , end ) ;
400
436
} ,
401
437
402
438
format : function format ( pathObject ) {
403
- if ( pathObject === null || typeof pathObject === 'undefined ') {
404
- throw new TypeError ( 'Parameter "pathObject" must be an object, not ' + ( typeof pathObject ) ) ;
439
+ if ( pathObject === null || typeof pathObject !== 'object ') {
440
+ throw new TypeError ( 'The "pathObject" argument must be of type Object. Received type ' + typeof pathObject ) ;
405
441
}
406
442
return _format ( '/' , pathObject ) ;
407
443
} ,
0 commit comments