@oozcitak/url 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,48 @@
1
- import { isNumber, isArray, utf8Decode, utf8Encode, StringWalker } from "@oozcitak/util";
2
- import { ParserState, OpaqueOrigin } from "./interfaces";
3
- import { codePoint as infraCodePoint, list as infraList, byteSequence as infraByteSequence } from "@oozcitak/infra";
4
- import { domainToASCII as nodeDomainToASCII, domainToUnicode as nodeDomainToUnicode } from "url";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setValidationErrorCallback = setValidationErrorCallback;
4
+ exports.newURL = newURL;
5
+ exports.isSpecialScheme = isSpecialScheme;
6
+ exports.isSpecial = isSpecial;
7
+ exports.defaultPort = defaultPort;
8
+ exports.includesCredentials = includesCredentials;
9
+ exports.cannotHaveAUsernamePasswordPort = cannotHaveAUsernamePasswordPort;
10
+ exports.urlSerializer = urlSerializer;
11
+ exports.hostSerializer = hostSerializer;
12
+ exports.iPv4Serializer = iPv4Serializer;
13
+ exports.iPv6Serializer = iPv6Serializer;
14
+ exports.urlParser = urlParser;
15
+ exports.basicURLParser = basicURLParser;
16
+ exports.setTheUsername = setTheUsername;
17
+ exports.setThePassword = setThePassword;
18
+ exports.isSingleDotPathSegment = isSingleDotPathSegment;
19
+ exports.isDoubleDotPathSegment = isDoubleDotPathSegment;
20
+ exports.shorten = shorten;
21
+ exports.isNormalizedWindowsDriveLetter = isNormalizedWindowsDriveLetter;
22
+ exports.isWindowsDriveLetter = isWindowsDriveLetter;
23
+ exports.startsWithAWindowsDriveLetter = startsWithAWindowsDriveLetter;
24
+ exports.hostParser = hostParser;
25
+ exports.iPv4NumberParser = iPv4NumberParser;
26
+ exports.iPv4Parser = iPv4Parser;
27
+ exports.iPv6Parser = iPv6Parser;
28
+ exports.opaqueHostParser = opaqueHostParser;
29
+ exports.resolveABlobURL = resolveABlobURL;
30
+ exports.percentEncode = percentEncode;
31
+ exports.percentDecode = percentDecode;
32
+ exports.stringPercentDecode = stringPercentDecode;
33
+ exports.utf8PercentEncode = utf8PercentEncode;
34
+ exports.hostEquals = hostEquals;
35
+ exports.urlEquals = urlEquals;
36
+ exports.urlEncodedStringParser = urlEncodedStringParser;
37
+ exports.urlEncodedParser = urlEncodedParser;
38
+ exports.urlEncodedByteSerializer = urlEncodedByteSerializer;
39
+ exports.urlEncodedSerializer = urlEncodedSerializer;
40
+ exports.origin = origin;
41
+ exports.domainToASCII = domainToASCII;
42
+ exports.asciiSerializationOfAnOrigin = asciiSerializationOfAnOrigin;
43
+ const util_1 = require("@oozcitak/util");
44
+ const interfaces_1 = require("./interfaces");
45
+ const infra_1 = require("@oozcitak/infra");
5
46
  let _validationErrorCallback;
6
47
  /**
7
48
  * Default ports for a special URL scheme.
@@ -56,7 +97,7 @@ const _forbiddenHostCodePoint = /[\0\t\f\r #%/:?@\[\\\]]/;
56
97
  * @param validationErrorCallback - a callback function to be called when a
57
98
  * validation error occurs
58
99
  */
