@@ -91,17 +91,11 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
91
91
}
92
92
}
93
93
if ( allowAboveRoot ) {
94
- if ( res . length > 0 )
95
- res += `${ separator } ..` ;
96
- else
97
- res = '..' ;
94
+ res += res . length > 0 ? `${ separator } ..` : '..' ;
98
95
lastSegmentLength = 2 ;
99
96
}
100
97
} else {
101
- if ( res . length > 0 )
102
- res += separator + path . slice ( lastSlash + 1 , i ) ;
103
- else
104
- res = path . slice ( lastSlash + 1 , i ) ;
98
+ res += ( res . length > 0 ? separator : '' ) + path . slice ( lastSlash + 1 , i ) ;
105
99
lastSegmentLength = i - lastSlash - 1 ;
106
100
}
107
101
lastSlash = i ;
@@ -118,14 +112,11 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
118
112
function _format ( sep , pathObject ) {
119
113
const dir = pathObject . dir || pathObject . root ;
120
114
const base = pathObject . base ||
121
- ( ( pathObject . name || '' ) + ( pathObject . ext || '' ) ) ;
115
+ ` ${ pathObject . name || '' } ${ pathObject . ext || '' } ` ;
122
116
if ( ! dir ) {
123
117
return base ;
124
118
}
125
- if ( dir === pathObject . root ) {
126
- return dir + base ;
127
- }
128
- return dir + sep + base ;
119
+ return dir === pathObject . root ? `${ dir } ${ base } ` : `${ dir } ${ sep } ${ base } ` ;
129
120
}
130
121
131
122
const win32 = {
@@ -147,7 +138,7 @@ const win32 = {
147
138
// absolute path, get cwd for that drive, or the process cwd if
148
139
// the drive cwd is not available. We're sure the device is not
149
140
// a UNC path at this points, because UNC paths are always absolute.
150
- path = process . env [ '=' + resolvedDevice ] || process . cwd ( ) ;
141
+ path = process . env [ `= ${ resolvedDevice } ` ] || process . cwd ( ) ;
151
142
152
143
// Verify that a cwd was found and that it actually points
153
144
// to our drive. If not, default to the drive's root.
@@ -272,18 +263,19 @@ const win32 = {
272
263
resolvedTail = normalizeString ( resolvedTail , ! resolvedAbsolute , '\\' ,
273
264
isPathSeparator ) ;
274
265
275
- return ( resolvedDevice + ( resolvedAbsolute ? '\\' : '' ) + resolvedTail ) ||
276
- '.' ;
266
+ return resolvedAbsolute ?
267
+ `${ resolvedDevice } \\${ resolvedTail } ` :
268
+ `${ resolvedDevice } ${ resolvedTail } ` || '.' ;
277
269
} ,
278
270
279
- normalize : function normalize ( path ) {
271
+ normalize ( path ) {
280
272
validateString ( path , 'path' ) ;
281
273
const len = path . length ;
282
274
if ( len === 0 )
283
275
return '.' ;
284
- var rootEnd = 0 ;
285
- var device ;
286
- var isAbsolute = false ;
276
+ let rootEnd = 0 ;
277
+ let device ;
278
+ let isAbsolute = false ;
287
279
const code = path . charCodeAt ( 0 ) ;
288
280
289
281
// Try to match a root
@@ -360,42 +352,20 @@ const win32 = {
360
352
return '\\' ;
361
353
}
362
354
363
- var tail ;
364
- if ( rootEnd < len ) {
365
- tail = normalizeString ( path . slice ( rootEnd ) , ! isAbsolute , '\\' ,
366
- isPathSeparator ) ;
367
- } else {
368
- tail = '' ;
369
- }
355
+ let tail = rootEnd < len ?
356
+ normalizeString ( path . slice ( rootEnd ) , ! isAbsolute , '\\' , isPathSeparator ) :
357
+ '' ;
370
358
if ( tail . length === 0 && ! isAbsolute )
371
359
tail = '.' ;
372
360
if ( tail . length > 0 && isPathSeparator ( path . charCodeAt ( len - 1 ) ) )
373
361
tail += '\\' ;
374
362
if ( device === undefined ) {
375
- if ( isAbsolute ) {
376
- if ( tail . length > 0 )
377
- return '\\' + tail ;
378
- else
379
- return '\\' ;
380
- } else if ( tail . length > 0 ) {
381
- return tail ;
382
- } else {
383
- return '' ;
384
- }
385
- } else if ( isAbsolute ) {
386
- if ( tail . length > 0 )
387
- return device + '\\' + tail ;
388
- else
389
- return device + '\\' ;
390
- } else if ( tail . length > 0 ) {
391
- return device + tail ;
392
- } else {
393
- return device ;
363
+ return isAbsolute ? `\\${ tail } ` : tail ;
394
364
}
365
+ return isAbsolute ? `${ device } \\${ tail } ` : `${ device } ${ tail } ` ;
395
366
} ,
396
367
397
-
398
- isAbsolute : function isAbsolute ( path ) {
368
+ isAbsolute ( path ) {
399
369
validateString ( path , 'path' ) ;
400
370
const len = path . length ;
401
371
if ( len === 0 )
@@ -429,7 +399,7 @@ const win32 = {
429
399
if ( joined === undefined )
430
400
joined = firstPart = arg ;
431
401
else
432
- joined += '\\' + arg ;
402
+ joined += `\\ ${ arg } ` ;
433
403
}
434
404
}
435
405
@@ -449,8 +419,8 @@ const win32 = {
449
419
// This means that the user can use join to construct UNC paths from
450
420
// a server name and a share name; for example:
451
421
// path.join('//server', 'share') -> '\\\\server\\share\\')
452
- var needsReplace = true ;
453
- var slashCount = 0 ;
422
+ let needsReplace = true ;
423
+ let slashCount = 0 ;
454
424
if ( isPathSeparator ( firstPart . charCodeAt ( 0 ) ) ) {
455
425
++ slashCount ;
456
426
const firstLen = firstPart . length ;
@@ -477,26 +447,25 @@ const win32 = {
477
447
478
448
// Replace the slashes if needed
479
449
if ( slashCount >= 2 )
480
- joined = '\\' + joined . slice ( slashCount ) ;
450
+ joined = `\\ ${ joined . slice ( slashCount ) } ` ;
481
451
}
482
452
483
453
return win32 . normalize ( joined ) ;
484
454
} ,
485
455
486
-
487
456
// It will solve the relative path from `from` to `to`, for instance:
488
457
// from = 'C:\\orandea\\test\\aaa'
489
458
// to = 'C:\\orandea\\impl\\bbb'
490
459
// The output of the function should be: '..\\..\\impl\\bbb'
491
- relative : function relative ( from , to ) {
460
+ relative ( from , to ) {
492
461
validateString ( from , 'from' ) ;
493
462
validateString ( to , 'to' ) ;
494
463
495
464
if ( from === to )
496
465
return '' ;
497
466
498
- var fromOrig = win32 . resolve ( from ) ;
499
- var toOrig = win32 . resolve ( to ) ;
467
+ const fromOrig = win32 . resolve ( from ) ;
468
+ const toOrig = win32 . resolve ( to ) ;
500
469
501
470
if ( fromOrig === toOrig )
502
471
return '' ;
@@ -519,7 +488,7 @@ const win32 = {
519
488
if ( from . charCodeAt ( fromEnd - 1 ) !== CHAR_BACKWARD_SLASH )
520
489
break ;
521
490
}
522
- var fromLen = ( fromEnd - fromStart ) ;
491
+ const fromLen = fromEnd - fromStart ;
523
492
524
493
// Trim any leading backslashes
525
494
var toStart = 0 ;
@@ -533,7 +502,7 @@ const win32 = {
533
502
if ( to . charCodeAt ( toEnd - 1 ) !== CHAR_BACKWARD_SLASH )
534
503
break ;
535
504
}
536
- var toLen = ( toEnd - toStart ) ;
505
+ const toLen = toEnd - toStart ;
537
506
538
507
// Compare paths to find the longest common path from root
539
508
var length = ( fromLen < toLen ? fromLen : toLen ) ;
@@ -579,17 +548,14 @@ const win32 = {
579
548
return toOrig ;
580
549
}
581
550
582
- var out = '' ;
551
+ let out = '' ;
583
552
if ( lastCommonSep === - 1 )
584
553
lastCommonSep = 0 ;
585
554
// Generate the relative path based on the path difference between `to` and
586
555
// `from`
587
556
for ( i = fromStart + lastCommonSep + 1 ; i <= fromEnd ; ++ i ) {
588
557
if ( i === fromEnd || from . charCodeAt ( i ) === CHAR_BACKWARD_SLASH ) {
589
- if ( out . length === 0 )
590
- out += '..' ;
591
- else
592
- out += '\\..' ;
558
+ out += out . length === 0 ? '..' : '\\..' ;
593
559
}
594
560
}
595
561
@@ -606,7 +572,7 @@ const win32 = {
606
572
} ,
607
573
608
574
609
- toNamespacedPath : function toNamespacedPath ( path ) {
575
+ toNamespacedPath ( path ) {
610
576
// Note: this will *probably* throw somewhere.
611
577
if ( typeof path !== 'string' )
612
578
return path ;
@@ -642,7 +608,7 @@ const win32 = {
642
608
return path ;
643
609
} ,
644
610
645
- dirname : function dirname ( path ) {
611
+ dirname ( path ) {
646
612
validateString ( path , 'path' ) ;
647
613
const len = path . length ;
648
614
if ( len === 0 )
@@ -731,14 +697,13 @@ const win32 = {
731
697
if ( end === - 1 ) {
732
698
if ( rootEnd === - 1 )
733
699
return '.' ;
734
- else
735
- end = rootEnd ;
700
+
701
+ end = rootEnd ;
736
702
}
737
703
return path . slice ( 0 , end ) ;
738
704
} ,
739
705
740
-
741
- basename : function basename ( path , ext ) {
706
+ basename ( path , ext ) {
742
707
if ( ext !== undefined )
743
708
validateString ( ext , 'ext' ) ;
744
709
validateString ( path , 'path' ) ;
@@ -902,7 +867,7 @@ const win32 = {
902
867
parse : function parse ( path ) {
903
868
validateString ( path , 'path' ) ;
904
869
905
- var ret = { root : '' , dir : '' , base : '' , ext : '' , name : '' } ;
870
+ const ret = { root : '' , dir : '' , base : '' , ext : '' , name : '' } ;
906
871
if ( path . length === 0 )
907
872
return ret ;
908
873
@@ -1177,17 +1142,17 @@ const posix = {
1177
1142
if ( from . charCodeAt ( fromStart ) !== CHAR_FORWARD_SLASH )
1178
1143
break ;
1179
1144
}
1180
- var fromEnd = from . length ;
1181
- var fromLen = ( fromEnd - fromStart ) ;
1145
+ const fromEnd = from . length ;
1146
+ const fromLen = ( fromEnd - fromStart ) ;
1182
1147
1183
1148
// Trim any leading backslashes
1184
1149
var toStart = 1 ;
1185
1150
for ( ; toStart < to . length ; ++ toStart ) {
1186
1151
if ( to . charCodeAt ( toStart ) !== CHAR_FORWARD_SLASH )
1187
1152
break ;
1188
1153
}
1189
- var toEnd = to . length ;
1190
- var toLen = ( toEnd - toStart ) ;
1154
+ const toEnd = to . length ;
1155
+ const toLen = ( toEnd - toStart ) ;
1191
1156
1192
1157
// Compare paths to find the longest common path from root
1193
1158
var length = ( fromLen < toLen ? fromLen : toLen ) ;
@@ -1425,10 +1390,10 @@ const posix = {
1425
1390
parse : function parse ( path ) {
1426
1391
validateString ( path , 'path' ) ;
1427
1392
1428
- var ret = { root : '' , dir : '' , base : '' , ext : '' , name : '' } ;
1393
+ const ret = { root : '' , dir : '' , base : '' , ext : '' , name : '' } ;
1429
1394
if ( path . length === 0 )
1430
1395
return ret ;
1431
- var isAbsolute = path . charCodeAt ( 0 ) === CHAR_FORWARD_SLASH ;
1396
+ const isAbsolute = path . charCodeAt ( 0 ) === CHAR_FORWARD_SLASH ;
1432
1397
var start ;
1433
1398
if ( isAbsolute ) {
1434
1399
ret . root = '/' ;
0 commit comments