@oozcitak/url 0.0.10 → 1.0.4

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,14 +1,41 @@
1
1
  "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
2
29
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const util_1 = require("@oozcitak/util");
4
- const interfaces_1 = require("./interfaces");
5
- const infra_1 = require("@oozcitak/infra");
6
- const uts46_1 = require("@oozcitak/uts46");
7
- let _validationErrorCallback;
30
+ var util_1 = require("@oozcitak/util");
31
+ var interfaces_1 = require("./interfaces");
32
+ var infra_1 = require("@oozcitak/infra");
33
+ var url_1 = require("url");
34
+ var _validationErrorCallback;
8
35
  /**
9
36
  * Default ports for a special URL scheme.
10
37
  */
11
- const _defaultPorts = {
38
+ var _defaultPorts = {
12
39
  "ftp": 21,
13
40
  "file": null,
14
41
  "http": 80,
@@ -20,23 +47,23 @@ const _defaultPorts = {
20
47
  * The C0 control percent-encode set are the C0 controls and all code points
21
48
  * greater than U+007E (~).
22
49
  */
23
- const _c0ControlPercentEncodeSet = /[\0-\x1F\x7F-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
50
+ var _c0ControlPercentEncodeSet = /[\0-\x1F\x7F-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
24
51
  /**
25
52
  * The fragment percent-encode set is the C0 control percent-encode set and
26
53
  * U+0020 SPACE, U+0022 ("), U+003C (<), U+003E (>), and U+0060 (`).
27
54
  */
28
- const _fragmentPercentEncodeSet = /[ "<>`]|[\0-\x1F\x7F-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
55
+ var _fragmentPercentEncodeSet = /[ "<>`]|[\0-\x1F\x7F-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
29
56
  /**
30
57
  * The path percent-encode set is the fragment percent-encode set and
31
58
  * U+0023 (#), U+003F (?), U+007B ({), and U+007D (}).
32
59
  */
33
- const _pathPercentEncodeSet = /[ "<>`#?{}]|[\0-\x1F\x7F-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
60
+ var _pathPercentEncodeSet = /[ "<>`#?{}]|[\0-\x1F\x7F-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
34
61
  /**
35
62
  * The userinfo percent-encode set is the path percent-encode set and
36
63
  * U+002F (/), U+003A (:), U+003B (;), U+003D (=), U+0040 (@), U+005B ([),
37
64
  * U+005C (\), U+005D (]), U+005E (^), and U+007C (|).
38
65
  */
39
- const _userInfoPercentEncodeSet = /[ "<>`#?{}/:;=@\[\]\\\^\|]|[\0-\x1F\x7F-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
66
+ var _userInfoPercentEncodeSet = /[ "<>`#?{}/:;=@\[\]\\\^\|]|[\0-\x1F\x7F-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
40
67
  /**
41
68
  * The URL code points are ASCII alphanumeric, U+0021 (!), U+0024 ($),
42
69
  * U+0026 (&), U+0027 ('), U+0028 LEFT PARENTHESIS, U+0029 RIGHT PARENTHESIS,
@@ -45,13 +72,13 @@ const _userInfoPercentEncodeSet = /[ "<>`#?{}/:;=@\[\]\\\^\|]|[\0-\x1F\x7F-\uD7F
45
72
  * U+007E (~), and code points in the range U+00A0 to U+10FFFD, inclusive,
46
73
  * excluding surrogates and noncharacters.
47
74
  */
48
- const _urlCodePoints = /[0-9A-Za-z!\$&-\/:;=\?@_~\xA0-\uD7FF\uE000-\uFDCF\uFDF0-\uFFFD]|[\uD800-\uD83E\uD840-\uD87E\uD880-\uD8BE\uD8C0-\uD8FE\uD900-\uD93E\uD940-\uD97E\uD980-\uD9BE\uD9C0-\uD9FE\uDA00-\uDA3E\uDA40-\uDA7E\uDA80-\uDABE\uDAC0-\uDAFE\uDB00-\uDB3E\uDB40-\uDB7E\uDB80-\uDBBE\uDBC0-\uDBFE][\uDC00-\uDFFF]|[\uD83F\uD87F\uD8BF\uD8FF\uD93F\uD97F\uD9BF\uD9FF\uDA3F\uDA7F\uDABF\uDAFF\uDB3F\uDB7F\uDBBF\uDBFF][\uDC00-\uDFFD]/;
75
+ var _urlCodePoints = /[0-9A-Za-z!\$&-\/:;=\?@_~\xA0-\uD7FF\uE000-\uFDCF\uFDF0-\uFFFD]|[\uD800-\uD83E\uD840-\uD87E\uD880-\uD8BE\uD8C0-\uD8FE\uD900-\uD93E\uD940-\uD97E\uD980-\uD9BE\uD9C0-\uD9FE\uDA00-\uDA3E\uDA40-\uDA7E\uDA80-\uDABE\uDAC0-\uDAFE\uDB00-\uDB3E\uDB40-\uDB7E\uDB80-\uDBBE\uDBC0-\uDBFE][\uDC00-\uDFFF]|[\uD83F\uD87F\uD8BF\uD8FF\uD93F\uD97F\uD9BF\uD9FF\uDA3F\uDA7F\uDABF\uDAFF\uDB3F\uDB7F\uDBBF\uDBFF][\uDC00-\uDFFD]/;
49
76
  /**
50
77
  * A forbidden host code point is U+0000 NULL, U+0009 TAB, U+000A LF,
51
78
  * U+000D CR, U+0020 SPACE, U+0023 (#), U+0025 (%), U+002F (/), U+003A (:),
52
79
  * U+003F (?), U+0040 (@), U+005B ([), U+005C (\), or U+005D (]).
53
80
  */
54
- const _forbiddenHostCodePoint = /[\0\t\f\r #%/:?@\[\\\]]/;
81
+ var _forbiddenHostCodePoint = /[\0\t\f\r #%/:?@\[\\\]]/;
55
82
  /**
56
83
  * Sets the callback function for validation errors.
57
84
  *
@@ -146,11 +173,13 @@ exports.cannotHaveAUsernamePasswordPort = cannotHaveAUsernamePasswordPort;
146
173
  *
147
174
  * @param url - an URL
148
175
  */
149
- function urlSerializer(url, excludeFragmentFlag = false) {
176
+ function urlSerializer(url, excludeFragmentFlag) {
177
+ var e_1, _a;
178
+ if (excludeFragmentFlag === void 0) { excludeFragmentFlag = false; }
150
179
  /**
151
180
  * 1. Let output be url’s scheme and U+003A (:) concatenated.
152
181
  */
153
- let output = url.scheme + ':';
182
+ var output = url.scheme + ':';
154
183
  /**
155
184
  * 2. If url’s host is non-null:
156
185
  */
@@ -201,8 +230,18 @@ function urlSerializer(url, excludeFragmentFlag = false) {
201
230
  output += url.path[0];
202
231
  }
203
232
  else {
204
- for (const str of url.path) {
205
- output += '/' + str;
233
+ try {
234
+ for (var _b = __values(url.path), _c = _b.next(); !_c.done; _c = _b.next()) {
235
+ var str = _c.value;
236
+ output += '/' + str;
237
+ }
238
+ }
239
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
240
+ finally {
241
+ try {
242
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
243
+ }
244
+ finally { if (e_1) throw e_1.error; }
206
245
  }
207
246
  }
208
247
  /**
@@ -261,9 +300,9 @@ function iPv4Serializer(address) {
261
300
  * 3.3. Set n to floor(n / 256).
262
301
  * 4. Return output.
263
302
  */
264
- let output = "";
265
- let n = address;
266
- for (let i = 1; i <= 4; i++) {
303
+ var output = "";
304
+ var n = address;
305
+ for (var i = 1; i <= 4; i++) {
267
306
  output = (n % 256).toString() + output;
268
307
  if (i !== 4) {
269
308
  output = '.' + output;
@@ -287,16 +326,16 @@ function iPv6Serializer(address) {
287
326
  * 3. If there is no sequence of address’s IPv6 pieces that are 0 that is
288
327
  * longer than 1, then set compress to null.
289
328
  */
290
- let output = "";
291
- let compress = null;
292
- let lastIndex = -1;
293
- let count = 0;
294
- let lastCount = 0;
295
- for (let i = 0; i < 8; i++) {
329
+ var output = "";
330
+ var compress = null;
331
+ var lastIndex = -1;
332
+ var count = 0;
333
+ var lastCount = 0;
334
+ for (var i = 0; i < 8; i++) {
296
335
  if (address[i] !== 0)
297
336
  continue;
298
337
  count = 1;
299
- for (let j = i + 1; j < 8; j++) {
338
+ for (var j = i + 1; j < 8; j++) {
300
339
  if (address[j] !== 0)
301
340
  break;
302
341
  count++;
@@ -313,8 +352,8 @@ function iPv6Serializer(address) {
313
352
  * 4. Let ignore0 be false.
314
353
  * 5. For each pieceIndex in the range 0 to 7, inclusive:
315
354
  */
316
- let ignore0 = false;
317
- for (let pieceIndex = 0; pieceIndex < 8; pieceIndex++) {
355
+ var ignore0 = false;
356
+ for (var pieceIndex = 0; pieceIndex < 8; pieceIndex++) {
318
357
  /**
319
358
  * 5.1. If ignore0 is true and address[pieceIndex] is 0, then continue.
320
359
  * 5.2. Otherwise, if ignore0 is true, set ignore0 to false.
@@ -366,12 +405,12 @@ function urlParser(input, baseURL, encodingOverride) {
366
405
  * if that did not return failure, and null otherwise.
367
406
  * 5. Return url.
368
407
  */
369
- const url = basicURLParser(input, baseURL, encodingOverride);
408
+ var url = basicURLParser(input, baseURL, encodingOverride);
370
409
  if (url === null)
371
410
  return null;
372
411
  if (url.scheme !== "blob")
373
412
  return url;
374
- const entry = resolveABlobURL(url);
413
+ var entry = resolveABlobURL(url);
375
414
  if (entry !== null) {
376
415
  url._blobURLEntry = entry;
377
416
  }
@@ -389,6 +428,7 @@ exports.urlParser = urlParser;
389
428
  * @param encodingOverride - encoding override
390
429
  */
391
430
  function basicURLParser(input, baseURL, encodingOverride, url, stateOverride) {
431
+ var e_2, _a, e_3, _b;
392
432
  /**
393
433
  * 1. If url is not given:
394
434
  * 1.1. Set url to a new URL.
@@ -399,8 +439,8 @@ function basicURLParser(input, baseURL, encodingOverride, url, stateOverride) {
399
439
  if (url === undefined) {
400
440
  url = newURL();
401
441
  // leading
402
- const leadingControlOrSpace = /^[\u0000-\u001F\u0020]+/;
403
- const trailingControlOrSpace = /[\u0000-\u001F\u0020]+$/;
442
+ var leadingControlOrSpace = /^[\u0000-\u001F\u0020]+/;
443
+ var trailingControlOrSpace = /[\u0000-\u001F\u0020]+$/;
404
444
  if (leadingControlOrSpace.test(input) || trailingControlOrSpace.test(input)) {
405
445
  validationError("Input string contains leading or trailing control characters or space.");
406
446
  }
@@ -411,7 +451,7 @@ function basicURLParser(input, baseURL, encodingOverride, url, stateOverride) {
411
451
  * 2. If input contains any ASCII tab or newline, validation error.
412
452
  * 3. Remove all ASCII tab or newline from input.
413
453
  */
414
- const tabOrNewline = /[\u0009\u000A\u000D]/g;
454
+ var tabOrNewline = /[\u0009\u000A\u000D]/g;
415
455
  if (tabOrNewline.test(input)) {
416
456
  validationError("Input string contains tab or newline characters.");
417
457
  }
@@ -423,10 +463,10 @@ function basicURLParser(input, baseURL, encodingOverride, url, stateOverride) {
423
463
  * 7. If encoding override is given, set encoding to the result of getting
424
464
  * an output encoding from encoding override.
425
465
  */
426
- let state = (stateOverride === undefined ? interfaces_1.ParserState.SchemeStart : stateOverride);
466
+ var state = (stateOverride === undefined ? interfaces_1.ParserState.SchemeStart : stateOverride);
427
467
  if (baseURL === undefined)
428
468
  baseURL = null;
429
- let encoding = (encodingOverride === undefined ||
469
+ var encoding = (encodingOverride === undefined ||
430
470
  encodingOverride === "replacement" || encodingOverride === "UTF-16BE" ||
431
471
  encodingOverride === "UTF-16LE" ? "UTF-8" : encodingOverride);
432
472
  /**
@@ -434,12 +474,12 @@ function basicURLParser(input, baseURL, encodingOverride, url, stateOverride) {
434
474
  * 9. Let the @ flag, [] flag, and passwordTokenSeenFlag be unset.
435
475
  * 10. Let pointer be a pointer to first code point in input.
436
476
  */
437
- let buffer = "";
438
- let atFlag = false;
439
- let arrayFlag = false;
440
- let passwordTokenSeenFlag = false;
441
- const EOF = "";
442
- const walker = new util_1.StringWalker(input);
477
+ var buffer = "";
478
+ var atFlag = false;
479
+ var arrayFlag = false;
480
+ var passwordTokenSeenFlag = false;
481
+ var EOF = "";
482
+ var walker = new util_1.StringWalker(input);
443
483
  /**
444
484
  * 11. Keep running the following state machine by switching on state. If
445
485
  * after a run pointer points to the EOF code point, go to the next step.
@@ -817,27 +857,37 @@ function basicURLParser(input, baseURL, encodingOverride, url, stateOverride) {
817
857
  if (atFlag)
818
858
  buffer = '%40' + buffer;
819
859
  atFlag = true;
820
- for (const codePoint of buffer) {
821
- /**
822
- * 1.4.1. If codePoint is U+003A (:) and passwordTokenSeenFlag is
823
- * unset, then set passwordTokenSeenFlag and continue.
824
- * 1.4.2. Let encodedCodePoints be the result of running UTF-8
825
- * percent encode codePoint using the userinfo percent-encode set.
826
- * 1.4.3. If passwordTokenSeenFlag is set, then append
827
- * encodedCodePoints to url’s password.
828
- * 1.4.4. Otherwise, append encodedCodePoints to url’s username.
829
- */
830
- if (codePoint === ':' && !passwordTokenSeenFlag) {
831
- passwordTokenSeenFlag = true;
832
- continue;
833
- }
834
- const encodedCodePoints = utf8PercentEncode(codePoint, _userInfoPercentEncodeSet);
835
- if (passwordTokenSeenFlag) {
836
- url.password += encodedCodePoints;
860
+ try {
861
+ for (var buffer_1 = (e_2 = void 0, __values(buffer)), buffer_1_1 = buffer_1.next(); !buffer_1_1.done; buffer_1_1 = buffer_1.next()) {
862
+ var codePoint = buffer_1_1.value;
863
+ /**
864
+ * 1.4.1. If codePoint is U+003A (:) and passwordTokenSeenFlag is
865
+ * unset, then set passwordTokenSeenFlag and continue.
866
+ * 1.4.2. Let encodedCodePoints be the result of running UTF-8
867
+ * percent encode codePoint using the userinfo percent-encode set.
868
+ * 1.4.3. If passwordTokenSeenFlag is set, then append
869
+ * encodedCodePoints to url’s password.
870
+ * 1.4.4. Otherwise, append encodedCodePoints to url’s username.
871
+ */
872
+ if (codePoint === ':' && !passwordTokenSeenFlag) {
873
+ passwordTokenSeenFlag = true;
874
+ continue;
875
+ }
876
+ var encodedCodePoints = utf8PercentEncode(codePoint, _userInfoPercentEncodeSet);
877
+ if (passwordTokenSeenFlag) {
878
+ url.password += encodedCodePoints;
879
+ }
880
+ else {
881
+ url.username += encodedCodePoints;
882
+ }
837
883
  }
838
- else {
839
- url.username += encodedCodePoints;
884
+ }
885
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
886
+ finally {
887
+ try {
888
+ if (buffer_1_1 && !buffer_1_1.done && (_a = buffer_1.return)) _a.call(buffer_1);
840
889
  }
890
+ finally { if (e_2) throw e_2.error; }
841
891
  }
842
892
  /**
843
893
  * 1.5. Set buffer to the empty string.
@@ -898,7 +948,7 @@ function basicURLParser(input, baseURL, encodingOverride, url, stateOverride) {
898
948
  validationError("Invalid input string.");
899
949
  return null;
900
950
  }
901
- const host = hostParser(buffer, !isSpecial(url));
951
+ var host = hostParser(buffer, !isSpecial(url));
902
952
  if (host === null)
903
953
  return null;
904
954
  url.host = host;
@@ -936,7 +986,7 @@ function basicURLParser(input, baseURL, encodingOverride, url, stateOverride) {
936
986
  validationError("Invalid input string.");
937
987
  return url;
938
988
  }
939
- const host = hostParser(buffer, !isSpecial(url));
989
+ var host = hostParser(buffer, !isSpecial(url));
940
990
  if (host === null)
941
991
  return null;
942
992
  url.host = host;
@@ -988,7 +1038,7 @@ function basicURLParser(input, baseURL, encodingOverride, url, stateOverride) {
988
1038
  * 2.1.4. Set buffer to the empty string.
989
1039
  */
990
1040
  if (buffer !== "") {
991
- const port = parseInt(buffer, 10);
1041
+ var port = parseInt(buffer, 10);
992
1042
  if (port > Math.pow(2, 16) - 1) {
993
1043
  validationError("Invalid port number.");
994
1044
  return null;
@@ -1184,7 +1234,7 @@ function basicURLParser(input, baseURL, encodingOverride, url, stateOverride) {
1184
1234
  * 1.3.6. Set buffer to the empty string and state to path start
1185
1235
  * state.
1186
1236
  */
1187
- let host = hostParser(buffer, !isSpecial(url));
1237
+ var host = hostParser(buffer, !isSpecial(url));
1188
1238
  if (host === null)
1189
1239
  return null;
1190
1240
  if (host === "localhost")
@@ -1302,7 +1352,7 @@ function basicURLParser(input, baseURL, encodingOverride, url, stateOverride) {
1302
1352
  validationError("Invalid input string.");
1303
1353
  url.host = "";
1304
1354
  }
1305
- const bufferCodePoints = Array.from(buffer);
1355
+ var bufferCodePoints = Array.from(buffer);
1306
1356
  buffer = bufferCodePoints.slice(0, 1) + ':' + bufferCodePoints.slice(2);
1307
1357
  }
1308
1358
  /**
@@ -1436,7 +1486,7 @@ function basicURLParser(input, baseURL, encodingOverride, url, stateOverride) {
1436
1486
  if (encoding.toUpperCase() !== "UTF-8") {
1437
1487
  throw new Error("Only UTF-8 encoding is supported.");
1438
1488
  }
1439
- let bytes = util_1.utf8Encode(walker.c());
1489
+ var bytes = util_1.utf8Encode(walker.c());
1440
1490
  /**
1441
1491
  * 3.4. If bytes starts with `&#` and ends with 0x3B (;), then:
1442
1492
  */
@@ -1453,26 +1503,36 @@ function basicURLParser(input, baseURL, encodingOverride, url, stateOverride) {
1453
1503
  url.query += "%26%23" + infra_1.byteSequence.isomorphicDecode(bytes) + "%3B";
1454
1504
  }
1455
1505
  else {
1456
- /**
1457
- * 3.5. Otherwise, for each byte in bytes:
1458
- * 3.5.1. If one of the following is true
1459
- * - byte is less than 0x21 (!)
1460
- * - byte is greater than 0x7E (~)
1461
- * - byte is 0x22 ("), 0x23 (#), 0x3C (<), or 0x3E (>)
1462
- * - byte is 0x27 (') and url is special
1463
- * then append byte, percent encoded, to url’s query.
1464
- * 3.5.2. Otherwise, append a code point whose value is byte to
1465
- * url’s query.
1466
- */
1467
- for (const byte of bytes) {
1468
- if (byte < 0x21 || byte > 0x7E || byte === 0x22 ||
1469
- byte === 0x23 || byte === 0x3C || byte === 0x3E ||
1470
- (byte === 0x27 && isSpecial(url))) {
1471
- url.query += percentEncode(byte);
1506
+ try {
1507
+ /**
1508
+ * 3.5. Otherwise, for each byte in bytes:
1509
+ * 3.5.1. If one of the following is true
1510
+ * - byte is less than 0x21 (!)
1511
+ * - byte is greater than 0x7E (~)
1512
+ * - byte is 0x22 ("), 0x23 (#), 0x3C (<), or 0x3E (>)
1513
+ * - byte is 0x27 (') and url is special
1514
+ * then append byte, percent encoded, to url’s query.
1515
+ * 3.5.2. Otherwise, append a code point whose value is byte to
1516
+ * url’s query.
1517
+ */
1518
+ for (var bytes_1 = (e_3 = void 0, __values(bytes)), bytes_1_1 = bytes_1.next(); !bytes_1_1.done; bytes_1_1 = bytes_1.next()) {
1519
+ var byte = bytes_1_1.value;
1520
+ if (byte < 0x21 || byte > 0x7E || byte === 0x22 ||
1521
+ byte === 0x23 || byte === 0x3C || byte === 0x3E ||
1522
+ (byte === 0x27 && isSpecial(url))) {
1523
+ url.query += percentEncode(byte);
1524
+ }
1525
+ else {
1526
+ url.query += String.fromCharCode(byte);
1527
+ }
1472
1528
  }
1473
- else {
1474
- url.query += String.fromCharCode(byte);
1529
+ }
1530
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1531
+ finally {
1532
+ try {
1533
+ if (bytes_1_1 && !bytes_1_1.done && (_b = bytes_1.return)) _b.call(bytes_1);
1475
1534
  }
1535
+ finally { if (e_3) throw e_3.error; }
1476
1536
  }
1477
1537
  }
1478
1538
  }
@@ -1527,14 +1587,25 @@ exports.basicURLParser = basicURLParser;
1527
1587
  * @param username - username string
1528
1588
  */
1529
1589
  function setTheUsername(url, username) {
1590
+ var e_4, _a;
1530
1591
  /**
1531
1592
  * 1. Set url’s username to the empty string.
1532
1593
  * 2. For each code point in username, UTF-8 percent encode it using the
1533
1594
  * userinfo percent-encode set, and append the result to url’s username.
1534
1595
  */
1535
- let result = "";
1536
- for (const codePoint of username) {
1537
- result += utf8PercentEncode(codePoint, _userInfoPercentEncodeSet);
1596
+ var result = "";
1597
+ try {
1598
+ for (var username_1 = __values(username), username_1_1 = username_1.next(); !username_1_1.done; username_1_1 = username_1.next()) {
1599
+ var codePoint = username_1_1.value;
1600
+ result += utf8PercentEncode(codePoint, _userInfoPercentEncodeSet);
1601
+ }
1602
+ }
1603
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1604
+ finally {
1605
+ try {
1606
+ if (username_1_1 && !username_1_1.done && (_a = username_1.return)) _a.call(username_1);
1607
+ }
1608
+ finally { if (e_4) throw e_4.error; }
1538
1609
  }
1539
1610
  url.username = result;
1540
1611
  }
@@ -1546,14 +1617,25 @@ exports.setTheUsername = setTheUsername;
1546
1617
  * @param username - password string
1547
1618
  */
1548
1619
  function setThePassword(url, password) {
1620
+ var e_5, _a;
1549
1621
  /**
1550
1622
  * 1. Set url’s password to the empty string.
1551
1623
  * 2. For each code point in password, UTF-8 percent encode it using the
1552
1624
  * userinfo percent-encode set, and append the result to url’s password.
1553
1625
  */
1554
- let result = "";
1555
- for (const codePoint of password) {
1556
- result += utf8PercentEncode(codePoint, _userInfoPercentEncodeSet);
1626
+ var result = "";
1627
+ try {
1628
+ for (var password_1 = __values(password), password_1_1 = password_1.next(); !password_1_1.done; password_1_1 = password_1.next()) {
1629
+ var codePoint = password_1_1.value;
1630
+ result += utf8PercentEncode(codePoint, _userInfoPercentEncodeSet);
1631
+ }
1632
+ }
1633
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1634
+ finally {
1635
+ try {
1636
+ if (password_1_1 && !password_1_1.done && (_a = password_1.return)) _a.call(password_1);
1637
+ }
1638
+ finally { if (e_5) throw e_5.error; }
1557
1639
  }
1558
1640
  url.password = result;
1559
1641
  }
@@ -1573,7 +1655,7 @@ exports.isSingleDotPathSegment = isSingleDotPathSegment;
1573
1655
  * @param str - a string
1574
1656
  */
1575
1657
  function isDoubleDotPathSegment(str) {
1576
- const lowerStr = str.toLowerCase();
1658
+ var lowerStr = str.toLowerCase();
1577
1659
  return lowerStr === ".." || lowerStr === ".%2e" ||
1578
1660
  lowerStr === "%2e." || lowerStr === "%2e%2e";
1579
1661
  }
@@ -1591,7 +1673,7 @@ function shorten(url) {
1591
1673
  * normalized Windows drive letter, then return.
1592
1674
  * 4. Remove path’s last item.
1593
1675
  */
1594
- const path = url.path;
1676
+ var path = url.path;
1595
1677
  if (path.length === 0)
1596
1678
  return;
1597
1679
  if (url.scheme === "file" && path.length === 1 &&
@@ -1654,7 +1736,8 @@ exports.startsWithAWindowsDriveLetter = startsWithAWindowsDriveLetter;
1654
1736
  * @param isNotSpecial - `true` if the source URL is not special; otherwise
1655
1737
  * `false`.
1656
1738
  */
1657
- function hostParser(input, isNotSpecial = false) {
1739
+ function hostParser(input, isNotSpecial) {
1740
+ if (isNotSpecial === void 0) { isNotSpecial = false; }
1658
1741
  /**
1659
1742
  * 1. If isNotSpecial is not given, then set isNotSpecial to false.
1660
1743
  * 2. If input starts with U+005B ([), then:
@@ -1684,14 +1767,14 @@ function hostParser(input, isNotSpecial = false) {
1684
1767
  * coupled with an early return for failure, as domain to ASCII fails
1685
1768
  * on U+FFFD REPLACEMENT CHARACTER.
1686
1769
  */
1687
- const domain = util_1.utf8Decode(stringPercentDecode(input));
1770
+ var domain = util_1.utf8Decode(stringPercentDecode(input));
1688
1771
  /**
1689
1772
  * 5. Let asciiDomain be the result of running domain to ASCII on domain.
1690
1773
  * 6. If asciiDomain is failure, validation error, return failure.
1691
1774
  * 7. If asciiDomain contains a forbidden host code point, validation error,
1692
1775
  * return failure.
1693
1776
  */
1694
- const asciiDomain = domainToASCII(domain);
1777
+ var asciiDomain = domainToASCII(domain);
1695
1778
  if (asciiDomain === null) {
1696
1779
  validationError("Invalid domain.");
1697
1780
  return null;
@@ -1705,7 +1788,7 @@ function hostParser(input, isNotSpecial = false) {
1705
1788
  * 9. If ipv4Host is an IPv4 address or failure, return ipv4Host.
1706
1789
  * 10. Return asciiDomain.
1707
1790
  */
1708
- const ipv4Host = iPv4Parser(asciiDomain);
1791
+ var ipv4Host = iPv4Parser(asciiDomain);
1709
1792
  if (ipv4Host === null || util_1.isNumber(ipv4Host))
1710
1793
  return ipv4Host;
1711
1794
  return asciiDomain;
@@ -1718,11 +1801,12 @@ exports.hostParser = hostParser;
1718
1801
  * @param isNotSpecial - `true` if the source URL is not special; otherwise
1719
1802
  * `false`.
1720
1803
  */
1721
- function iPv4NumberParser(input, validationErrorFlag = { value: false }) {
1804
+ function iPv4NumberParser(input, validationErrorFlag) {
1805
+ if (validationErrorFlag === void 0) { validationErrorFlag = { value: false }; }
1722
1806
  /**
1723
1807
  * 1. Let R be 10.
1724
1808
  */
1725
- let R = 10;
1809
+ var R = 10;
1726
1810
  if (input.startsWith("0x") || input.startsWith("0X")) {
1727
1811
  /**
1728
1812
  * 2. If input contains at least two code points and the first two code
@@ -1754,7 +1838,7 @@ function iPv4NumberParser(input, validationErrorFlag = { value: false }) {
1754
1838
  */
1755
1839
  if (input === "")
1756
1840
  return 0;
1757
- const radixRDigits = (R === 10 ? /^[0-9]+$/ : (R === 16 ? /^[0-9A-Fa-f]+$/ : /^[0-7]+$/));
1841
+ var radixRDigits = (R === 10 ? /^[0-9]+$/ : (R === 16 ? /^[0-9A-Fa-f]+$/ : /^[0-7]+$/));
1758
1842
  if (!radixRDigits.test(input))
1759
1843
  return null;
1760
1844
  /**
@@ -1771,12 +1855,13 @@ exports.iPv4NumberParser = iPv4NumberParser;
1771
1855
  * @param input - input string
1772
1856
  */
1773
1857
  function iPv4Parser(input) {
1858
+ var e_6, _a, e_7, _b;
1774
1859
  /**
1775
1860
  * 1. Let validationErrorFlag be unset.
1776
1861
  * 2. Let parts be input split on U+002E (.).
1777
1862
  */
1778
- const validationErrorFlag = { value: false };
1779
- const parts = input.split('.');
1863
+ var validationErrorFlag = { value: false };
1864
+ var parts = input.split('.');
1780
1865
  /**
1781
1866
  * 3. If the last item in parts is the empty string, then:
1782
1867
  * 3.1. Set validationErrorFlag.
@@ -1801,14 +1886,24 @@ function iPv4Parser(input) {
1801
1886
  * 6.3. If n is failure, return input.
1802
1887
  * 6.4. Append n to numbers.
1803
1888
  */
1804
- const numbers = [];
1805
- for (const part of parts) {
1806
- if (part === "")
1807
- return input;
1808
- const n = iPv4NumberParser(part, validationErrorFlag);
1809
- if (n === null)
1810
- return input;
1811
- numbers.push(n);
1889
+ var numbers = [];
1890
+ try {
1891
+ for (var parts_1 = __values(parts), parts_1_1 = parts_1.next(); !parts_1_1.done; parts_1_1 = parts_1.next()) {
1892
+ var part = parts_1_1.value;
1893
+ if (part === "")
1894
+ return input;
1895
+ var n = iPv4NumberParser(part, validationErrorFlag);
1896
+ if (n === null)
1897
+ return input;
1898
+ numbers.push(n);
1899
+ }
1900
+ }
1901
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
1902
+ finally {
1903
+ try {
1904
+ if (parts_1_1 && !parts_1_1.done && (_a = parts_1.return)) _a.call(parts_1);
1905
+ }
1906
+ finally { if (e_6) throw e_6.error; }
1812
1907
  }
1813
1908
  /**
1814
1909
  * 7. If validationErrorFlag is set, validation error.
@@ -1820,8 +1915,8 @@ function iPv4Parser(input) {
1820
1915
  */
1821
1916
  if (validationErrorFlag.value)
1822
1917
  validationError("Invalid IP v4 address.");
1823
- for (let i = 0; i < numbers.length; i++) {
1824
- const item = numbers[i];
1918
+ for (var i = 0; i < numbers.length; i++) {
1919
+ var item = numbers[i];
1825
1920
  if (item > 255) {
1826
1921
  validationError("Invalid IP v4 address.");
1827
1922
  if (i < numbers.length - 1)
@@ -1836,7 +1931,7 @@ function iPv4Parser(input) {
1836
1931
  * 11. Let ipv4 be the last item in numbers.
1837
1932
  * 12. Remove the last item from numbers.
1838
1933
  */
1839
- let ipv4 = numbers[numbers.length - 1];
1934
+ var ipv4 = numbers[numbers.length - 1];
1840
1935
  numbers.pop();
1841
1936
  /**
1842
1937
  * 13. Let counter be zero.
@@ -1844,10 +1939,20 @@ function iPv4Parser(input) {
1844
1939
  * 14.2. Increment ipv4 by n × 256**(3 − counter).
1845
1940
  * 14.2. Increment counter by 1.
1846
1941
  */
1847
- let counter = 0;
1848
- for (const n of numbers) {
1849
- ipv4 += n * Math.pow(256, 3 - counter);
1850
- counter++;
1942
+ var counter = 0;
1943
+ try {
1944
+ for (var numbers_1 = __values(numbers), numbers_1_1 = numbers_1.next(); !numbers_1_1.done; numbers_1_1 = numbers_1.next()) {
1945
+ var n = numbers_1_1.value;
1946
+ ipv4 += n * Math.pow(256, 3 - counter);
1947
+ counter++;
1948
+ }
1949
+ }
1950
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
1951
+ finally {
1952
+ try {
1953
+ if (numbers_1_1 && !numbers_1_1.done && (_b = numbers_1.return)) _b.call(numbers_1);
1954
+ }
1955
+ finally { if (e_7) throw e_7.error; }
1851
1956
  }
1852
1957
  /**
1853
1958
  * 15. Return ipv4.
@@ -1861,6 +1966,7 @@ exports.iPv4Parser = iPv4Parser;
1861
1966
  * @param input - input string
1862
1967
  */
1863
1968
  function iPv6Parser(input) {
1969
+ var _a;
1864
1970
  /**
1865
1971
  * 1. Let address be a new IPv6 address whose IPv6 pieces are all 0.
1866
1972
  * 2. Let pieceIndex be 0.
@@ -1868,11 +1974,11 @@ function iPv6Parser(input) {
1868
1974
  * 4. Let pointer be a pointer into input, initially 0 (pointing to the
1869
1975
  * first code point).
1870
1976
  */
1871
- const EOF = "";
1872
- const address = [0, 0, 0, 0, 0, 0, 0, 0];
1873
- let pieceIndex = 0;
1874
- let compress = null;
1875
- const walker = new util_1.StringWalker(input);
1977
+ var EOF = "";
1978
+ var address = [0, 0, 0, 0, 0, 0, 0, 0];
1979
+ var pieceIndex = 0;
1980
+ var compress = null;
1981
+ var walker = new util_1.StringWalker(input);
1876
1982
  /**
1877
1983
  * 5. If c is U+003A (:), then:
1878
1984
  * 5.1. If remaining does not start with U+003A (:), validation error,
@@ -1922,8 +2028,8 @@ function iPv6Parser(input) {
1922
2028
  * to value × 0x10 + c interpreted as hexadecimal number, and increase
1923
2029
  * pointer and length by 1.
1924
2030
  */
1925
- let value = 0;
1926
- let length = 0;
2031
+ var value = 0;
2032
+ var length = 0;
1927
2033
  while (length < 4 && infra_1.codePoint.ASCIIHexDigit.test(walker.c())) {
1928
2034
  value = value * 0x10 + parseInt(walker.c(), 16);
1929
2035
  walker.pointer++;
@@ -1949,7 +2055,7 @@ function iPv6Parser(input) {
1949
2055
  validationError("Invalid IP v6 address.");
1950
2056
  return null;
1951
2057
  }
1952
- let numbersSeen = 0;
2058
+ var numbersSeen = 0;
1953
2059
  /**
1954
2060
  * 6.5.5. While c is not the EOF code point:
1955
2061
  */
@@ -1957,7 +2063,7 @@ function iPv6Parser(input) {
1957
2063
  /**
1958
2064
  * 6.5.5.1. Let ipv4Piece be null.
1959
2065
  */
1960
- let ipv4Piece = null;
2066
+ var ipv4Piece = null;
1961
2067
  /**
1962
2068
  * 6.5.5.2. If numbersSeen is greater than 0, then:
1963
2069
  * 6.5.5.2.1. If c is a U+002E (.) and numbersSeen is less than 4, then
@@ -1988,7 +2094,7 @@ function iPv6Parser(input) {
1988
2094
  /**
1989
2095
  * 6.5.5.4.1. Let number be c interpreted as decimal number.
1990
2096
  */
1991
- const number = parseInt(walker.c(), 10);
2097
+ var number = parseInt(walker.c(), 10);
1992
2098
  /**
1993
2099
  * 6.5.5.4.2. If ipv4Piece is null, then set ipv4Piece to number.
1994
2100
  * Otherwise, if ipv4Piece is 0, validation error, return failure.
@@ -2076,11 +2182,10 @@ function iPv6Parser(input) {
2076
2182
  * both pieceIndex and swaps by 1.
2077
2183
  */
2078
2184
  if (compress !== null) {
2079
- let swaps = pieceIndex - compress;
2185
+ var swaps = pieceIndex - compress;
2080
2186
  pieceIndex = 7;
2081
2187
  while (pieceIndex !== 0 && swaps > 0) {
2082
- [address[pieceIndex], address[compress + swaps - 1]] =
2083
- [address[compress + swaps - 1], address[pieceIndex]];
2188
+ _a = __read([address[compress + swaps - 1], address[pieceIndex]], 2), address[pieceIndex] = _a[0], address[compress + swaps - 1] = _a[1];
2084
2189
  pieceIndex--;
2085
2190
  swaps--;
2086
2191
  }
@@ -2105,6 +2210,7 @@ exports.iPv6Parser = iPv6Parser;
2105
2210
  * @param input - a string
2106
2211
  */
2107
2212
  function opaqueHostParser(input) {
2213
+ var e_8, _a;
2108
2214
  /**
2109
2215
  * 1. If input contains a forbidden host code point excluding U+0025 (%),
2110
2216
  * validation error, return failure.
@@ -2113,14 +2219,24 @@ function opaqueHostParser(input) {
2113
2219
  * control percent-encode set, and append the result to output.
2114
2220
  * 4. Return output.
2115
2221
  */
2116
- const forbiddenChars = /[\x00\t\f\r #/:?@\[\\\]]/;
2222
+ var forbiddenChars = /[\x00\t\f\r #/:?@\[\\\]]/;
2117
2223
  if (forbiddenChars.test(input)) {
2118
2224
  validationError("Invalid host string.");
2119
2225
  return null;
2120
2226
  }
2121
- let output = "";
2122
- for (const codePoint of input) {
2123
- output += utf8PercentEncode(codePoint, _c0ControlPercentEncodeSet);
2227
+ var output = "";
2228
+ try {
2229
+ for (var input_1 = __values(input), input_1_1 = input_1.next(); !input_1_1.done; input_1_1 = input_1.next()) {
2230
+ var codePoint = input_1_1.value;
2231
+ output += utf8PercentEncode(codePoint, _c0ControlPercentEncodeSet);
2232
+ }
2233
+ }
2234
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
2235
+ finally {
2236
+ try {
2237
+ if (input_1_1 && !input_1_1.done && (_a = input_1.return)) _a.call(input_1);
2238
+ }
2239
+ finally { if (e_8) throw e_8.error; }
2124
2240
  }
2125
2241
  return output;
2126
2242
  }
@@ -2156,7 +2272,7 @@ exports.percentEncode = percentEncode;
2156
2272
  * @param input - a byte sequence
2157
2273
  */
2158
2274
  function percentDecode(input) {
2159
- const isHexDigit = (byte) => {
2275
+ var isHexDigit = function (byte) {
2160
2276
  return (byte >= 0x30 && byte <= 0x39) || (byte >= 0x41 && byte <= 0x46) ||
2161
2277
  (byte >= 0x61 && byte <= 0x66);
2162
2278
  };
@@ -2164,10 +2280,10 @@ function percentDecode(input) {
2164
2280
  * 1. Let output be an empty byte sequence.
2165
2281
  * 2. For each byte byte in input:
2166
2282
  */
2167
- const output = new Uint8Array(input.length);
2168
- let n = 0;
2169
- for (let i = 0; i < input.length; i++) {
2170
- const byte = input[i];
2283
+ var output = new Uint8Array(input.length);
2284
+ var n = 0;
2285
+ for (var i = 0; i < input.length; i++) {
2286
+ var byte = input[i];
2171
2287
  /**
2172
2288
  * 2.1. If byte is not 0x25 (%), then append byte to output.
2173
2289
  * 2.2. Otherwise, if byte is 0x25 (%) and the next two bytes after byte
@@ -2193,7 +2309,7 @@ function percentDecode(input) {
2193
2309
  n++;
2194
2310
  }
2195
2311
  else {
2196
- const bytePoint = parseInt(util_1.utf8Decode(Uint8Array.of(input[i + 1], input[i + 2])), 16);
2312
+ var bytePoint = parseInt(util_1.utf8Decode(Uint8Array.of(input[i + 1], input[i + 2])), 16);
2197
2313
  output[n] = bytePoint;
2198
2314
  n++;
2199
2315
  i += 2;
@@ -2222,6 +2338,7 @@ exports.stringPercentDecode = stringPercentDecode;
2222
2338
  * @param percentEncodeSet - a percent encode set
2223
2339
  */
2224
2340
  function utf8PercentEncode(codePoint, percentEncodeSet) {
2341
+ var e_9, _a;
2225
2342
  /**
2226
2343
  * 1. If codePoint is not in percentEncodeSet, then return codePoint.
2227
2344
  * 2. Let bytes be the result of running UTF-8 encode on codePoint.
@@ -2230,10 +2347,20 @@ function utf8PercentEncode(codePoint, percentEncodeSet) {
2230
2347
  */
2231
2348
  if (!percentEncodeSet.test(codePoint))
2232
2349
  return codePoint;
2233
- const bytes = util_1.utf8Encode(codePoint);
2234
- let result = "";
2235
- for (const byte of bytes) {
2236
- result += percentEncode(byte);
2350
+ var bytes = util_1.utf8Encode(codePoint);
2351
+ var result = "";
2352
+ try {
2353
+ for (var bytes_2 = __values(bytes), bytes_2_1 = bytes_2.next(); !bytes_2_1.done; bytes_2_1 = bytes_2.next()) {
2354
+ var byte = bytes_2_1.value;
2355
+ result += percentEncode(byte);
2356
+ }
2357
+ }
2358
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
2359
+ finally {
2360
+ try {
2361
+ if (bytes_2_1 && !bytes_2_1.done && (_a = bytes_2.return)) _a.call(bytes_2);
2362
+ }
2363
+ finally { if (e_9) throw e_9.error; }
2237
2364
  }
2238
2365
  return result;
2239
2366
  }
@@ -2255,7 +2382,8 @@ exports.hostEquals = hostEquals;
2255
2382
  * @param urlB - a URL
2256
2383
  * @param excludeFragmentsFlag - whether to ignore fragments while comparing
2257
2384
  */
2258
- function urlEquals(urlA, urlB, excludeFragmentsFlag = false) {
2385
+ function urlEquals(urlA, urlB, excludeFragmentsFlag) {
2386
+ if (excludeFragmentsFlag === void 0) { excludeFragmentsFlag = false; }
2259
2387
  /**
2260
2388
  * 1. Let serializedA be the result of serializing A, with the exclude
2261
2389
  * fragment flag set if the exclude fragments flag is set.
@@ -2287,19 +2415,30 @@ exports.urlEncodedStringParser = urlEncodedStringParser;
2287
2415
  * @param input - a byte sequence
2288
2416
  */
2289
2417
  function urlEncodedParser(input) {
2418
+ var e_10, _a, e_11, _b;
2290
2419
  /**
2291
2420
  * 1. Let sequences be the result of splitting input on 0x26 (&).
2292
2421
  */
2293
- const sequences = [];
2294
- let currentSequence = [];
2295
- for (const byte of input) {
2296
- if (byte === 0x26) {
2297
- sequences.push(Uint8Array.from(currentSequence));
2298
- currentSequence = [];
2422
+ var sequences = [];
2423
+ var currentSequence = [];
2424
+ try {
2425
+ for (var input_2 = __values(input), input_2_1 = input_2.next(); !input_2_1.done; input_2_1 = input_2.next()) {
2426
+ var byte = input_2_1.value;
2427
+ if (byte === 0x26) {
2428
+ sequences.push(Uint8Array.from(currentSequence));
2429
+ currentSequence = [];
2430
+ }
2431
+ else {
2432
+ currentSequence.push(byte);
2433
+ }
2299
2434
  }
2300
- else {
2301
- currentSequence.push(byte);
2435
+ }
2436
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
2437
+ finally {
2438
+ try {
2439
+ if (input_2_1 && !input_2_1.done && (_a = input_2.return)) _a.call(input_2);
2302
2440
  }
2441
+ finally { if (e_10) throw e_10.error; }
2303
2442
  }
2304
2443
  if (currentSequence.length !== 0) {
2305
2444
  sequences.push(Uint8Array.from(currentSequence));
@@ -2307,48 +2446,58 @@ function urlEncodedParser(input) {
2307
2446
  /**
2308
2447
  * 2. Let output be an initially empty list of name-value tuples where both name and value hold a string.
2309
2448
  */
2310
- const output = [];
2311
- /**
2312
- * 3. For each byte sequence bytes in sequences:
2313
- */
2314
- for (const bytes of sequences) {
2315
- /**
2316
- * 3.1. If bytes is the empty byte sequence, then continue.
2317
- */
2318
- if (bytes.length === 0)
2319
- continue;
2449
+ var output = [];
2450
+ try {
2320
2451
  /**
2321
- * 3.2. If bytes contains a 0x3D (=), then let name be the bytes from the
2322
- * start of bytes up to but excluding its first 0x3D (=), and let value be
2323
- * the bytes, if any, after the first 0x3D (=) up to the end of bytes.
2324
- * If 0x3D (=) is the first byte, then name will be the empty byte
2325
- * sequence. If it is the last, then value will be the empty byte sequence.
2326
- * 3.3. Otherwise, let name have the value of bytes and let value be the
2327
- * empty byte sequence.
2452
+ * 3. For each byte sequence bytes in sequences:
2328
2453
  */
2329
- const index = bytes.indexOf(0x3D);
2330
- const name = (index !== -1 ? bytes.slice(0, index) : bytes);
2331
- const value = (index !== -1 ? bytes.slice(index + 1) : new Uint8Array());
2332
- /**
2333
- * 3.4. Replace any 0x2B (+) in name and value with 0x20 (SP).
2334
- */
2335
- for (let i = 0; i < name.length; i++)
2336
- if (name[i] === 0x2B)
2337
- name[i] = 0x20;
2338
- for (let i = 0; i < value.length; i++)
2339
- if (value[i] === 0x2B)
2340
- value[i] = 0x20;
2341
- /**
2342
- * 3.5. Let nameString and valueString be the result of running UTF-8
2343
- * decode without BOM on the percent decoding of name and value,
2344
- * respectively.
2345
- */
2346
- const nameString = util_1.utf8Decode(name);
2347
- const valueString = util_1.utf8Decode(value);
2348
- /**
2349
- * 3.6. Append (nameString, valueString) to output.
2350
- */
2351
- output.push([nameString, valueString]);
2454
+ for (var sequences_1 = __values(sequences), sequences_1_1 = sequences_1.next(); !sequences_1_1.done; sequences_1_1 = sequences_1.next()) {
2455
+ var bytes = sequences_1_1.value;
2456
+ /**
2457
+ * 3.1. If bytes is the empty byte sequence, then continue.
2458
+ */
2459
+ if (bytes.length === 0)
2460
+ continue;
2461
+ /**
2462
+ * 3.2. If bytes contains a 0x3D (=), then let name be the bytes from the
2463
+ * start of bytes up to but excluding its first 0x3D (=), and let value be
2464
+ * the bytes, if any, after the first 0x3D (=) up to the end of bytes.
2465
+ * If 0x3D (=) is the first byte, then name will be the empty byte
2466
+ * sequence. If it is the last, then value will be the empty byte sequence.
2467
+ * 3.3. Otherwise, let name have the value of bytes and let value be the
2468
+ * empty byte sequence.
2469
+ */
2470
+ var index = bytes.indexOf(0x3D);
2471
+ var name = (index !== -1 ? bytes.slice(0, index) : bytes);
2472
+ var value = (index !== -1 ? bytes.slice(index + 1) : new Uint8Array());
2473
+ /**
2474
+ * 3.4. Replace any 0x2B (+) in name and value with 0x20 (SP).
2475
+ */
2476
+ for (var i = 0; i < name.length; i++)
2477
+ if (name[i] === 0x2B)
2478
+ name[i] = 0x20;
2479
+ for (var i = 0; i < value.length; i++)
2480
+ if (value[i] === 0x2B)
2481
+ value[i] = 0x20;
2482
+ /**
2483
+ * 3.5. Let nameString and valueString be the result of running UTF-8
2484
+ * decode without BOM on the percent decoding of name and value,
2485
+ * respectively.
2486
+ */
2487
+ var nameString = util_1.utf8Decode(name);
2488
+ var valueString = util_1.utf8Decode(value);
2489
+ /**
2490
+ * 3.6. Append (nameString, valueString) to output.
2491
+ */
2492
+ output.push([nameString, valueString]);
2493
+ }
2494
+ }
2495
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
2496
+ finally {
2497
+ try {
2498
+ if (sequences_1_1 && !sequences_1_1.done && (_b = sequences_1.return)) _b.call(sequences_1);
2499
+ }
2500
+ finally { if (e_11) throw e_11.error; }
2352
2501
  }
2353
2502
  /**
2354
2503
  * 4. Return output.
@@ -2362,6 +2511,7 @@ exports.urlEncodedParser = urlEncodedParser;
2362
2511
  * @param input - a byte sequence
2363
2512
  */
2364
2513
  function urlEncodedByteSerializer(input) {
2514
+ var e_12, _a;
2365
2515
  /**
2366
2516
  * 1. Let output be the empty string.
2367
2517
  * 2. For each byte in input, depending on byte:
@@ -2381,19 +2531,29 @@ function urlEncodedByteSerializer(input) {
2381
2531
  * Append byte, percent encoded, to output.
2382
2532
  * 3. Return output.
2383
2533
  */
2384
- let output = "";
2385
- for (const byte of input) {
2386
- if (byte === 0x20) {
2387
- output += '+';
2388
- }
2389
- else if (byte === 0x2A || byte === 0x2D || byte === 0x2E ||
2390
- (byte >= 0x30 && byte <= 0x39) || (byte >= 0x41 && byte <= 0x5A) ||
2391
- byte === 0x5F || (byte >= 0x61 && byte <= 0x7A)) {
2392
- output += String.fromCodePoint(byte);
2534
+ var output = "";
2535
+ try {
2536
+ for (var input_3 = __values(input), input_3_1 = input_3.next(); !input_3_1.done; input_3_1 = input_3.next()) {
2537
+ var byte = input_3_1.value;
2538
+ if (byte === 0x20) {
2539
+ output += '+';
2540
+ }
2541
+ else if (byte === 0x2A || byte === 0x2D || byte === 0x2E ||
2542
+ (byte >= 0x30 && byte <= 0x39) || (byte >= 0x41 && byte <= 0x5A) ||
2543
+ byte === 0x5F || (byte >= 0x61 && byte <= 0x7A)) {
2544
+ output += String.fromCodePoint(byte);
2545
+ }
2546
+ else {
2547
+ output += percentEncode(byte);
2548
+ }
2393
2549
  }
2394
- else {
2395
- output += percentEncode(byte);
2550
+ }
2551
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
2552
+ finally {
2553
+ try {
2554
+ if (input_3_1 && !input_3_1.done && (_a = input_3.return)) _a.call(input_3);
2396
2555
  }
2556
+ finally { if (e_12) throw e_12.error; }
2397
2557
  }
2398
2558
  return output;
2399
2559
  }
@@ -2405,12 +2565,13 @@ exports.urlEncodedByteSerializer = urlEncodedByteSerializer;
2405
2565
  * @param encodingOverride: encoding override
2406
2566
  */
2407
2567
  function urlEncodedSerializer(tuples, encodingOverride) {
2568
+ var e_13, _a;
2408
2569
  /**
2409
2570
  * 1. Let encoding be UTF-8.
2410
2571
  * 2. If encoding override is given, set encoding to the result of getting
2411
2572
  * an output encoding from encoding override.
2412
2573
  */
2413
- const encoding = (encodingOverride === undefined ||
2574
+ var encoding = (encodingOverride === undefined ||
2414
2575
  encodingOverride === "replacement" || encodingOverride === "UTF-16BE" ||
2415
2576
  encodingOverride === "UTF-16LE" ? "UTF-8" : encodingOverride);
2416
2577
  if (encoding.toUpperCase() !== "UTF-8") {
@@ -2419,39 +2580,49 @@ function urlEncodedSerializer(tuples, encodingOverride) {
2419
2580
  /**
2420
2581
  * 3. Let output be the empty string.
2421
2582
  */
2422
- let output = "";
2423
- /**
2424
- * 4. For each tuple in tuples:
2425
- */
2426
- for (const tuple of tuples) {
2583
+ var output = "";
2584
+ try {
2427
2585
  /**
2428
- * 4.1. Let name be the result of serializing the result of encoding
2429
- * tuple’s name, using encoding.
2586
+ * 4. For each tuple in tuples:
2430
2587
  */
2431
- const name = urlEncodedByteSerializer(util_1.utf8Encode(tuple[0]));
2432
- /**
2433
- * 4.2. Let value be tuple’s value.
2434
- */
2435
- let value = tuple[1];
2436
- /**
2437
- * TODO:
2438
- * 4.3. If value is a file, then set value to value’s filename.
2439
- */
2440
- /**
2441
- * 4.4. Set value to the result of serializing the result of encoding
2442
- * value, using encoding.
2443
- */
2444
- value = urlEncodedByteSerializer(util_1.utf8Encode(value));
2445
- /**
2446
- * 4.5. If tuple is not the first pair in tuples, then append U+0026 (&)
2447
- * to output.
2448
- */
2449
- if (output !== "")
2450
- output += '&';
2451
- /**
2452
- * 4.6. Append name, followed by U+003D (=), followed by value, to output.
2453
- */
2454
- output += name + '=' + value;
2588
+ for (var tuples_1 = __values(tuples), tuples_1_1 = tuples_1.next(); !tuples_1_1.done; tuples_1_1 = tuples_1.next()) {
2589
+ var tuple = tuples_1_1.value;
2590
+ /**
2591
+ * 4.1. Let name be the result of serializing the result of encoding
2592
+ * tuple’s name, using encoding.
2593
+ */
2594
+ var name = urlEncodedByteSerializer(util_1.utf8Encode(tuple[0]));
2595
+ /**
2596
+ * 4.2. Let value be tuple’s value.
2597
+ */
2598
+ var value = tuple[1];
2599
+ /**
2600
+ * TODO:
2601
+ * 4.3. If value is a file, then set value to value’s filename.
2602
+ */
2603
+ /**
2604
+ * 4.4. Set value to the result of serializing the result of encoding
2605
+ * value, using encoding.
2606
+ */
2607
+ value = urlEncodedByteSerializer(util_1.utf8Encode(value));
2608
+ /**
2609
+ * 4.5. If tuple is not the first pair in tuples, then append U+0026 (&)
2610
+ * to output.
2611
+ */
2612
+ if (output !== "")
2613
+ output += '&';
2614
+ /**
2615
+ * 4.6. Append name, followed by U+003D (=), followed by value, to output.
2616
+ */
2617
+ output += name + '=' + value;
2618
+ }
2619
+ }
2620
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
2621
+ finally {
2622
+ try {
2623
+ if (tuples_1_1 && !tuples_1_1.done && (_a = tuples_1.return)) _a.call(tuples_1);
2624
+ }
2625
+ finally { if (e_13) throw e_13.error; }
2455
2626
  }
2456
2627
  /**
2457
2628
  * 5. Return output.
@@ -2492,7 +2663,7 @@ function origin(url) {
2492
2663
  if (url._blobURLEntry !== null) {
2493
2664
  // TODO: return URL’s blob URL entry’s environment’s origin.
2494
2665
  }
2495
- const parsedURL = basicURLParser(url.path[0]);
2666
+ var parsedURL = basicURLParser(url.path[0]);
2496
2667
  if (parsedURL === null)
2497
2668
  return interfaces_1.OpaqueOrigin;
2498
2669
  else
@@ -2515,7 +2686,8 @@ exports.origin = origin;
2515
2686
  *
2516
2687
  * @param domain - a domain string
2517
2688
  */
2518
- function domainToASCII(domain, beStrict = false) {
2689
+ function domainToASCII(domain, beStrict) {
2690
+ if (beStrict === void 0) { beStrict = false; }
2519
2691
  /**
2520
2692
  * 1. If beStrict is not given, set it to false.
2521
2693
  * 2. Let result be the result of running Unicode ToASCII with domain_name
@@ -2525,10 +2697,9 @@ function domainToASCII(domain, beStrict = false) {
2525
2697
  * 3. If result is a failure value, validation error, return failure.
2526
2698
  * 4. Return result.
2527
2699
  */
2528
- const result = uts46_1.toASCII(domain, { useSTD3ASCIIRules: beStrict,
2529
- checkHyphens: false, checkBidi: true, checkJoiners: true,
2530
- transitionalProcessing: false, verifyDnsLength: beStrict });
2531
- if (result === null) {
2700
+ // Use node.js function
2701
+ var result = url_1.domainToASCII(domain);
2702
+ if (result === "") {
2532
2703
  validationError("Invalid domain name.");
2533
2704
  return null;
2534
2705
  }
@@ -2540,7 +2711,8 @@ exports.domainToASCII = domainToASCII;
2540
2711
  *
2541
2712
  * @param domain - a domain string
2542
2713
  */
2543
- function domainToUnicode(domain, beStrict = false) {
2714
+ function domainToUnicode(domain, beStrict) {
2715
+ if (beStrict === void 0) { beStrict = false; }
2544
2716
  /**
2545
2717
  * 1. Let result be the result of running Unicode ToUnicode with domain_name
2546
2718
  * set to domain, CheckHyphens set to false, CheckBidi set to true,
@@ -2549,11 +2721,9 @@ function domainToUnicode(domain, beStrict = false) {
2549
2721
  * 2. Signify validation errors for any returned errors, and then,
2550
2722
  * return result.
2551
2723
  */
2552
- const output = { errors: false };
2553
- const result = uts46_1.toUnicode(domain, { checkHyphens: false, checkBidi: true,
2554
- checkJoiners: true, useSTD3ASCIIRules: false,
2555
- transitionalProcessing: false }, output);
2556
- if (output.errors) {
2724
+ // Use node.js function
2725
+ var result = url_1.domainToUnicode(domain);
2726
+ if (result === "") {
2557
2727
  validationError("Invalid domain name.");
2558
2728
  }
2559
2729
  return result;
@@ -2579,7 +2749,7 @@ function asciiSerializationOfAnOrigin(origin) {
2579
2749
  if (origin[0] === "" && origin[1] === "" && origin[2] === null && origin[3] === null) {
2580
2750
  return "null";
2581
2751
  }
2582
- let result = origin[0] + "://" + hostSerializer(origin[1]);
2752
+ var result = origin[0] + "://" + hostSerializer(origin[1]);
2583
2753
  if (origin[2] !== null)
2584
2754
  result += ":" + origin[2].toString();
2585
2755
  return result;