22
22
'use strict' ;
23
23
24
24
const errors = require ( 'internal/errors' ) ;
25
+ const {
26
+ CHAR_UPPERCASE_A ,
27
+ CHAR_LOWERCASE_A ,
28
+ CHAR_UPPERCASE_Z ,
29
+ CHAR_LOWERCASE_Z ,
30
+ CHAR_DOT ,
31
+ CHAR_FORWARD_SLASH ,
32
+ CHAR_BACKWARD_SLASH ,
33
+ CHAR_COLON ,
34
+ CHAR_QUESTION_MARK ,
35
+ } = require ( 'internal/constants' ) ;
25
36
26
37
function assertPath ( path ) {
27
38
if ( typeof path !== 'string' ) {
@@ -39,17 +50,17 @@ function normalizeStringWin32(path, allowAboveRoot) {
39
50
for ( var i = 0 ; i <= path . length ; ++ i ) {
40
51
if ( i < path . length )
41
52
code = path . charCodeAt ( i ) ;
42
- else if ( code === 47 /*/*/ || code === 92 /*\*/ )
53
+ else if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH )
43
54
break ;
44
55
else
45
- code = 47 /*/*/ ;
46
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
56
+ code = CHAR_FORWARD_SLASH ;
57
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
47
58
if ( lastSlash === i - 1 || dots === 1 ) {
48
59
// NOOP
49
60
} else if ( lastSlash !== i - 1 && dots === 2 ) {
50
61
if ( res . length < 2 || lastSegmentLength !== 2 ||
51
- res . charCodeAt ( res . length - 1 ) !== 46 /*.*/ ||
52
- res . charCodeAt ( res . length - 2 ) !== 46 /*.*/ ) {
62
+ res . charCodeAt ( res . length - 1 ) !== CHAR_DOT ||
63
+ res . charCodeAt ( res . length - 2 ) !== CHAR_DOT ) {
53
64
if ( res . length > 2 ) {
54
65
const lastSlashIndex = res . lastIndexOf ( '\\' ) ;
55
66
if ( lastSlashIndex !== res . length - 1 ) {
@@ -88,7 +99,7 @@ function normalizeStringWin32(path, allowAboveRoot) {
88
99
}
89
100
lastSlash = i ;
90
101
dots = 0 ;
91
- } else if ( code === 46 /*.*/ && dots !== - 1 ) {
102
+ } else if ( code === CHAR_DOT && dots !== - 1 ) {
92
103
++ dots ;
93
104
} else {
94
105
dots = - 1 ;
@@ -107,17 +118,17 @@ function normalizeStringPosix(path, allowAboveRoot) {
107
118
for ( var i = 0 ; i <= path . length ; ++ i ) {
108
119
if ( i < path . length )
109
120
code = path . charCodeAt ( i ) ;
110
- else if ( code === 47 /*/*/ )
121
+ else if ( code === CHAR_FORWARD_SLASH )
111
122
break ;
112
123
else
113
- code = 47 /*/*/ ;
114
- if ( code === 47 /*/*/ ) {
124
+ code = CHAR_FORWARD_SLASH ;
125
+ if ( code === CHAR_FORWARD_SLASH ) {
115
126
if ( lastSlash === i - 1 || dots === 1 ) {
116
127
// NOOP
117
128
} else if ( lastSlash !== i - 1 && dots === 2 ) {
118
129
if ( res . length < 2 || lastSegmentLength !== 2 ||
119
- res . charCodeAt ( res . length - 1 ) !== 46 /*.*/ ||
120
- res . charCodeAt ( res . length - 2 ) !== 46 /*.*/ ) {
130
+ res . charCodeAt ( res . length - 1 ) !== CHAR_DOT ||
131
+ res . charCodeAt ( res . length - 2 ) !== CHAR_DOT ) {
121
132
if ( res . length > 2 ) {
122
133
const lastSlashIndex = res . lastIndexOf ( '/' ) ;
123
134
if ( lastSlashIndex !== res . length - 1 ) {
@@ -156,7 +167,7 @@ function normalizeStringPosix(path, allowAboveRoot) {
156
167
}
157
168
lastSlash = i ;
158
169
dots = 0 ;
159
- } else if ( code === 46 /*.*/ && dots !== - 1 ) {
170
+ } else if ( code === CHAR_DOT && dots !== - 1 ) {
160
171
++ dots ;
161
172
} else {
162
173
dots = - 1 ;
@@ -223,22 +234,22 @@ const win32 = {
223
234
224
235
// Try to match a root
225
236
if ( len > 1 ) {
226
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
237
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
227
238
// Possible UNC root
228
239
229
240
// If we started with a separator, we know we at least have an
230
241
// absolute path of some kind (UNC or otherwise)
231
242
isAbsolute = true ;
232
243
233
244
code = path . charCodeAt ( 1 ) ;
234
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
245
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
235
246
// Matched double path separator at beginning
236
247
var j = 2 ;
237
248
var last = j ;
238
249
// Match 1 or more non-path separators
239
250
for ( ; j < len ; ++ j ) {
240
251
code = path . charCodeAt ( j ) ;
241
- if ( code === 47 /*/*/ || code === 92 /*\*/ )
252
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH )
242
253
break ;
243
254
}
244
255
if ( j < len && j !== last ) {
@@ -248,7 +259,7 @@ const win32 = {
248
259
// Match 1 or more path separators
249
260
for ( ; j < len ; ++ j ) {
250
261
code = path . charCodeAt ( j ) ;
251
- if ( code !== 47 /*/*/ && code !== 92 /*\*/ )
262
+ if ( code !== CHAR_FORWARD_SLASH && code !== CHAR_BACKWARD_SLASH )
252
263
break ;
253
264
}
254
265
if ( j < len && j !== last ) {
@@ -257,7 +268,10 @@ const win32 = {
257
268
// Match 1 or more non-path separators
258
269
for ( ; j < len ; ++ j ) {
259
270
code = path . charCodeAt ( j ) ;
260
- if ( code === 47 /*/*/ || code === 92 /*\*/ )
271
+ const isPathSeparator =
272
+ code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ;
273
+
274
+ if ( isPathSeparator )
261
275
break ;
262
276
}
263
277
if ( j === len ) {
@@ -276,16 +290,16 @@ const win32 = {
276
290
} else {
277
291
rootEnd = 1 ;
278
292
}
279
- } else if ( ( code >= 65 /*A*/ && code <= 90 /*Z*/ ) ||
280
- ( code >= 97 /*a*/ && code <= 122 /*z*/ ) ) {
293
+ } else if ( ( code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z ) ||
294
+ ( code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z ) ) {
281
295
// Possible device root
282
296
283
- if ( path . charCodeAt ( 1 ) === 58 /*:*/ ) {
297
+ if ( path . charCodeAt ( 1 ) === CHAR_COLON ) {
284
298
device = path . slice ( 0 , 2 ) ;
285
299
rootEnd = 2 ;
286
300
if ( len > 2 ) {
287
301
code = path . charCodeAt ( 2 ) ;
288
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
302
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
289
303
// Treat separator following drive name as an absolute path
290
304
// indicator
291
305
isAbsolute = true ;
@@ -294,7 +308,7 @@ const win32 = {
294
308
}
295
309
}
296
310
}
297
- } else if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
311
+ } else if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
298
312
// `path` contains just a path separator
299
313
rootEnd = 1 ;
300
314
isAbsolute = true ;
@@ -343,22 +357,22 @@ const win32 = {
343
357
344
358
// Try to match a root
345
359
if ( len > 1 ) {
346
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
360
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
347
361
// Possible UNC root
348
362
349
363
// If we started with a separator, we know we at least have an absolute
350
364
// path of some kind (UNC or otherwise)
351
365
isAbsolute = true ;
352
366
353
367
code = path . charCodeAt ( 1 ) ;
354
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
368
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
355
369
// Matched double path separator at beginning
356
370
var j = 2 ;
357
371
var last = j ;
358
372
// Match 1 or more non-path separators
359
373
for ( ; j < len ; ++ j ) {
360
374
code = path . charCodeAt ( j ) ;
361
- if ( code === 47 /*/*/ || code === 92 /*\*/ )
375
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH )
362
376
break ;
363
377
}
364
378
if ( j < len && j !== last ) {
@@ -368,7 +382,7 @@ const win32 = {
368
382
// Match 1 or more path separators
369
383
for ( ; j < len ; ++ j ) {
370
384
code = path . charCodeAt ( j ) ;
371
- if ( code !== 47 /*/*/ && code !== 92 /*\*/ )
385
+ if ( code !== CHAR_FORWARD_SLASH && code !== CHAR_BACKWARD_SLASH )
372
386
break ;
373
387
}
374
388
if ( j < len && j !== last ) {
@@ -377,7 +391,7 @@ const win32 = {
377
391
// Match 1 or more non-path separators
378
392
for ( ; j < len ; ++ j ) {
379
393
code = path . charCodeAt ( j ) ;
380
- if ( code === 47 /*/*/ || code === 92 /*\*/ )
394
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH )
381
395
break ;
382
396
}
383
397
if ( j === len ) {
@@ -397,16 +411,16 @@ const win32 = {
397
411
} else {
398
412
rootEnd = 1 ;
399
413
}
400
- } else if ( ( code >= 65 /*A*/ && code <= 90 /*Z*/ ) ||
401
- ( code >= 97 /*a*/ && code <= 122 /*z*/ ) ) {
414
+ } else if ( ( code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z ) ||
415
+ ( code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z ) ) {
402
416
// Possible device root
403
417
404
- if ( path . charCodeAt ( 1 ) === 58 /*:*/ ) {
418
+ if ( path . charCodeAt ( 1 ) === CHAR_COLON ) {
405
419
device = path . slice ( 0 , 2 ) ;
406
420
rootEnd = 2 ;
407
421
if ( len > 2 ) {
408
422
code = path . charCodeAt ( 2 ) ;
409
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
423
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
410
424
// Treat separator following drive name as an absolute path
411
425
// indicator
412
426
isAbsolute = true ;
@@ -415,14 +429,15 @@ const win32 = {
415
429
}
416
430
}
417
431
}
418
- } else if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
432
+ } else if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
419
433
// `path` contains just a path separator, exit early to avoid unnecessary
420
434
// work
421
435
return '\\' ;
422
436
}
423
437
424
438
code = path . charCodeAt ( len - 1 ) ;
425
- var trailingSeparator = ( code === 47 /*/*/ || code === 92 /*\*/ ) ;
439
+ var trailingSeparator =
440
+ ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) ;
426
441
var tail ;
427
442
if ( rootEnd < len )
428
443
tail = normalizeStringWin32 ( path . slice ( rootEnd ) , ! isAbsolute ) ;
@@ -462,15 +477,15 @@ const win32 = {
462
477
if ( len === 0 )
463
478
return false ;
464
479
var code = path . charCodeAt ( 0 ) ;
465
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
480
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
466
481
return true ;
467
- } else if ( ( code >= 65 /*A*/ && code <= 90 /*Z*/ ) ||
468
- ( code >= 97 /*a*/ && code <= 122 /*z*/ ) ) {
482
+ } else if ( ( code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z ) ||
483
+ ( code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z ) ) {
469
484
// Possible device root
470
485
471
- if ( len > 2 && path . charCodeAt ( 1 ) === 58 /*:*/ ) {
486
+ if ( len > 2 && path . charCodeAt ( 1 ) === CHAR_COLON ) {
472
487
code = path . charCodeAt ( 2 ) ;
473
- if ( code === 47 /*/*/ || code === 92 /*\*/ )
488
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH )
474
489
return true ;
475
490
}
476
491
}
@@ -514,16 +529,16 @@ const win32 = {
514
529
var needsReplace = true ;
515
530
var slashCount = 0 ;
516
531
var code = firstPart . charCodeAt ( 0 ) ;
517
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
532
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
518
533
++ slashCount ;
519
534
const firstLen = firstPart . length ;
520
535
if ( firstLen > 1 ) {
521
536
code = firstPart . charCodeAt ( 1 ) ;
522
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
537
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
523
538
++ slashCount ;
524
539
if ( firstLen > 2 ) {
525
540
code = firstPart . charCodeAt ( 2 ) ;
526
- if ( code === 47 /*/*/ || code === 92 /*\*/ )
541
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH )
527
542
++ slashCount ;
528
543
else {
529
544
// We matched a UNC path in the first part
@@ -537,7 +552,7 @@ const win32 = {
537
552
// Find any more consecutive slashes we need to replace
538
553
for ( ; slashCount < joined . length ; ++ slashCount ) {
539
554
code = joined . charCodeAt ( slashCount ) ;
540
- if ( code !== 47 /*/*/ && code !== 92 /*\*/ )
555
+ if ( code !== CHAR_FORWARD_SLASH && code !== CHAR_BACKWARD_SLASH )
541
556
break ;
542
557
}
543
558
@@ -576,27 +591,27 @@ const win32 = {
576
591
// Trim any leading backslashes
577
592
var fromStart = 0 ;
578
593
for ( ; fromStart < from . length ; ++ fromStart ) {
579
- if ( from . charCodeAt ( fromStart ) !== 92 /*\*/ )
594
+ if ( from . charCodeAt ( fromStart ) !== CHAR_BACKWARD_SLASH )
580
595
break ;
581
596
}
582
597
// Trim trailing backslashes (applicable to UNC paths only)
583
598
var fromEnd = from . length ;
584
599
for ( ; fromEnd - 1 > fromStart ; -- fromEnd ) {
585
- if ( from . charCodeAt ( fromEnd - 1 ) !== 92 /*\*/ )
600
+ if ( from . charCodeAt ( fromEnd - 1 ) !== CHAR_BACKWARD_SLASH )
586
601
break ;
587
602
}
588
603
var fromLen = ( fromEnd - fromStart ) ;
589
604
590
605
// Trim any leading backslashes
591
606
var toStart = 0 ;
592
607
for ( ; toStart < to . length ; ++ toStart ) {
593
- if ( to . charCodeAt ( toStart ) !== 92 /*\*/ )
608
+ if ( to . charCodeAt ( toStart ) !== CHAR_BACKWARD_SLASH )
594
609
break ;
595
610
}
596
611
// Trim trailing backslashes (applicable to UNC paths only)
597
612
var toEnd = to . length ;
598
613
for ( ; toEnd - 1 > toStart ; -- toEnd ) {
599
- if ( to . charCodeAt ( toEnd - 1 ) !== 92 /*\*/ )
614
+ if ( to . charCodeAt ( toEnd - 1 ) !== CHAR_BACKWARD_SLASH )
600
615
break ;
601
616
}
602
617
var toLen = ( toEnd - toStart ) ;
@@ -608,7 +623,7 @@ const win32 = {
608
623
for ( ; i <= length ; ++ i ) {
609
624
if ( i === length ) {
610
625
if ( toLen > length ) {
611
- if ( to . charCodeAt ( toStart + i ) === 92 /*\*/ ) {
626
+ if ( to . charCodeAt ( toStart + i ) === CHAR_BACKWARD_SLASH ) {
612
627
// We get here if `from` is the exact base path for `to`.
613
628
// For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
614
629
return toOrig . slice ( toStart + i + 1 ) ;
@@ -619,7 +634,7 @@ const win32 = {
619
634
}
620
635
}
621
636
if ( fromLen > length ) {
622
- if ( from . charCodeAt ( fromStart + i ) === 92 /*\*/ ) {
637
+ if ( from . charCodeAt ( fromStart + i ) === CHAR_BACKWARD_SLASH ) {
623
638
// We get here if `to` is the exact base path for `from`.
624
639
// For example: from='C:\\foo\\bar'; to='C:\\foo'
625
640
lastCommonSep = i ;
@@ -635,7 +650,7 @@ const win32 = {
635
650
var toCode = to . charCodeAt ( toStart + i ) ;
636
651
if ( fromCode !== toCode )
637
652
break ;
638
- else if ( fromCode === 92 /*\*/ )
653
+ else if ( fromCode === CHAR_BACKWARD_SLASH )
639
654
lastCommonSep = i ;
640
655
}
641
656
@@ -651,7 +666,7 @@ const win32 = {
651
666
// Generate the relative path based on the path difference between `to` and
652
667
// `from`
653
668
for ( i = fromStart + lastCommonSep + 1 ; i <= fromEnd ; ++ i ) {
654
- if ( i === fromEnd || from . charCodeAt ( i ) === 92 /*\*/ ) {
669
+ if ( i === fromEnd || from . charCodeAt ( i ) === CHAR_BACKWARD_SLASH ) {
655
670
if ( out . length === 0 )
656
671
out += '..' ;
657
672
else
@@ -665,7 +680,7 @@ const win32 = {
665
680
return out + toOrig . slice ( toStart + lastCommonSep , toEnd ) ;
666
681
else {
667
682
toStart += lastCommonSep ;
668
- if ( toOrig . charCodeAt ( toStart ) === 92 /*\*/ )
683
+ if ( toOrig . charCodeAt ( toStart ) === CHAR_BACKWARD_SLASH )
669
684
++ toStart ;
670
685
return toOrig . slice ( toStart , toEnd ) ;
671
686
}
@@ -685,22 +700,22 @@ const win32 = {
685
700
686
701
if ( resolvedPath . length >= 3 ) {
687
702
var code = resolvedPath . charCodeAt ( 0 ) ;
688
- if ( code === 92 /*\*/ ) {
703
+ if ( code === CHAR_BACKWARD_SLASH ) {
689
704
// Possible UNC root
690
705
691
- if ( resolvedPath . charCodeAt ( 1 ) === 92 /*\*/ ) {
706
+ if ( resolvedPath . charCodeAt ( 1 ) === CHAR_BACKWARD_SLASH ) {
692
707
code = resolvedPath . charCodeAt ( 2 ) ;
693
- if ( code !== 63 /*?*/ && code !== 46 /*.*/ ) {
708
+ if ( code !== CHAR_QUESTION_MARK && code !== CHAR_DOT ) {
694
709
// Matched non-long UNC root, convert the path to a long UNC path
695
710
return '\\\\?\\UNC\\' + resolvedPath . slice ( 2 ) ;
696
711
}
697
712
}
698
- } else if ( ( code >= 65 /*A*/ && code <= 90 /*Z*/ ) ||
699
- ( code >= 97 /*a*/ && code <= 122 /*z*/ ) ) {
713
+ } else if ( ( code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z ) ||
714
+ ( code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z ) ) {
700
715
// Possible device root
701
716
702
- if ( resolvedPath . charCodeAt ( 1 ) === 58 /*:*/ &&
703
- resolvedPath . charCodeAt ( 2 ) === 92 /*\*/ ) {
717
+ if ( resolvedPath . charCodeAt ( 1 ) === CHAR_COLON &&
718
+ resolvedPath . charCodeAt ( 2 ) === CHAR_BACKWARD_SLASH ) {
704
719
// Matched device root, convert the path to a long UNC path
705
720
return '\\\\?\\' + resolvedPath ;
706
721
}
@@ -723,20 +738,20 @@ const win32 = {
723
738
724
739
// Try to match a root
725
740
if ( len > 1 ) {
726
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
741
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
727
742
// Possible UNC root
728
743
729
744
rootEnd = offset = 1 ;
730
745
731
746
code = path . charCodeAt ( 1 ) ;
732
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
747
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
733
748
// Matched double path separator at beginning
734
749
var j = 2 ;
735
750
var last = j ;
736
751
// Match 1 or more non-path separators
737
752
for ( ; j < len ; ++ j ) {
738
753
code = path . charCodeAt ( j ) ;
739
- if ( code === 47 /*/*/ || code === 92 /*\*/ )
754
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH )
740
755
break ;
741
756
}
742
757
if ( j < len && j !== last ) {
@@ -745,7 +760,7 @@ const win32 = {
745
760
// Match 1 or more path separators
746
761
for ( ; j < len ; ++ j ) {
747
762
code = path . charCodeAt ( j ) ;
748
- if ( code !== 47 /*/*/ && code !== 92 /*\*/ )
763
+ if ( code !== CHAR_FORWARD_SLASH && code !== CHAR_BACKWARD_SLASH )
749
764
break ;
750
765
}
751
766
if ( j < len && j !== last ) {
@@ -754,7 +769,7 @@ const win32 = {
754
769
// Match 1 or more non-path separators
755
770
for ( ; j < len ; ++ j ) {
756
771
code = path . charCodeAt ( j ) ;
757
- if ( code === 47 /*/*/ || code === 92 /*\*/ )
772
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH )
758
773
break ;
759
774
}
760
775
if ( j === len ) {
@@ -771,28 +786,28 @@ const win32 = {
771
786
}
772
787
}
773
788
}
774
- } else if ( ( code >= 65 /*A*/ && code <= 90 /*Z*/ ) ||
775
- ( code >= 97 /*a*/ && code <= 122 /*z*/ ) ) {
789
+ } else if ( ( code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z ) ||
790
+ ( code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z ) ) {
776
791
// Possible device root
777
792
778
- if ( path . charCodeAt ( 1 ) === 58 /*:*/ ) {
793
+ if ( path . charCodeAt ( 1 ) === CHAR_COLON ) {
779
794
rootEnd = offset = 2 ;
780
795
if ( len > 2 ) {
781
796
code = path . charCodeAt ( 2 ) ;
782
- if ( code === 47 /*/*/ || code === 92 /*\*/ )
797
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH )
783
798
rootEnd = offset = 3 ;
784
799
}
785
800
}
786
801
}
787
- } else if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
802
+ } else if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
788
803
// `path` contains just a path separator, exit early to avoid
789
804
// unnecessary work
790
805
return path ;
791
806
}
792
807
793
808
for ( var i = len - 1 ; i >= offset ; -- i ) {
794
809
code = path . charCodeAt ( i ) ;
795
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
810
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
796
811
if ( ! matchedSlash ) {
797
812
end = i ;
798
813
break ;
@@ -827,9 +842,9 @@ const win32 = {
827
842
// disregarded
828
843
if ( path . length >= 2 ) {
829
844
const drive = path . charCodeAt ( 0 ) ;
830
- if ( ( drive >= 65 /*A*/ && drive <= 90 /*Z*/ ) ||
831
- ( drive >= 97 /*a*/ && drive <= 122 /*z*/ ) ) {
832
- if ( path . charCodeAt ( 1 ) === 58 /*:*/ )
845
+ if ( ( drive >= CHAR_UPPERCASE_A && drive <= CHAR_UPPERCASE_Z ) ||
846
+ ( drive >= CHAR_LOWERCASE_A && drive <= CHAR_LOWERCASE_Z ) ) {
847
+ if ( path . charCodeAt ( 1 ) === CHAR_COLON )
833
848
start = 2 ;
834
849
}
835
850
}
@@ -841,7 +856,7 @@ const win32 = {
841
856
var firstNonSlashEnd = - 1 ;
842
857
for ( i = path . length - 1 ; i >= start ; -- i ) {
843
858
const code = path . charCodeAt ( i ) ;
844
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
859
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
845
860
// If we reached a path separator that was not part of a set of path
846
861
// separators at the end of the string, stop now
847
862
if ( ! matchedSlash ) {
@@ -881,7 +896,7 @@ const win32 = {
881
896
} else {
882
897
for ( i = path . length - 1 ; i >= start ; -- i ) {
883
898
const code = path . charCodeAt ( i ) ;
884
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
899
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
885
900
// If we reached a path separator that was not part of a set of path
886
901
// separators at the end of the string, stop now
887
902
if ( ! matchedSlash ) {
@@ -919,16 +934,16 @@ const win32 = {
919
934
// disregarded
920
935
if ( path . length >= 2 ) {
921
936
const code = path . charCodeAt ( 0 ) ;
922
- if ( path . charCodeAt ( 1 ) === 58 /*:*/ &&
923
- ( ( code >= 65 /*A*/ && code <= 90 /*Z*/ ) ||
924
- ( code >= 97 /*a*/ && code <= 122 /*z*/ ) ) ) {
937
+ if ( path . charCodeAt ( 1 ) === CHAR_COLON &&
938
+ ( ( code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z ) ||
939
+ ( code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z ) ) ) {
925
940
start = startPart = 2 ;
926
941
}
927
942
}
928
943
929
944
for ( var i = path . length - 1 ; i >= start ; -- i ) {
930
945
const code = path . charCodeAt ( i ) ;
931
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
946
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
932
947
// If we reached a path separator that was not part of a set of path
933
948
// separators at the end of the string, stop now
934
949
if ( ! matchedSlash ) {
@@ -943,7 +958,7 @@ const win32 = {
943
958
matchedSlash = false ;
944
959
end = i + 1 ;
945
960
}
946
- if ( code === 46 /*.*/ ) {
961
+ if ( code === CHAR_DOT ) {
947
962
// If this is our first dot, mark it as the start of our extension
948
963
if ( startDot === - 1 )
949
964
startDot = i ;
@@ -992,19 +1007,19 @@ const win32 = {
992
1007
993
1008
// Try to match a root
994
1009
if ( len > 1 ) {
995
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
1010
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
996
1011
// Possible UNC root
997
1012
998
1013
code = path . charCodeAt ( 1 ) ;
999
1014
rootEnd = 1 ;
1000
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
1015
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
1001
1016
// Matched double path separator at beginning
1002
1017
var j = 2 ;
1003
1018
var last = j ;
1004
1019
// Match 1 or more non-path separators
1005
1020
for ( ; j < len ; ++ j ) {
1006
1021
code = path . charCodeAt ( j ) ;
1007
- if ( code === 47 /*/*/ || code === 92 /*\*/ )
1022
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH )
1008
1023
break ;
1009
1024
}
1010
1025
if ( j < len && j !== last ) {
@@ -1013,7 +1028,7 @@ const win32 = {
1013
1028
// Match 1 or more path separators
1014
1029
for ( ; j < len ; ++ j ) {
1015
1030
code = path . charCodeAt ( j ) ;
1016
- if ( code !== 47 /*/*/ && code !== 92 /*\*/ )
1031
+ if ( code !== CHAR_FORWARD_SLASH && code !== CHAR_BACKWARD_SLASH )
1017
1032
break ;
1018
1033
}
1019
1034
if ( j < len && j !== last ) {
@@ -1022,7 +1037,7 @@ const win32 = {
1022
1037
// Match 1 or more non-path separators
1023
1038
for ( ; j < len ; ++ j ) {
1024
1039
code = path . charCodeAt ( j ) ;
1025
- if ( code === 47 /*/*/ || code === 92 /*\*/ )
1040
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH )
1026
1041
break ;
1027
1042
}
1028
1043
if ( j === len ) {
@@ -1037,15 +1052,15 @@ const win32 = {
1037
1052
}
1038
1053
}
1039
1054
}
1040
- } else if ( ( code >= 65 /*A*/ && code <= 90 /*Z*/ ) ||
1041
- ( code >= 97 /*a*/ && code <= 122 /*z*/ ) ) {
1055
+ } else if ( ( code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z ) ||
1056
+ ( code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z ) ) {
1042
1057
// Possible device root
1043
1058
1044
- if ( path . charCodeAt ( 1 ) === 58 /*:*/ ) {
1059
+ if ( path . charCodeAt ( 1 ) === CHAR_COLON ) {
1045
1060
rootEnd = 2 ;
1046
1061
if ( len > 2 ) {
1047
1062
code = path . charCodeAt ( 2 ) ;
1048
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
1063
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
1049
1064
if ( len === 3 ) {
1050
1065
// `path` contains just a drive root, exit early to avoid
1051
1066
// unnecessary work
@@ -1062,7 +1077,7 @@ const win32 = {
1062
1077
}
1063
1078
}
1064
1079
}
1065
- } else if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
1080
+ } else if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
1066
1081
// `path` contains just a path separator, exit early to avoid
1067
1082
// unnecessary work
1068
1083
ret . root = ret . dir = path ;
@@ -1085,7 +1100,7 @@ const win32 = {
1085
1100
// Get non-dir info
1086
1101
for ( ; i >= rootEnd ; -- i ) {
1087
1102
code = path . charCodeAt ( i ) ;
1088
- if ( code === 47 /*/*/ || code === 92 /*\*/ ) {
1103
+ if ( code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH ) {
1089
1104
// If we reached a path separator that was not part of a set of path
1090
1105
// separators at the end of the string, stop now
1091
1106
if ( ! matchedSlash ) {
@@ -1100,7 +1115,7 @@ const win32 = {
1100
1115
matchedSlash = false ;
1101
1116
end = i + 1 ;
1102
1117
}
1103
- if ( code === 46 /*.*/ ) {
1118
+ if ( code === CHAR_DOT ) {
1104
1119
// If this is our first dot, mark it as the start of our extension
1105
1120
if ( startDot === - 1 )
1106
1121
startDot = i ;
@@ -1174,7 +1189,7 @@ const posix = {
1174
1189
}
1175
1190
1176
1191
resolvedPath = path + '/' + resolvedPath ;
1177
- resolvedAbsolute = path . charCodeAt ( 0 ) === 47 /*/*/ ;
1192
+ resolvedAbsolute = path . charCodeAt ( 0 ) === CHAR_FORWARD_SLASH ;
1178
1193
}
1179
1194
1180
1195
// At this point the path should be resolved to a full absolute path, but
@@ -1202,8 +1217,9 @@ const posix = {
1202
1217
if ( path . length === 0 )
1203
1218
return '.' ;
1204
1219
1205
- const isAbsolute = path . charCodeAt ( 0 ) === 47 /*/*/ ;
1206
- const trailingSeparator = path . charCodeAt ( path . length - 1 ) === 47 /*/*/ ;
1220
+ const isAbsolute = path . charCodeAt ( 0 ) === CHAR_FORWARD_SLASH ;
1221
+ const trailingSeparator =
1222
+ path . charCodeAt ( path . length - 1 ) === CHAR_FORWARD_SLASH ;
1207
1223
1208
1224
// Normalize the path
1209
1225
path = normalizeStringPosix ( path , ! isAbsolute ) ;
@@ -1221,7 +1237,7 @@ const posix = {
1221
1237
1222
1238
isAbsolute : function isAbsolute ( path ) {
1223
1239
assertPath ( path ) ;
1224
- return path . length > 0 && path . charCodeAt ( 0 ) === 47 /*/*/ ;
1240
+ return path . length > 0 && path . charCodeAt ( 0 ) === CHAR_FORWARD_SLASH ;
1225
1241
} ,
1226
1242
1227
1243
@@ -1261,7 +1277,7 @@ const posix = {
1261
1277
// Trim any leading backslashes
1262
1278
var fromStart = 1 ;
1263
1279
for ( ; fromStart < from . length ; ++ fromStart ) {
1264
- if ( from . charCodeAt ( fromStart ) !== 47 /*/*/ )
1280
+ if ( from . charCodeAt ( fromStart ) !== CHAR_FORWARD_SLASH )
1265
1281
break ;
1266
1282
}
1267
1283
var fromEnd = from . length ;
@@ -1270,7 +1286,7 @@ const posix = {
1270
1286
// Trim any leading backslashes
1271
1287
var toStart = 1 ;
1272
1288
for ( ; toStart < to . length ; ++ toStart ) {
1273
- if ( to . charCodeAt ( toStart ) !== 47 /*/*/ )
1289
+ if ( to . charCodeAt ( toStart ) !== CHAR_FORWARD_SLASH )
1274
1290
break ;
1275
1291
}
1276
1292
var toEnd = to . length ;
@@ -1283,7 +1299,7 @@ const posix = {
1283
1299
for ( ; i <= length ; ++ i ) {
1284
1300
if ( i === length ) {
1285
1301
if ( toLen > length ) {
1286
- if ( to . charCodeAt ( toStart + i ) === 47 /*/*/ ) {
1302
+ if ( to . charCodeAt ( toStart + i ) === CHAR_FORWARD_SLASH ) {
1287
1303
// We get here if `from` is the exact base path for `to`.
1288
1304
// For example: from='/foo/bar'; to='/foo/bar/baz'
1289
1305
return to . slice ( toStart + i + 1 ) ;
@@ -1293,7 +1309,7 @@ const posix = {
1293
1309
return to . slice ( toStart + i ) ;
1294
1310
}
1295
1311
} else if ( fromLen > length ) {
1296
- if ( from . charCodeAt ( fromStart + i ) === 47 /*/*/ ) {
1312
+ if ( from . charCodeAt ( fromStart + i ) === CHAR_FORWARD_SLASH ) {
1297
1313
// We get here if `to` is the exact base path for `from`.
1298
1314
// For example: from='/foo/bar/baz'; to='/foo/bar'
1299
1315
lastCommonSep = i ;
@@ -1309,15 +1325,15 @@ const posix = {
1309
1325
var toCode = to . charCodeAt ( toStart + i ) ;
1310
1326
if ( fromCode !== toCode )
1311
1327
break ;
1312
- else if ( fromCode === 47 /*/*/ )
1328
+ else if ( fromCode === CHAR_FORWARD_SLASH )
1313
1329
lastCommonSep = i ;
1314
1330
}
1315
1331
1316
1332
var out = '' ;
1317
1333
// Generate the relative path based on the path difference between `to`
1318
1334
// and `from`
1319
1335
for ( i = fromStart + lastCommonSep + 1 ; i <= fromEnd ; ++ i ) {
1320
- if ( i === fromEnd || from . charCodeAt ( i ) === 47 /*/*/ ) {
1336
+ if ( i === fromEnd || from . charCodeAt ( i ) === CHAR_FORWARD_SLASH ) {
1321
1337
if ( out . length === 0 )
1322
1338
out += '..' ;
1323
1339
else
@@ -1331,7 +1347,7 @@ const posix = {
1331
1347
return out + to . slice ( toStart + lastCommonSep ) ;
1332
1348
else {
1333
1349
toStart += lastCommonSep ;
1334
- if ( to . charCodeAt ( toStart ) === 47 /*/*/ )
1350
+ if ( to . charCodeAt ( toStart ) === CHAR_FORWARD_SLASH )
1335
1351
++ toStart ;
1336
1352
return to . slice ( toStart ) ;
1337
1353
}
@@ -1348,12 +1364,12 @@ const posix = {
1348
1364
if ( path . length === 0 )
1349
1365
return '.' ;
1350
1366
var code = path . charCodeAt ( 0 ) ;
1351
- var hasRoot = ( code === 47 /*/*/ ) ;
1367
+ var hasRoot = ( code === CHAR_FORWARD_SLASH ) ;
1352
1368
var end = - 1 ;
1353
1369
var matchedSlash = true ;
1354
1370
for ( var i = path . length - 1 ; i >= 1 ; -- i ) {
1355
1371
code = path . charCodeAt ( i ) ;
1356
- if ( code === 47 /*/*/ ) {
1372
+ if ( code === CHAR_FORWARD_SLASH ) {
1357
1373
if ( ! matchedSlash ) {
1358
1374
end = i ;
1359
1375
break ;
@@ -1389,7 +1405,7 @@ const posix = {
1389
1405
var firstNonSlashEnd = - 1 ;
1390
1406
for ( i = path . length - 1 ; i >= 0 ; -- i ) {
1391
1407
const code = path . charCodeAt ( i ) ;
1392
- if ( code === 47 /*/*/ ) {
1408
+ if ( code === CHAR_FORWARD_SLASH ) {
1393
1409
// If we reached a path separator that was not part of a set of path
1394
1410
// separators at the end of the string, stop now
1395
1411
if ( ! matchedSlash ) {
@@ -1428,7 +1444,7 @@ const posix = {
1428
1444
return path . slice ( start , end ) ;
1429
1445
} else {
1430
1446
for ( i = path . length - 1 ; i >= 0 ; -- i ) {
1431
- if ( path . charCodeAt ( i ) === 47 /*/*/ ) {
1447
+ if ( path . charCodeAt ( i ) === CHAR_FORWARD_SLASH ) {
1432
1448
// If we reached a path separator that was not part of a set of path
1433
1449
// separators at the end of the string, stop now
1434
1450
if ( ! matchedSlash ) {
@@ -1461,7 +1477,7 @@ const posix = {
1461
1477
var preDotState = 0 ;
1462
1478
for ( var i = path . length - 1 ; i >= 0 ; -- i ) {
1463
1479
const code = path . charCodeAt ( i ) ;
1464
- if ( code === 47 /*/*/ ) {
1480
+ if ( code === CHAR_FORWARD_SLASH ) {
1465
1481
// If we reached a path separator that was not part of a set of path
1466
1482
// separators at the end of the string, stop now
1467
1483
if ( ! matchedSlash ) {
@@ -1476,7 +1492,7 @@ const posix = {
1476
1492
matchedSlash = false ;
1477
1493
end = i + 1 ;
1478
1494
}
1479
- if ( code === 46 /*.*/ ) {
1495
+ if ( code === CHAR_DOT ) {
1480
1496
// If this is our first dot, mark it as the start of our extension
1481
1497
if ( startDot === - 1 )
1482
1498
startDot = i ;
@@ -1519,7 +1535,7 @@ const posix = {
1519
1535
if ( path . length === 0 )
1520
1536
return ret ;
1521
1537
var code = path . charCodeAt ( 0 ) ;
1522
- var isAbsolute = ( code === 47 /*/*/ ) ;
1538
+ var isAbsolute = ( code === CHAR_FORWARD_SLASH ) ;
1523
1539
var start ;
1524
1540
if ( isAbsolute ) {
1525
1541
ret . root = '/' ;
@@ -1540,7 +1556,7 @@ const posix = {
1540
1556
// Get non-dir info
1541
1557
for ( ; i >= start ; -- i ) {
1542
1558
code = path . charCodeAt ( i ) ;
1543
- if ( code === 47 /*/*/ ) {
1559
+ if ( code === CHAR_FORWARD_SLASH ) {
1544
1560
// If we reached a path separator that was not part of a set of path
1545
1561
// separators at the end of the string, stop now
1546
1562
if ( ! matchedSlash ) {
@@ -1555,7 +1571,7 @@ const posix = {
1555
1571
matchedSlash = false ;
1556
1572
end = i + 1 ;
1557
1573
}
1558
- if ( code === 46 /*.*/ ) {
1574
+ if ( code === CHAR_DOT ) {
1559
1575
// If this is our first dot, mark it as the start of our extension
1560
1576
if ( startDot === - 1 )
1561
1577
startDot = i ;
0 commit comments