59
- export function setValidationErrorCallback(validationErrorCallback) {
100
+ function setValidationErrorCallback(validationErrorCallback) {
60
101
  _validationErrorCallback = validationErrorCallback;
61
102
  }
62
103
  /**
@@ -72,7 +113,7 @@ function validationError(message) {
72
113
  /**
73
114
  * Creates a new URL.
74
115
  */
75
- export function newURL() {
116
+ function newURL() {
76
117
  return {
77
118
  scheme: '',
78
119
  username: '',
@@ -91,7 +132,7 @@ export function newURL() {
91
132
  *
92
133
  * @param scheme - a scheme
93
134
  */
94
- export function isSpecialScheme(scheme) {
135
+ function isSpecialScheme(scheme) {
95
136
  return (scheme in _defaultPorts);
96
137
  }
97
138
  /**
@@ -99,7 +140,7 @@ export function isSpecialScheme(scheme) {
99
140
  *
100
141
  * @param url - an URL
101
142
  */
102
- export function isSpecial(url) {
143
+ function isSpecial(url) {
103
144
  return isSpecialScheme(url.scheme);
104
145
  }
105
146
  /**
@@ -107,7 +148,7 @@ export function isSpecial(url) {
107
148
  *
108
149
  * @param scheme - a scheme
109
150
  */
110
- export function defaultPort(scheme) {
151
+ function defaultPort(scheme) {
111
152
  return _defaultPorts[scheme] || null;
112
153
  }
113
154
  /**
@@ -115,7 +156,7 @@ export function defaultPort(scheme) {
115
156
  *
116
157
  * @param url - an URL
117
158
  */
118
- export function includesCredentials(url) {
159
+ function includesCredentials(url) {
119
160
  return url.username !== '' || url.password !== '';
120
161
  }
121
162
  /**
@@ -123,7 +164,7 @@ export function includesCredentials(url) {
123
164
  *
124
165
  * @param url - an URL
125
166
  */
126
- export function cannotHaveAUsernamePasswordPort(url) {
167
+ function cannotHaveAUsernamePasswordPort(url) {
127
168
  /**
128
169
  * A URL cannot have a username/password/port if its host is null or the
129
170
  * empty string, its cannot-be-a-base-URL flag is set, or its scheme is
@@ -137,7 +178,7 @@ export function cannotHaveAUsernamePasswordPort(url) {
137
178
  *
138
179
  * @param url - an URL
139
180
  */
140
- export function urlSerializer(url, excludeFragmentFlag = false) {
181
+ function urlSerializer(url, excludeFragmentFlag = false) {
141
182
  /**
142
183
  * 1. Let output be url’s scheme and U+003A (:) concatenated.
143
184
  */
@@ -216,7 +257,7 @@ export function urlSerializer(url, excludeFragmentFlag = false) {
216
257
  *
217
258
  * @param host - a host
218
259
  */
219
- export function hostSerializer(host) {
260
+ function hostSerializer(host) {
220
261
  /**
221
262
  * 1. If host is an IPv4 address, return the result of running the IPv4
222
263
  * serializer on host.
@@ -225,10 +266,10 @@ export function hostSerializer(host) {
225
266
  * U+005D (]).
226
267
  * 3. Otherwise, host is a domain, opaque host, or empty host, return host.
227
268
  */
228
- if (isNumber(host)) {
269
+ if ((0, util_1.isNumber)(host)) {
229
270
  return iPv4Serializer(host);
230
271
  }
231
- else if (isArray(host)) {
272
+ else if ((0, util_1.isArray)(host)) {
232
273
  return '[' + iPv6Serializer(host) + ']';
233
274
  }
234
275
  else {
@@ -240,7 +281,7 @@ export function hostSerializer(host) {
240
281
  *
241
282
  * @param address - an IPv4 address
242
283
  */
243
- export function iPv4Serializer(address) {
284
+ function iPv4Serializer(address) {
244
285
  /**
245
286
  * 1. Let output be the empty string.
246
287
  * 2. Let n be the value of address.
@@ -266,7 +307,7 @@ export function iPv4Serializer(address) {
266
307
  *
267
308
  * @param address - an IPv6 address represented as a list of eight numbers
268
309
  */
269
- export function iPv6Serializer(address) {
310
+ function iPv6Serializer(address) {
270
311
  /**
271
312
  * 1. Let output be the empty string.
272
313
  * 2. Let compress be an index to the first IPv6 piece in the first longest
@@ -343,7 +384,7 @@ export function iPv6Serializer(address) {
343
384
  * @param baseURL - base URL
344
385
  * @param encodingOverride - encoding override
345
386
  */
346
- export function urlParser(input, baseURL, encodingOverride) {
387
+ function urlParser(input, baseURL, encodingOverride) {
347
388
  /**
348
389
  * 1. Let url be the result of running the basic URL parser on input with
349
390
  * base, and encoding override as provided.
@@ -374,7 +415,7 @@ export function urlParser(input, baseURL, encodingOverride) {
374
415
  * @param baseURL - base URL
375
416
  * @param encodingOverride - encoding override
376
417
  */
377
- export function basicURLParser(input, baseURL, encodingOverride, url, stateOverride) {
418
+ function basicURLParser(input, baseURL, encodingOverride, url, stateOverride) {
378
419
  /**
379
420
  * 1. If url is not given:
380
421
  * 1.1. Set url to a new URL.
@@ -409,7 +450,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
409
450
  * 7. If encoding override is given, set encoding to the result of getting
410
451
  * an output encoding from encoding override.
411
452
  */
412
- let state = (stateOverride === undefined ? ParserState.SchemeStart : stateOverride);
453
+ let state = (stateOverride === undefined ? interfaces_1.ParserState.SchemeStart : stateOverride);
413
454
  if (baseURL === undefined)
414
455
  baseURL = null;
415
456
  let encoding = (encodingOverride === undefined ||
@@ -425,7 +466,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
425
466
  let arrayFlag = false;
426
467
  let passwordTokenSeenFlag = false;
427
468
  const EOF = "";
428
- const walker = new StringWalker(input);
469
+ const walker = new util_1.StringWalker(input);
429
470
  /**
430
471
  * 11. Keep running the following state machine by switching on state. If
431
472
  * after a run pointer points to the EOF code point, go to the next step.
@@ -433,7 +474,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
433
474
  */
434
475
  while (true) {
435
476
  switch (state) {
436
- case ParserState.SchemeStart:
477
+ case interfaces_1.ParserState.SchemeStart:
437
478
  /**
438
479
  * 1. If c is an ASCII alpha, append c, lowercased, to buffer, and set
439
480
  * state to scheme state.
@@ -441,12 +482,12 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
441
482
  * state, and decrease pointer by one.
442
483
  * 3. Otherwise, validation error, return failure.
443
484
  */
444
- if (infraCodePoint.ASCIIAlpha.test(walker.c())) {
485
+ if (infra_1.codePoint.ASCIIAlpha.test(walker.c())) {
445
486
  buffer += walker.c().toLowerCase();
446
- state = ParserState.Scheme;
487
+ state = interfaces_1.ParserState.Scheme;
447
488
  }
448
489
  else if (stateOverride === undefined) {
449
- state = ParserState.NoScheme;
490
+ state = interfaces_1.ParserState.NoScheme;
450
491
  walker.pointer--;
451
492
  }
452
493
  else {
@@ -454,12 +495,12 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
454
495
  return null;
455
496
  }
456
497
  break;
457
- case ParserState.Scheme:
498
+ case interfaces_1.ParserState.Scheme:
458
499
  /**
459
500
  * 1. If c is an ASCII alphanumeric, U+002B (+), U+002D (-), or U+002E
460
501
  * (.), append c, lowercased, to buffer.
461
502
  */
462
- if (infraCodePoint.ASCIIAlphanumeric.test(walker.c()) ||
503
+ if (infra_1.codePoint.ASCIIAlphanumeric.test(walker.c()) ||
463
504
  walker.c() === '+' || walker.c() === '-' || walker.c() === '.') {
464
505
  buffer += walker.c().toLowerCase();
465
506
  }
@@ -515,7 +556,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
515
556
  if (!walker.remaining().startsWith("//")) {
516
557
  validationError("Invalid file URL scheme, '//' expected.");
517
558
  }
518
- state = ParserState.File;
559
+ state = interfaces_1.ParserState.File;
519
560
  }
520
561
  else if (isSpecial(url) && baseURL !== null && baseURL.scheme === url.scheme) {
521
562
  /**
@@ -523,21 +564,21 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
523
564
  * scheme is equal to url’s scheme, set state to special relative
524
565
  * or authority state.
525
566
  */
526
- state = ParserState.SpecialRelativeOrAuthority;
567
+ state = interfaces_1.ParserState.SpecialRelativeOrAuthority;
527
568
  }
528
569
  else if (isSpecial(url)) {
529
570
  /**
530
571
  * 2.7. Otherwise, if url is special, set state to special
531
572
  * authority slashes state.
532
573
  */
533
- state = ParserState.SpecialAuthoritySlashes;
574
+ state = interfaces_1.ParserState.SpecialAuthoritySlashes;
534
575
  }
535
576
  else if (walker.remaining().startsWith("/")) {
536
577
  /**
537
578
  * 2.8. Otherwise, if remaining starts with an U+002F (/), set state
538
579
  * to path or authority state and increase pointer by one.
539
580
  */
540
- state = ParserState.PathOrAuthority;
581
+ state = interfaces_1.ParserState.PathOrAuthority;
541
582
  walker.pointer++;
542
583
  }
543
584
  else {
@@ -548,7 +589,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
548
589
  */
549
590
  url._cannotBeABaseURLFlag = true;
550
591
  url.path.push("");
551
- state = ParserState.CannotBeABaseURLPath;
592
+ state = interfaces_1.ParserState.CannotBeABaseURLPath;
552
593
  }
553
594
  }
554
595
  else if (stateOverride === undefined) {
@@ -558,7 +599,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
558
599
  * first code point in input).
559
600
  */
560
601
  buffer = "";
561
- state = ParserState.NoScheme;
602
+ state = interfaces_1.ParserState.NoScheme;
562
603
  walker.pointer = 0;
563
604
  continue;
564
605
  }
@@ -570,7 +611,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
570
611
  return null;
571
612
  }
572
613
  break;
573
- case ParserState.NoScheme:
614
+ case interfaces_1.ParserState.NoScheme:
574
615
  /**
575
616
  * 1. If base is null, or base’s cannot-be-a-base-URL flag is set
576
617
  * and c is not U+0023 (#), validation error, return failure.
@@ -589,22 +630,22 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
589
630
  }
590
631
  else if (baseURL._cannotBeABaseURLFlag && walker.c() === '#') {
591
632
  url.scheme = baseURL.scheme;
592
- url.path = infraList.clone(baseURL.path);
633
+ url.path = infra_1.list.clone(baseURL.path);
593
634
  url.query = baseURL.query;
594
635
  url.fragment = "";
595
636
  url._cannotBeABaseURLFlag = true;
596
- state = ParserState.Fragment;
637
+ state = interfaces_1.ParserState.Fragment;
597
638
  }
598
639
  else if (baseURL.scheme !== "file") {
599
- state = ParserState.Relative;
640
+ state = interfaces_1.ParserState.Relative;
600
641
  walker.pointer--;
601
642
  }
602
643
  else {
603
- state = ParserState.File;
644
+ state = interfaces_1.ParserState.File;
604
645
  walker.pointer--;
605
646
  }
606
647
  break;
607
- case ParserState.SpecialRelativeOrAuthority:
648
+ case interfaces_1.ParserState.SpecialRelativeOrAuthority:
608
649
  /**
609
650
  * If c is U+002F (/) and remaining starts with U+002F (/), then set
610
651
  * state to special authority ignore slashes state and increase
@@ -613,29 +654,29 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
613
654
  * decrease pointer by one.
614
655
  */
615
656
  if (walker.c() === '/' && walker.remaining().startsWith('/')) {
616
- state = ParserState.SpecialAuthorityIgnoreSlashes;
657
+ state = interfaces_1.ParserState.SpecialAuthorityIgnoreSlashes;
617
658
  walker.pointer++;
618
659
  }
619
660
  else {
620
661
  validationError("Invalid input string.");
621
- state = ParserState.Relative;
662
+ state = interfaces_1.ParserState.Relative;
622
663
  walker.pointer--;
623
664
  }
624
665
  break;
625
- case ParserState.PathOrAuthority:
666
+ case interfaces_1.ParserState.PathOrAuthority:
626
667
  /**
627
668
  * If c is U+002F (/), then set state to authority state.
628
669
  * Otherwise, set state to path state, and decrease pointer by one.
629
670
  */
630
671
  if (walker.c() === '/') {
631
- state = ParserState.Authority;
672
+ state = interfaces_1.ParserState.Authority;
632
673
  }
633
674
  else {
634
- state = ParserState.Path;
675
+ state = interfaces_1.ParserState.Path;
635
676
  walker.pointer--;
636
677
  }
637
678
  break;
638
- case ParserState.Relative:
679
+ case interfaces_1.ParserState.Relative:
639
680
  /**
640
681
  * Set url’s scheme to base’s scheme, and then, switching on c:
641
682
  */
@@ -655,14 +696,14 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
655
696
  url.password = baseURL.password;
656
697
  url.host = baseURL.host;
657
698
  url.port = baseURL.port;
658
- url.path = infraList.clone(baseURL.path);
699
+ url.path = infra_1.list.clone(baseURL.path);
659
700
  url.query = baseURL.query;
660
701
  break;
661
702
  case '/':
662
703
  /**
663
704
  * Set state to relative slash state.
664
705
  */
665
- state = ParserState.RelativeSlash;
706
+ state = interfaces_1.ParserState.RelativeSlash;
666
707
  break;
667
708
  case '?':
668
709
  /**
@@ -675,9 +716,9 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
675
716
  url.password = baseURL.password;
676
717
  url.host = baseURL.host;
677
718
  url.port = baseURL.port;
678
- url.path = infraList.clone(baseURL.path);
719
+ url.path = infra_1.list.clone(baseURL.path);
679
720
  url.query = "";
680
- state = ParserState.Query;
721
+ state = interfaces_1.ParserState.Query;
681
722
  break;
682
723
  case '#':
683
724
  /**
@@ -691,10 +732,10 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
691
732
  url.password = baseURL.password;
692
733
  url.host = baseURL.host;
693
734
  url.port = baseURL.port;
694
- url.path = infraList.clone(baseURL.path);
735
+ url.path = infra_1.list.clone(baseURL.path);
695
736
  url.query = baseURL.query;
696
737
  url.fragment = "";
697
- state = ParserState.Fragment;
738
+ state = interfaces_1.ParserState.Fragment;
698
739
  break;
699
740
  default:
700
741
  /**
@@ -709,23 +750,23 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
709
750
  */
710
751
  if (isSpecial(url) && walker.c() === '\\') {
711
752
  validationError("Invalid input string.");
712
- state = ParserState.RelativeSlash;
753
+ state = interfaces_1.ParserState.RelativeSlash;
713
754
  }
714
755
  else {
715
756
  url.username = baseURL.username;
716
757
  url.password = baseURL.password;
717
758
  url.host = baseURL.host;
718
759
  url.port = baseURL.port;
719
- url.path = infraList.clone(baseURL.path);
760
+ url.path = infra_1.list.clone(baseURL.path);
720
761
  if (url.path.length !== 0)
721
762
  url.path.splice(url.path.length - 1, 1);
722
- state = ParserState.Path;
763
+ state = interfaces_1.ParserState.Path;
723
764
  walker.pointer--;
724
765
  }
725
766
  break;
726
767
  }
727
768
  break;
728
- case ParserState.RelativeSlash:
769
+ case interfaces_1.ParserState.RelativeSlash:
729
770
  /**
730
771
  * 1. If url is special and c is U+002F (/) or U+005C (\), then:
731
772
  * 1.1. If c is U+005C (\), validation error.
@@ -739,10 +780,10 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
739
780
  if (walker.c() === '\\') {
740
781
  validationError("Invalid input string.");
741
782
  }
742
- state = ParserState.SpecialAuthorityIgnoreSlashes;
783
+ state = interfaces_1.ParserState.SpecialAuthorityIgnoreSlashes;
743
784
  }
744
785
  else if (walker.c() === '/') {
745
- state = ParserState.Authority;
786
+ state = interfaces_1.ParserState.Authority;
746
787
  }
747
788
  else {
748
789
  if (baseURL === null) {
@@ -752,11 +793,11 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
752
793
  url.password = baseURL.password;
753
794
  url.host = baseURL.host;
754
795
  url.port = baseURL.port;
755
- state = ParserState.Path;
796
+ state = interfaces_1.ParserState.Path;
756
797
  walker.pointer--;
757
798
  }
758
799
  break;
759
- case ParserState.SpecialAuthoritySlashes:
800
+ case interfaces_1.ParserState.SpecialAuthoritySlashes:
760
801
  /**
761
802
  * If c is U+002F (/) and remaining starts with U+002F (/), then set
762
803
  * state to special authority ignore slashes state and increase
@@ -765,30 +806,30 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
765
806
  * slashes state, and decrease pointer by one.
766
807
  */
767
808
  if (walker.c() === '/' && walker.remaining().startsWith('/')) {
768
- state = ParserState.SpecialAuthorityIgnoreSlashes;
809
+ state = interfaces_1.ParserState.SpecialAuthorityIgnoreSlashes;
769
810
  walker.pointer++;
770
811
  }
771
812
  else {
772
813
  validationError("Expected '//'.");
773
- state = ParserState.SpecialAuthorityIgnoreSlashes;
814
+ state = interfaces_1.ParserState.SpecialAuthorityIgnoreSlashes;
774
815
  walker.pointer--;
775
816
  }
776
817
  break;
777
- case ParserState.SpecialAuthorityIgnoreSlashes:
818
+ case interfaces_1.ParserState.SpecialAuthorityIgnoreSlashes:
778
819
  /**
779
820
  * If c is neither U+002F (/) nor U+005C (\), then set state to
780
821
  * authority state and decrease pointer by one.
781
822
  * Otherwise, validation error.
782
823
  */
783
824
  if (walker.c() !== '/' && walker.c() !== '\\') {
784
- state = ParserState.Authority;
825
+ state = interfaces_1.ParserState.Authority;
785
826
  walker.pointer--;
786
827
  }
787
828
  else {
788
829
  validationError("Unexpected '/' or '\\'.");
789
830
  }
790
831
  break;
791
- case ParserState.Authority:
832
+ case interfaces_1.ParserState.Authority:
792
833
  /**
793
834
  * 1. If c is U+0040 (@), then:
794
835
  */
@@ -848,7 +889,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
848
889
  }
849
890
  walker.pointer -= (buffer.length + 1);
850
891
  buffer = "";
851
- state = ParserState.Host;
892
+ state = interfaces_1.ParserState.Host;
852
893
  }
853
894
  else {
854
895
  /**
@@ -857,15 +898,15 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
857
898
  buffer += walker.c();
858
899
  }
859
900
  break;
860
- case ParserState.Host:
861
- case ParserState.Hostname:
901
+ case interfaces_1.ParserState.Host:
902
+ case interfaces_1.ParserState.Hostname:
862
903
  if (stateOverride !== undefined && url.scheme === "file") {
863
904
  /**
864
905
  * 1. If state override is given and url’s scheme is "file", then
865
906
  * decrease pointer by one and set state to file host state.
866
907
  */
867
908
  walker.pointer--;
868
- state = ParserState.FileHost;
909
+ state = interfaces_1.ParserState.FileHost;
869
910
  }
870
911
  else if (walker.c() === ':' && !arrayFlag) {
871
912
  /**
@@ -889,8 +930,8 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
889
930
  return null;
890
931
  url.host = host;
891
932
  buffer = "";
892
- state = ParserState.Port;
893
- if (stateOverride === ParserState.Hostname)
933
+ state = interfaces_1.ParserState.Port;
934
+ if (stateOverride === interfaces_1.ParserState.Hostname)
894
935
  return url;
895
936
  }
896
937
  else if (walker.c() === EOF || walker.c() === '/' || walker.c() === '?' || walker.c() === '#' ||
@@ -927,7 +968,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
927
968
  return null;
928
969
  url.host = host;
929
970
  buffer = "";
930
- state = ParserState.PathStart;
971
+ state = interfaces_1.ParserState.PathStart;
931
972
  if (stateOverride !== undefined)
932
973
  return url;
933
974
  }
@@ -945,8 +986,8 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
945
986
  buffer += walker.c();
946
987
  }
947
988
  break;
948
- case ParserState.Port:
949
- if (infraCodePoint.ASCIIDigit.test(walker.c())) {
989
+ case interfaces_1.ParserState.Port:
990
+ if (infra_1.codePoint.ASCIIDigit.test(walker.c())) {
950
991
  /**
951
992
  * 1. If c is an ASCII digit, append c to buffer.
952
993
  */
@@ -990,7 +1031,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
990
1031
  if (stateOverride !== undefined) {
991
1032
  return url;
992
1033
  }
993
- state = ParserState.PathStart;
1034
+ state = interfaces_1.ParserState.PathStart;
994
1035
  walker.pointer--;
995
1036
  }
996
1037
  else {
@@ -1001,7 +1042,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1001
1042
  return null;
1002
1043
  }
1003
1044
  break;
1004
- case ParserState.File:
1045
+ case interfaces_1.ParserState.File:
1005
1046
  /**
1006
1047
  * 1. Set url’s scheme to "file".
1007
1048
  */
@@ -1015,7 +1056,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1015
1056
  if (walker.c() === '\\') {
1016
1057
  validationError("Invalid input string.");
1017
1058
  }
1018
- state = ParserState.FileSlash;
1059
+ state = interfaces_1.ParserState.FileSlash;
1019
1060
  }
1020
1061
  else if (baseURL !== null && baseURL.scheme === "file") {
1021
1062
  /**
@@ -1029,7 +1070,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1029
1070
  * path, and url’s query to base’s query.
1030
1071
  */
1031
1072
  url.host = baseURL.host;
1032
- url.path = infraList.clone(baseURL.path);
1073
+ url.path = infra_1.list.clone(baseURL.path);
1033
1074
  url.query = baseURL.query;
1034
1075
  break;
1035
1076
  case '?':
@@ -1039,9 +1080,9 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1039
1080
  * state.
1040
1081
  */
1041
1082
  url.host = baseURL.host;
1042
- url.path = infraList.clone(baseURL.path);
1083
+ url.path = infra_1.list.clone(baseURL.path);
1043
1084
  url.query = "";
1044
- state = ParserState.Query;
1085
+ state = interfaces_1.ParserState.Query;
1045
1086
  break;
1046
1087
  case '#':
1047
1088
  /**
@@ -1050,10 +1091,10 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1050
1091
  * empty string, and state to fragment state.
1051
1092
  */
1052
1093
  url.host = baseURL.host;
1053
- url.path = infraList.clone(baseURL.path);
1094
+ url.path = infra_1.list.clone(baseURL.path);
1054
1095
  url.query = baseURL.query;
1055
1096
  url.fragment = "";
1056
- state = ParserState.Fragment;
1097
+ state = interfaces_1.ParserState.Fragment;
1057
1098
  break;
1058
1099
  default:
1059
1100
  /**
@@ -1068,13 +1109,13 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1068
1109
  */
1069
1110
  if (!startsWithAWindowsDriveLetter(walker.substring())) {
1070
1111
  url.host = baseURL.host;
1071
- url.path = infraList.clone(baseURL.path);
1112
+ url.path = infra_1.list.clone(baseURL.path);
1072
1113
  shorten(url);
1073
1114
  }
1074
1115
  else {
1075
1116
  validationError("Unexpected windows drive letter in input string.");
1076
1117
  }
1077
- state = ParserState.Path;
1118
+ state = interfaces_1.ParserState.Path;
1078
1119
  walker.pointer--;
1079
1120
  break;
1080
1121
  }
@@ -1084,11 +1125,11 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1084
1125
  * 4. Otherwise, set state to path state, and decrease pointer by
1085
1126
  * one.
1086
1127
  */
1087
- state = ParserState.Path;
1128
+ state = interfaces_1.ParserState.Path;
1088
1129
  walker.pointer--;
1089
1130
  }
1090
1131
  break;
1091
- case ParserState.FileSlash:
1132
+ case interfaces_1.ParserState.FileSlash:
1092
1133
  if (walker.c() === '/' || walker.c() === '\\') {
1093
1134
  /**
1094
1135
  * 1. If c is U+002F (/) or U+005C (\), then:
@@ -1098,7 +1139,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1098
1139
  if (walker.c() === '\\') {
1099
1140
  validationError("Invalid input string.");
1100
1141
  }
1101
- state = ParserState.FileHost;
1142
+ state = interfaces_1.ParserState.FileHost;
1102
1143
  }
1103
1144
  else {
1104
1145
  /**
@@ -1123,11 +1164,11 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1123
1164
  url.host = baseURL.host;
1124
1165
  }
1125
1166
  }
1126
- state = ParserState.Path;
1167
+ state = interfaces_1.ParserState.Path;
1127
1168
  walker.pointer--;
1128
1169
  }
1129
1170
  break;
1130
- case ParserState.FileHost:
1171
+ case interfaces_1.ParserState.FileHost:
1131
1172
  if (walker.c() === EOF || walker.c() === '/' || walker.c() === '\\' ||
1132
1173
  walker.c() === '?' || walker.c() === '#') {
1133
1174
  /**
@@ -1143,7 +1184,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1143
1184
  * quirk. buffer is not reset here and instead used in the path state.
1144
1185
  */
1145
1186
  validationError("Unexpected windows drive letter in input string.");
1146
- state = ParserState.Path;
1187
+ state = interfaces_1.ParserState.Path;
1147
1188
  }
1148
1189
  else if (buffer === "") {
1149
1190
  /**
@@ -1155,7 +1196,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1155
1196
  url.host = "";
1156
1197
  if (stateOverride !== undefined)
1157
1198
  return url;
1158
- state = ParserState.PathStart;
1199
+ state = interfaces_1.ParserState.PathStart;
1159
1200
  }
1160
1201
  else {
1161
1202
  /**
@@ -1179,7 +1220,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1179
1220
  if (stateOverride !== undefined)
1180
1221
  return url;
1181
1222
  buffer = "";
1182
- state = ParserState.PathStart;
1223
+ state = interfaces_1.ParserState.PathStart;
1183
1224
  }
1184
1225
  }
1185
1226
  else {
@@ -1189,7 +1230,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1189
1230
  buffer += walker.c();
1190
1231
  }
1191
1232
  break;
1192
- case ParserState.PathStart:
1233
+ case interfaces_1.ParserState.PathStart:
1193
1234
  if (isSpecial(url)) {
1194
1235
  /**
1195
1236
  * 1. If url is special, then:
@@ -1201,7 +1242,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1201
1242
  if (walker.c() === '\\') {
1202
1243
  validationError("Invalid input string.");
1203
1244
  }
1204
- state = ParserState.Path;
1245
+ state = interfaces_1.ParserState.Path;
1205
1246
  if (walker.c() !== '/' && walker.c() !== '\\')
1206
1247
  walker.pointer--;
1207
1248
  }
@@ -1211,7 +1252,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1211
1252
  * set url’s query to the empty string and state to query state.
1212
1253
  */
1213
1254
  url.query = "";
1214
- state = ParserState.Query;
1255
+ state = interfaces_1.ParserState.Query;
1215
1256
  }
1216
1257
  else if (stateOverride === undefined && walker.c() === '#') {
1217
1258
  /**
@@ -1220,7 +1261,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1220
1261
  * state.
1221
1262
  */
1222
1263
  url.fragment = "";
1223
- state = ParserState.Fragment;
1264
+ state = interfaces_1.ParserState.Fragment;
1224
1265
  }
1225
1266
  else if (walker.c() !== EOF) {
1226
1267
  /**
@@ -1228,12 +1269,12 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1228
1269
  * 4.1. Set state to path state.
1229
1270
  * 4.2. If c is not U+002F (/), then decrease pointer by one.
1230
1271
  */
1231
- state = ParserState.Path;
1272
+ state = interfaces_1.ParserState.Path;
1232
1273
  if (walker.c() !== '/')
1233
1274
  walker.pointer--;
1234
1275
  }
1235
1276
  break;
1236
- case ParserState.Path:
1277
+ case interfaces_1.ParserState.Path:
1237
1278
  if ((walker.c() === EOF || walker.c() === '/') ||
1238
1279
  (isSpecial(url) && walker.c() === '\\') ||
1239
1280
  (stateOverride === undefined && (walker.c() === '?' || walker.c() === '#'))) {
@@ -1320,11 +1361,11 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1320
1361
  */
1321
1362
  if (walker.c() === '?') {
1322
1363
  url.query = "";
1323
- state = ParserState.Query;
1364
+ state = interfaces_1.ParserState.Query;
1324
1365
  }
1325
1366
  if (walker.c() === '#') {
1326
1367
  url.fragment = "";
1327
- state = ParserState.Fragment;
1368
+ state = interfaces_1.ParserState.Fragment;
1328
1369
  }
1329
1370
  }
1330
1371
  else {
@@ -1346,7 +1387,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1346
1387
  buffer += utf8PercentEncode(walker.c(), _pathPercentEncodeSet);
1347
1388
  }
1348
1389
  break;
1349
- case ParserState.CannotBeABaseURLPath:
1390
+ case interfaces_1.ParserState.CannotBeABaseURLPath:
1350
1391
  /**
1351
1392
  * 1. If c is U+003F (?), then set url’s query to the empty string and
1352
1393
  * state to query state.
@@ -1363,11 +1404,11 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1363
1404
  */
1364
1405
  if (walker.c() === '?') {
1365
1406
  url.query = "";
1366
- state = ParserState.Query;
1407
+ state = interfaces_1.ParserState.Query;
1367
1408
  }
1368
1409
  else if (walker.c() === '#') {
1369
1410
  url.fragment = "";
1370
- state = ParserState.Fragment;
1411
+ state = interfaces_1.ParserState.Fragment;
1371
1412
  }
1372
1413
  else {
1373
1414
  if (walker.c() !== EOF && !_urlCodePoints.test(walker.c()) && walker.c() !== '%') {
@@ -1381,7 +1422,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1381
1422
  }
1382
1423
  }
1383
1424
  break;
1384
- case ParserState.Query:
1425
+ case interfaces_1.ParserState.Query:
1385
1426
  /**
1386
1427
  * 1. If encoding is not UTF-8 and one of the following is true
1387
1428
  * - url is not special
@@ -1398,7 +1439,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1398
1439
  * url’s fragment to the empty string and state to fragment state.
1399
1440
  */
1400
1441
  url.fragment = "";
1401
- state = ParserState.Fragment;
1442
+ state = interfaces_1.ParserState.Fragment;
1402
1443
  }
1403
1444
  else if (walker.c() !== EOF) {
1404
1445
  /**
@@ -1422,7 +1463,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1422
1463
  if (encoding.toUpperCase() !== "UTF-8") {
1423
1464
  throw new Error("Only UTF-8 encoding is supported.");
1424
1465
  }
1425
- let bytes = utf8Encode(walker.c());
1466
+ let bytes = (0, util_1.utf8Encode)(walker.c());
1426
1467
  /**
1427
1468
  * 3.4. If bytes starts with `&#` and ends with 0x3B (;), then:
1428
1469
  */
@@ -1436,7 +1477,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1436
1477
  * non-UTF-8 encoding.
1437
1478
  */
1438
1479
  bytes = bytes.subarray(2, bytes.length - 1);
1439
- url.query += "%26%23" + infraByteSequence.isomorphicDecode(bytes) + "%3B";
1480
+ url.query += "%26%23" + infra_1.byteSequence.isomorphicDecode(bytes) + "%3B";
1440
1481
  }
1441
1482
  else {
1442
1483
  /**
@@ -1463,7 +1504,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1463
1504
  }
1464
1505
  }
1465
1506
  break;
1466
- case ParserState.Fragment:
1507
+ case interfaces_1.ParserState.Fragment:
1467
1508
  /**
1468
1509
  * Switching on c:
1469
1510
  * - The EOF code point
@@ -1511,7 +1552,7 @@ export function basicURLParser(input, baseURL, encodingOverride, url, stateOverr
1511
1552
  * @param url - a URL
1512
1553
  * @param username - username string
1513
1554
  */
1514
- export function setTheUsername(url, username) {
1555
+ function setTheUsername(url, username) {
1515
1556
  /**
1516
1557
  * 1. Set url’s username to the empty string.
1517
1558
  * 2. For each code point in username, UTF-8 percent encode it using the
@@ -1529,7 +1570,7 @@ export function setTheUsername(url, username) {
1529
1570
  * @param url - a URL
1530
1571
  * @param username - password string
1531
1572
  */
1532
- export function setThePassword(url, password) {
1573
+ function setThePassword(url, password) {
1533
1574
  /**
1534
1575
  * 1. Set url’s password to the empty string.
1535
1576
  * 2. For each code point in password, UTF-8 percent encode it using the
@@ -1546,7 +1587,7 @@ export function setThePassword(url, password) {
1546
1587
  *
1547
1588
  * @param str - a string
1548
1589
  */
1549
- export function isSingleDotPathSegment(str) {
1590
+ function isSingleDotPathSegment(str) {
1550
1591
  return str === '.' || str.toLowerCase() === "%2e";
1551
1592
  }
1552
1593
  /**
@@ -1554,7 +1595,7 @@ export function isSingleDotPathSegment(str) {
1554
1595
  *
1555
1596
  * @param str - a string
1556
1597
  */
1557
- export function isDoubleDotPathSegment(str) {
1598
+ function isDoubleDotPathSegment(str) {
1558
1599
  const lowerStr = str.toLowerCase();
1559
1600
  return lowerStr === ".." || lowerStr === ".%2e" ||
1560
1601
  lowerStr === "%2e." || lowerStr === "%2e%2e";
@@ -1564,7 +1605,7 @@ export function isDoubleDotPathSegment(str) {
1564
1605
  *
1565
1606
  * @param url - an URL
1566
1607
  */
1567
- export function shorten(url) {
1608
+ function shorten(url) {
1568
1609
  /**
1569
1610
  * 1. Let path be url’s path.
1570
1611
  * 2. If path is empty, then return.
@@ -1585,12 +1626,12 @@ export function shorten(url) {
1585
1626
  *
1586
1627
  * @param str - a string
1587
1628
  */
1588
- export function isNormalizedWindowsDriveLetter(str) {
1629
+ function isNormalizedWindowsDriveLetter(str) {
1589
1630
  /**
1590
1631
  * A normalized Windows drive letter is a Windows drive letter of which the
1591
1632
  * second code point is U+003A (:).
1592
1633
  */
1593
- return str.length >= 2 && infraCodePoint.ASCIIAlpha.test(str[0]) &&
1634
+ return str.length >= 2 && infra_1.codePoint.ASCIIAlpha.test(str[0]) &&
1594
1635
  str[1] === ':';
1595
1636
  }
1596
1637
  /**
@@ -1598,12 +1639,12 @@ export function isNormalizedWindowsDriveLetter(str) {
1598
1639
  *
1599
1640
  * @param str - a string
1600
1641
  */
1601
- export function isWindowsDriveLetter(str) {
1642
+ function isWindowsDriveLetter(str) {
1602
1643
  /**
1603
1644
  * A Windows drive letter is two code points, of which the first is an ASCII
1604
1645
  * alpha and the second is either U+003A (:) or U+007C (|).
1605
1646
  */
1606
- return str.length >= 2 && infraCodePoint.ASCIIAlpha.test(str[0]) &&
1647
+ return str.length >= 2 && infra_1.codePoint.ASCIIAlpha.test(str[0]) &&
1607
1648
  (str[1] === ':' || str[1] === '|');
1608
1649
  }
1609
1650
  /**
@@ -1611,7 +1652,7 @@ export function isWindowsDriveLetter(str) {
1611
1652
  *
1612
1653
  * @param str - a string
1613
1654
  */
1614
- export function startsWithAWindowsDriveLetter(str) {
1655
+ function startsWithAWindowsDriveLetter(str) {
1615
1656
  /**
1616
1657
  * A string starts with a Windows drive letter if all of the following are
1617
1658
  * true:
@@ -1631,7 +1672,7 @@ export function startsWithAWindowsDriveLetter(str) {
1631
1672
  * @param isNotSpecial - `true` if the source URL is not special; otherwise
1632
1673
  * `false`.
1633
1674
  */
1634
- export function hostParser(input, isNotSpecial = false) {
1675
+ function hostParser(input, isNotSpecial = false) {
1635
1676
  /**
1636
1677
  * 1. If isNotSpecial is not given, then set isNotSpecial to false.
1637
1678
  * 2. If input starts with U+005B ([), then:
@@ -1661,7 +1702,7 @@ export function hostParser(input, isNotSpecial = false) {
1661
1702
  * coupled with an early return for failure, as domain to ASCII fails
1662
1703
  * on U+FFFD REPLACEMENT CHARACTER.
1663
1704
  */
1664
- const domain = utf8Decode(stringPercentDecode(input));
1705
+ const domain = (0, util_1.utf8Decode)(stringPercentDecode(input));
1665
1706
  /**
1666
1707
  * 5. Let asciiDomain be the result of running domain to ASCII on domain.
1667
1708
  * 6. If asciiDomain is failure, validation error, return failure.
@@ -1683,7 +1724,7 @@ export function hostParser(input, isNotSpecial = false) {
1683
1724
  * 10. Return asciiDomain.
1684
1725
  */
1685
1726
  const ipv4Host = iPv4Parser(asciiDomain);
1686
- if (ipv4Host === null || isNumber(ipv4Host))
1727
+ if (ipv4Host === null || (0, util_1.isNumber)(ipv4Host))
1687
1728
  return ipv4Host;
1688
1729
  return asciiDomain;
1689
1730
  }
@@ -1694,7 +1735,7 @@ export function hostParser(input, isNotSpecial = false) {
1694
1735
  * @param isNotSpecial - `true` if the source URL is not special; otherwise
1695
1736
  * `false`.
1696
1737
  */
1697
- export function iPv4NumberParser(input, validationErrorFlag = { value: false }) {
1738
+ function iPv4NumberParser(input, validationErrorFlag = { value: false }) {
1698
1739
  /**
1699
1740
  * 1. Let R be 10.
1700
1741
  */
@@ -1745,7 +1786,7 @@ export function iPv4NumberParser(input, validationErrorFlag = { value: false })
1745
1786
  *
1746
1787
  * @param input - input string
1747
1788
  */
1748
- export function iPv4Parser(input) {
1789
+ function iPv4Parser(input) {
1749
1790
  /**
1750
1791
  * 1. Let validationErrorFlag be unset.
1751
1792
  * 2. Let parts be input split on U+002E (.).
@@ -1834,7 +1875,7 @@ export function iPv4Parser(input) {
1834
1875
  *
1835
1876
  * @param input - input string
1836
1877
  */
1837
- export function iPv6Parser(input) {
1878
+ function iPv6Parser(input) {
1838
1879
  /**
1839
1880
  * 1. Let address be a new IPv6 address whose IPv6 pieces are all 0.
1840
1881
  * 2. Let pieceIndex be 0.
@@ -1846,7 +1887,7 @@ export function iPv6Parser(input) {
1846
1887
  const address = [0, 0, 0, 0, 0, 0, 0, 0];
1847
1888
  let pieceIndex = 0;
1848
1889
  let compress = null;
1849
- const walker = new StringWalker(input);
1890
+ const walker = new util_1.StringWalker(input);
1850
1891
  /**
1851
1892
  * 5. If c is U+003A (:), then:
1852
1893
  * 5.1. If remaining does not start with U+003A (:), validation error,
@@ -1898,7 +1939,7 @@ export function iPv6Parser(input) {
1898
1939
  */
1899
1940
  let value = 0;
1900
1941
  let length = 0;
1901
- while (length < 4 && infraCodePoint.ASCIIHexDigit.test(walker.c())) {
1942
+ while (length < 4 && infra_1.codePoint.ASCIIHexDigit.test(walker.c())) {
1902
1943
  value = value * 0x10 + parseInt(walker.c(), 16);
1903
1944
  walker.pointer++;
1904
1945
  length++;
@@ -1951,14 +1992,14 @@ export function iPv6Parser(input) {
1951
1992
  * 6.5.5.3. If c is not an ASCII digit, validation error, return
1952
1993
  * failure.
1953
1994
  */
1954
- if (!infraCodePoint.ASCIIDigit.test(walker.c())) {
1995
+ if (!infra_1.codePoint.ASCIIDigit.test(walker.c())) {
1955
1996
  validationError("Invalid IP v6 address.");
1956
1997
  return null;
1957
1998
  }
1958
1999
  /**
1959
2000
  * 6.5.5.4. While c is an ASCII digit:
1960
2001
  */
1961
- while (infraCodePoint.ASCIIDigit.test(walker.c())) {
2002
+ while (infra_1.codePoint.ASCIIDigit.test(walker.c())) {
1962
2003
  /**
1963
2004
  * 6.5.5.4.1. Let number be c interpreted as decimal number.
1964
2005
  */
@@ -2077,7 +2118,7 @@ export function iPv6Parser(input) {
2077
2118
  *
2078
2119
  * @param input - a string
2079
2120
  */
2080
- export function opaqueHostParser(input) {
2121
+ function opaqueHostParser(input) {
2081
2122
  /**
2082
2123
  * 1. If input contains a forbidden host code point excluding U+0025 (%),
2083
2124
  * validation error, return failure.
@@ -2104,7 +2145,7 @@ export function opaqueHostParser(input) {
2104
2145
  *
2105
2146
  * @param url - an url
2106
2147
  */
2107
- export function resolveABlobURL(url) {
2148
+ function resolveABlobURL(url) {
2108
2149
  return null;
2109
2150
  }
2110
2151
  /**
@@ -2112,7 +2153,7 @@ export function resolveABlobURL(url) {
2112
2153
  *
2113
2154
  * @param value - a byte
2114
2155
  */
2115
- export function percentEncode(value) {
2156
+ function percentEncode(value) {
2116
2157
  /**
2117
2158
  * To percent encode a byte into a percent-encoded byte, return a string
2118
2159
  * consisting of U+0025 (%), followed by two ASCII upper hex digits
@@ -2125,7 +2166,7 @@ export function percentEncode(value) {
2125
2166
  *
2126
2167
  * @param input - a byte sequence
2127
2168
  */
2128
- export function percentDecode(input) {
2169
+ function percentDecode(input) {
2129
2170
  const isHexDigit = (byte) => {
2130
2171
  return (byte >= 0x30 && byte <= 0x39) || (byte >= 0x41 && byte <= 0x46) ||
2131
2172
  (byte >= 0x61 && byte <= 0x66);
@@ -2163,7 +2204,7 @@ export function percentDecode(input) {
2163
2204
  n++;
2164
2205
  }
2165
2206
  else {
2166
- const bytePoint = parseInt(utf8Decode(Uint8Array.of(input[i + 1], input[i + 2])), 16);
2207
+ const bytePoint = parseInt((0, util_1.utf8Decode)(Uint8Array.of(input[i + 1], input[i + 2])), 16);
2167
2208
  output[n] = bytePoint;
2168
2209
  n++;
2169
2210
  i += 2;
@@ -2176,12 +2217,12 @@ export function percentDecode(input) {
2176
2217
  *
2177
2218
  * @param input - a string
2178
2219
  */
2179
- export function stringPercentDecode(input) {
2220
+ function stringPercentDecode(input) {
2180
2221
  /**
2181
2222
  * 1. Let bytes be the UTF-8 encoding of input.
2182
2223
  * 2. Return the percent decoding of bytes.
2183
2224
  */
2184
- return percentDecode(utf8Encode(input));
2225
+ return percentDecode((0, util_1.utf8Encode)(input));
2185
2226
  }
2186
2227
  /**
2187
2228
  * UTF-8 percent encodes a code point, using a percent encode set.
@@ -2189,7 +2230,7 @@ export function stringPercentDecode(input) {
2189
2230
  * @param codePoint - a code point
2190
2231
  * @param percentEncodeSet - a percent encode set
2191
2232
  */
2192
- export function utf8PercentEncode(codePoint, percentEncodeSet) {
2233
+ function utf8PercentEncode(codePoint, percentEncodeSet) {
2193
2234
  /**
2194
2235
  * 1. If codePoint is not in percentEncodeSet, then return codePoint.
2195
2236
  * 2. Let bytes be the result of running UTF-8 encode on codePoint.
@@ -2198,7 +2239,7 @@ export function utf8PercentEncode(codePoint, percentEncodeSet) {
2198
2239
  */
2199
2240
  if (!percentEncodeSet.test(codePoint))
2200
2241
  return codePoint;
2201
- const bytes = utf8Encode(codePoint);
2242
+ const bytes = (0, util_1.utf8Encode)(codePoint);
2202
2243
  let result = "";
2203
2244
  for (const byte of bytes) {
2204
2245
  result += percentEncode(byte);
@@ -2211,7 +2252,7 @@ export function utf8PercentEncode(codePoint, percentEncodeSet) {
2211
2252
  * @param hostA - a host
2212
2253
  * @param hostB - a host
2213
2254
  */
2214
- export function hostEquals(hostA, hostB) {
2255
+ function hostEquals(hostA, hostB) {
2215
2256
  return hostA === hostB;
2216
2257
  }
2217
2258
  /**
@@ -2221,7 +2262,7 @@ export function hostEquals(hostA, hostB) {
2221
2262
  * @param urlB - a URL
2222
2263
  * @param excludeFragmentsFlag - whether to ignore fragments while comparing
2223
2264
  */
2224
- export function urlEquals(urlA, urlB, excludeFragmentsFlag = false) {
2265
+ function urlEquals(urlA, urlB, excludeFragmentsFlag = false) {
2225
2266
  /**
2226
2267
  * 1. Let serializedA be the result of serializing A, with the exclude
2227
2268
  * fragment flag set if the exclude fragments flag is set.
@@ -2237,20 +2278,20 @@ export function urlEquals(urlA, urlB, excludeFragmentsFlag = false) {
2237
2278
  *
2238
2279
  * @param input - a string
2239
2280
  */
2240
- export function urlEncodedStringParser(input) {
2281
+ function urlEncodedStringParser(input) {
2241
2282
  /**
2242
2283
  * The application/x-www-form-urlencoded string parser takes a string input,
2243
2284
  * UTF-8 encodes it, and then returns the result of
2244
2285
  * application/x-www-form-urlencoded parsing it.
2245
2286
  */
2246
- return urlEncodedParser(utf8Encode(input));
2287
+ return urlEncodedParser((0, util_1.utf8Encode)(input));
2247
2288
  }
2248
2289
  /**
2249
2290
  * Parses `application/x-www-form-urlencoded` bytes.
2250
2291
  *
2251
2292
  * @param input - a byte sequence
2252
2293
  */
2253
- export function urlEncodedParser(input) {
2294
+ function urlEncodedParser(input) {
2254
2295
  /**
2255
2296
  * 1. Let sequences be the result of splitting input on 0x26 (&).
2256
2297
  */
@@ -2307,8 +2348,8 @@ export function urlEncodedParser(input) {
2307
2348
  * decode without BOM on the percent decoding of name and value,
2308
2349
  * respectively.
2309
2350
  */
2310
- const nameString = utf8Decode(name);
2311
- const valueString = utf8Decode(value);
2351
+ const nameString = (0, util_1.utf8Decode)(name);
2352
+ const valueString = (0, util_1.utf8Decode)(value);
2312
2353
  /**
2313
2354
  * 3.6. Append (nameString, valueString) to output.
2314
2355
  */
@@ -2324,7 +2365,7 @@ export function urlEncodedParser(input) {
2324
2365
  *
2325
2366
  * @param input - a byte sequence
2326
2367
  */
2327
- export function urlEncodedByteSerializer(input) {
2368
+ function urlEncodedByteSerializer(input) {
2328
2369
  /**
2329
2370
  * 1. Let output be the empty string.
2330
2371
  * 2. For each byte in input, depending on byte:
@@ -2366,7 +2407,7 @@ export function urlEncodedByteSerializer(input) {
2366
2407
  * @param input - input tuple of name/value pairs
2367
2408
  * @param encodingOverride: encoding override
2368
2409
  */
2369
- export function urlEncodedSerializer(tuples, encodingOverride) {
2410
+ function urlEncodedSerializer(tuples, encodingOverride) {
2370
2411
  /**
2371
2412
  * 1. Let encoding be UTF-8.
2372
2413
  * 2. If encoding override is given, set encoding to the result of getting
@@ -2390,7 +2431,7 @@ export function urlEncodedSerializer(tuples, encodingOverride) {
2390
2431
  * 4.1. Let name be the result of serializing the result of encoding
2391
2432
  * tuple’s name, using encoding.
2392
2433
  */
2393
- const name = urlEncodedByteSerializer(utf8Encode(tuple[0]));
2434
+ const name = urlEncodedByteSerializer((0, util_1.utf8Encode)(tuple[0]));
2394
2435
  /**
2395
2436
  * 4.2. Let value be tuple’s value.
2396
2437
  */
@@ -2403,7 +2444,7 @@ export function urlEncodedSerializer(tuples, encodingOverride) {
2403
2444
  * 4.4. Set value to the result of serializing the result of encoding
2404
2445
  * value, using encoding.
2405
2446
  */
2406
- value = urlEncodedByteSerializer(utf8Encode(value));
2447
+ value = urlEncodedByteSerializer((0, util_1.utf8Encode)(value));
2407
2448
  /**
2408
2449
  * 4.5. If tuple is not the first pair in tuples, then append U+0026 (&)
2409
2450
  * to output.
@@ -2425,7 +2466,7 @@ export function urlEncodedSerializer(tuples, encodingOverride) {
2425
2466
  *
2426
2467
  * @param url - a URL
2427
2468
  */
2428
- export function origin(url) {
2469
+ function origin(url) {
2429
2470
  /**
2430
2471
  * A URL’s origin is the origin returned by running these steps, switching
2431
2472
  * on URL’s scheme:
@@ -2455,7 +2496,7 @@ export function origin(url) {
2455
2496
  }
2456
2497
  const parsedURL = basicURLParser(url.path[0]);
2457
2498
  if (parsedURL === null)
2458
- return OpaqueOrigin;
2499
+ return interfaces_1.OpaqueOrigin;
2459
2500
  else
2460
2501
  return origin(parsedURL);
2461
2502
  case "ftp":
@@ -2465,9 +2506,9 @@ export function origin(url) {
2465
2506
  case "wss":
2466
2507
  return [url.scheme, url.host === null ? "" : url.host, url.port, null];
2467
2508
  case "file":
2468
- return OpaqueOrigin;
2509
+ return interfaces_1.OpaqueOrigin;
2469
2510
  default:
2470
- return OpaqueOrigin;
2511
+ return interfaces_1.OpaqueOrigin;
2471
2512
  }
2472
2513
  }
2473
2514
  /**
@@ -2475,7 +2516,7 @@ export function origin(url) {
2475
2516
  *
2476
2517
  * @param domain - a domain string
2477
2518
  */
2478
- export function domainToASCII(domain, beStrict = false) {
2519
+ function domainToASCII(domain, beStrict = false) {
2479
2520
  /**
2480
2521
  * 1. If beStrict is not given, set it to false.
2481
2522
  * 2. Let result be the result of running Unicode ToASCII with domain_name
@@ -2485,32 +2526,24 @@ export function domainToASCII(domain, beStrict = false) {
2485
2526
  * 3. If result is a failure value, validation error, return failure.
2486
2527
  * 4. Return result.
2487
2528
  */
2488
- // Use node.js function
2489
- const result = nodeDomainToASCII(domain);
2490
- if (result === "") {
2491
- validationError("Invalid domain name.");
2492
- return null;
2529
+ // Use the platform URL parser
2530
+ let result = "";
2531
+ try {
2532
+ // characters that would be read as URL syntax rather than part of a host
2533
+ if (!/[\u0000- #%/:<>?@[\\\]^|\u007f]/.test(domain)) {
2534
+ const parsed = new globalThis.URL("ws://" + domain);
2535
+ if (parsed.port === "" && parsed.pathname === "/" && parsed.search === "" &&
2536
+ parsed.hash === "" && parsed.username === "" && parsed.password === "") {
2537
+ result = parsed.hostname;
2538
+ }
2539
+ }
2540
+ }
2541
+ catch {
2542
+ result = "";
2493
2543
  }
2494
- return result;
2495
- }
2496
- /**
2497
- * Converts a domain string to Unicode.
2498
- *
2499
- * @param domain - a domain string
2500
- */
2501
- export function domainToUnicode(domain, beStrict = false) {
2502
- /**
2503
- * 1. Let result be the result of running Unicode ToUnicode with domain_name
2504
- * set to domain, CheckHyphens set to false, CheckBidi set to true,
2505
- * CheckJoiners set to true, UseSTD3ASCIIRules set to false, and
2506
- * Transitional_Processing set to false.
2507
- * 2. Signify validation errors for any returned errors, and then,
2508
- * return result.
2509
- */
2510
- // Use node.js function
2511
- const result = nodeDomainToUnicode(domain);
2512
2544
  if (result === "") {
2513
2545
  validationError("Invalid domain name.");
2546
+ return null;
2514
2547
  }
2515
2548
  return result;
2516
2549
  }
@@ -2521,7 +2554,7 @@ export function domainToUnicode(domain, beStrict = false) {
2521
2554
  *
2522
2555
  * @param origin - an origin
2523
2556
  */
2524
- export function asciiSerializationOfAnOrigin(origin) {
2557
+ function asciiSerializationOfAnOrigin(origin) {
2525
2558
  /**
2526
2559
  * 1. If origin is an opaque origin, then return "null".
2527
2560
  * 2. Otherwise, let result be origin's scheme.