@b9g/match-pattern 0.2.0 → 0.2.1

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.
Files changed (2) hide show
  1. package/package.json +6 -1
  2. package/src/index.js +196 -98
package/package.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "@b9g/match-pattern",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/bikeshaving/shovel.git",
7
+ "directory": "packages/match-pattern"
8
+ },
4
9
  "devDependencies": {
5
10
  "@b9g/libuild": "^0.1.18"
6
11
  },
package/src/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  /// <reference types="./index.d.ts" />
2
2
  // src/index.ts
3
3
  function isValidProtocol(protocol) {
4
- if (!protocol) return false;
5
- if (!/^[a-zA-Z]/.test(protocol)) return false;
4
+ if (!protocol)
5
+ return false;
6
+ if (!/^[a-zA-Z]/.test(protocol))
7
+ return false;
6
8
  return /^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(protocol);
7
9
  }
8
10
  function isSpecialScheme(protocol) {
@@ -10,7 +12,8 @@ function isSpecialScheme(protocol) {
10
12
  return special.includes(protocol.toLowerCase());
11
13
  }
12
14
  function isDefinitelyNonSpecialScheme(protocolPattern) {
13
- if (!protocolPattern) return false;
15
+ if (!protocolPattern)
16
+ return false;
14
17
  if (protocolPattern.includes("*") || protocolPattern.includes("+")) {
15
18
  return false;
16
19
  }
@@ -38,7 +41,8 @@ function toASCII(hostname) {
38
41
  try {
39
42
  return new URL("http://" + hostname).hostname;
40
43
  } catch (err) {
41
- if (!(err instanceof TypeError)) throw err;
44
+ if (!(err instanceof TypeError))
45
+ throw err;
42
46
  return hostname;
43
47
  }
44
48
  }
@@ -151,8 +155,10 @@ function validateHostnamePattern(hostname) {
151
155
  j += 2;
152
156
  continue;
153
157
  }
154
- if (hostname[j] === "(") depth++;
155
- if (hostname[j] === ")") depth--;
158
+ if (hostname[j] === "(")
159
+ depth++;
160
+ if (hostname[j] === ")")
161
+ depth--;
156
162
  j++;
157
163
  }
158
164
  i = j;
@@ -221,10 +227,12 @@ function normalizeHostnamePattern(hostname) {
221
227
  return hostname;
222
228
  }
223
229
  function canonicalizePort(port, throwOnInvalid = false) {
224
- if (port === "") return "";
230
+ if (port === "")
231
+ return "";
225
232
  const stripped = port.replace(/[\t\n\r]/g, "");
226
233
  const match = stripped.match(/^(\d+)/);
227
- if (!match) return void 0;
234
+ if (!match)
235
+ return void 0;
228
236
  const numericPort = parseInt(match[1], 10);
229
237
  if (numericPort > 65535) {
230
238
  if (throwOnInvalid) {
@@ -235,7 +243,8 @@ function canonicalizePort(port, throwOnInvalid = false) {
235
243
  return numericPort.toString();
236
244
  }
237
245
  function isValidPatternPort(port) {
238
- if (port === "") return true;
246
+ if (port === "")
247
+ return true;
239
248
  const stripped = port.replace(/[\t\n\r]/g, "");
240
249
  return /^\d+$/.test(stripped);
241
250
  }
@@ -331,15 +340,22 @@ function normalizePathname(pathname) {
331
340
  return result;
332
341
  }
333
342
  function isSimplePattern(pathname) {
334
- if (pathname.includes("\\")) return false;
335
- if (pathname.includes("{")) return false;
336
- if (pathname.includes("(")) return false;
337
- if (pathname.includes("+")) return false;
338
- if (pathname.includes("?")) return false;
343
+ if (pathname.includes("\\"))
344
+ return false;
345
+ if (pathname.includes("{"))
346
+ return false;
347
+ if (pathname.includes("("))
348
+ return false;
349
+ if (pathname.includes("+"))
350
+ return false;
351
+ if (pathname.includes("?"))
352
+ return false;
339
353
  const wildcardIndex = pathname.indexOf("*");
340
354
  if (wildcardIndex !== -1) {
341
- if (wildcardIndex !== pathname.length - 1) return false;
342
- if (pathname[wildcardIndex - 1] !== "/") return false;
355
+ if (wildcardIndex !== pathname.length - 1)
356
+ return false;
357
+ if (pathname[wildcardIndex - 1] !== "/")
358
+ return false;
343
359
  }
344
360
  const paramMatches = pathname.matchAll(new RegExp(":(\\p{ID_Continue}+)", "gu"));
345
361
  for (const match of paramMatches) {
@@ -427,12 +443,18 @@ function findSearchDelimiter(pattern) {
427
443
  i++;
428
444
  continue;
429
445
  }
430
- if (char === "(") parenDepth++;
431
- else if (char === ")") parenDepth--;
432
- else if (char === "[") bracketDepth++;
433
- else if (char === "]") bracketDepth--;
434
- else if (char === "{") braceDepth++;
435
- else if (char === "}") braceDepth--;
446
+ if (char === "(")
447
+ parenDepth++;
448
+ else if (char === ")")
449
+ parenDepth--;
450
+ else if (char === "[")
451
+ bracketDepth++;
452
+ else if (char === "]")
453
+ bracketDepth--;
454
+ else if (char === "{")
455
+ braceDepth++;
456
+ else if (char === "}")
457
+ braceDepth--;
436
458
  if (char === "?" && parenDepth === 0 && bracketDepth === 0 && braceDepth === 0) {
437
459
  const prev = i > 0 ? pattern[i - 1] : "";
438
460
  if ("*+)}".includes(prev)) {
@@ -464,16 +486,22 @@ function findPathnameStart(afterScheme) {
464
486
  i++;
465
487
  continue;
466
488
  }
467
- if (char === "(") parenDepth++;
468
- else if (char === ")") parenDepth--;
469
- else if (char === "[") bracketDepth++;
470
- else if (char === "]") bracketDepth--;
489
+ if (char === "(")
490
+ parenDepth++;
491
+ else if (char === ")")
492
+ parenDepth--;
493
+ else if (char === "[")
494
+ bracketDepth++;
495
+ else if (char === "]")
496
+ bracketDepth--;
471
497
  else if (char === "{") {
472
498
  braceDepth++;
473
- if (braceDepth === 1) braceStart = i;
499
+ if (braceDepth === 1)
500
+ braceStart = i;
474
501
  } else if (char === "}") {
475
502
  braceDepth--;
476
- if (braceDepth === 0) braceStart = -1;
503
+ if (braceDepth === 0)
504
+ braceStart = -1;
477
505
  } else if (char === "/" && parenDepth === 0 && bracketDepth === 0) {
478
506
  if (braceDepth > 0 && braceStart !== -1) {
479
507
  return { index: i, truncateHostname: i, useWildcardPathname: true };
@@ -514,12 +542,18 @@ function validatePatternStructure(pattern) {
514
542
  i++;
515
543
  continue;
516
544
  }
517
- if (char === "(") parenDepth++;
518
- else if (char === ")") parenDepth--;
519
- else if (char === "[") bracketDepth++;
520
- else if (char === "]") bracketDepth--;
521
- else if (char === "{") braceDepth++;
522
- else if (char === "}") braceDepth--;
545
+ if (char === "(")
546
+ parenDepth++;
547
+ else if (char === ")")
548
+ parenDepth--;
549
+ else if (char === "[")
550
+ bracketDepth++;
551
+ else if (char === "]")
552
+ bracketDepth--;
553
+ else if (char === "{")
554
+ braceDepth++;
555
+ else if (char === "}")
556
+ braceDepth--;
523
557
  }
524
558
  if (parenDepth > 0 || bracketDepth > 0 || braceDepth > 0) {
525
559
  throw new TypeError(
@@ -588,10 +622,12 @@ function parseStringPattern(pattern) {
588
622
  const hashIdx = afterAt.indexOf("#");
589
623
  const searchDelim2 = findSearchDelimiter(afterAt);
590
624
  let hostEnd = afterAt.length;
591
- if (slashIdx !== -1 && slashIdx < hostEnd) hostEnd = slashIdx;
625
+ if (slashIdx !== -1 && slashIdx < hostEnd)
626
+ hostEnd = slashIdx;
592
627
  if (searchDelim2.index !== -1 && searchDelim2.index < hostEnd)
593
628
  hostEnd = searchDelim2.index;
594
- if (hashIdx !== -1 && hashIdx < hostEnd) hostEnd = hashIdx;
629
+ if (hashIdx !== -1 && hashIdx < hostEnd)
630
+ hostEnd = hashIdx;
595
631
  const hostPart = afterAt.slice(0, hostEnd);
596
632
  let hostname;
597
633
  let port;
@@ -610,12 +646,14 @@ function parseStringPattern(pattern) {
610
646
  let pathEnd = afterAt.length;
611
647
  if (searchDelim2.index !== -1 && searchDelim2.index > slashIdx)
612
648
  pathEnd = Math.min(pathEnd, searchDelim2.index);
613
- if (hashIdx !== -1) pathEnd = Math.min(pathEnd, hashIdx);
649
+ if (hashIdx !== -1)
650
+ pathEnd = Math.min(pathEnd, hashIdx);
614
651
  pathname2 = afterAt.slice(pathStart, pathEnd);
615
652
  }
616
653
  if (searchDelim2.index !== -1) {
617
654
  let searchEnd = afterAt.length;
618
- if (hashIdx !== -1 && hashIdx > searchDelim2.index) searchEnd = hashIdx;
655
+ if (hashIdx !== -1 && hashIdx > searchDelim2.index)
656
+ searchEnd = hashIdx;
619
657
  search2 = afterAt.slice(
620
658
  searchDelim2.index + searchDelim2.offset,
621
659
  searchEnd
@@ -678,12 +716,18 @@ function parseStringPattern(pattern) {
678
716
  i++;
679
717
  continue;
680
718
  }
681
- if (char === "[") bracketDepth++;
682
- else if (char === "]") bracketDepth--;
683
- else if (char === "{") braceDepth++;
684
- else if (char === "}") braceDepth--;
685
- else if (char === "(") parenDepth++;
686
- else if (char === ")") parenDepth--;
719
+ if (char === "[")
720
+ bracketDepth++;
721
+ else if (char === "]")
722
+ bracketDepth--;
723
+ else if (char === "{")
724
+ braceDepth++;
725
+ else if (char === "}")
726
+ braceDepth--;
727
+ else if (char === "(")
728
+ parenDepth++;
729
+ else if (char === ")")
730
+ parenDepth--;
687
731
  else if (char === "@" && bracketDepth === 0 && braceDepth === 0 && parenDepth === 0) {
688
732
  atIndex = i;
689
733
  break;
@@ -706,8 +750,10 @@ function parseStringPattern(pattern) {
706
750
  i++;
707
751
  continue;
708
752
  }
709
- if (char === "{") braceDepth2++;
710
- else if (char === "}") braceDepth2--;
753
+ if (char === "{")
754
+ braceDepth2++;
755
+ else if (char === "}")
756
+ braceDepth2--;
711
757
  else if (char === ":" && braceDepth2 === 0) {
712
758
  const afterColon = userinfo.slice(i + 1);
713
759
  const paramMatch = afterColon.match(
@@ -865,9 +911,12 @@ function compileComponentPattern(component, ignoreCase = false) {
865
911
  j += 2;
866
912
  continue;
867
913
  }
868
- if (component[j] === "(") depth++;
869
- if (component[j] === ")") depth--;
870
- if (depth > 0) regexContent += component[j];
914
+ if (component[j] === "(")
915
+ depth++;
916
+ if (component[j] === ")")
917
+ depth--;
918
+ if (depth > 0)
919
+ regexContent += component[j];
871
920
  j++;
872
921
  }
873
922
  validateRegexGroupContent(regexContent);
@@ -900,7 +949,8 @@ function compileComponentPattern(component, ignoreCase = false) {
900
949
  }
901
950
  paramNames.push(...compiled.paramNames);
902
951
  i = closeIndex + 1;
903
- if (isModifier) i++;
952
+ if (isModifier)
953
+ i++;
904
954
  continue;
905
955
  }
906
956
  }
@@ -940,8 +990,10 @@ function compileComponentPattern(component, ignoreCase = false) {
940
990
  }
941
991
  const needsVFlag = requiresVFlag(pattern);
942
992
  let flags = "";
943
- if (ignoreCase) flags += "i";
944
- if (needsVFlag) flags += "v";
993
+ if (ignoreCase)
994
+ flags += "i";
995
+ if (needsVFlag)
996
+ flags += "v";
945
997
  const regex = new RegExp(`^${pattern}$`, flags || void 0);
946
998
  return { regex, paramNames, hasWildcard };
947
999
  }
@@ -1049,9 +1101,12 @@ function compilePathname(pathname, encodeChars = true, ignoreCase = false) {
1049
1101
  j += 2;
1050
1102
  continue;
1051
1103
  }
1052
- if (pathname[j] === "(") depth++;
1053
- if (pathname[j] === ")") depth--;
1054
- if (depth > 0) regexContent += pathname[j];
1104
+ if (pathname[j] === "(")
1105
+ depth++;
1106
+ if (pathname[j] === ")")
1107
+ depth--;
1108
+ if (depth > 0)
1109
+ regexContent += pathname[j];
1055
1110
  j++;
1056
1111
  }
1057
1112
  validateRegexGroupContent(regexContent);
@@ -1108,7 +1163,8 @@ function compilePathname(pathname, encodeChars = true, ignoreCase = false) {
1108
1163
  }
1109
1164
  paramNames.push(...compiled.paramNames);
1110
1165
  i = closeIndex + 1;
1111
- if (isModifier) i++;
1166
+ if (isModifier)
1167
+ i++;
1112
1168
  continue;
1113
1169
  }
1114
1170
  }
@@ -1180,8 +1236,10 @@ function compilePathname(pathname, encodeChars = true, ignoreCase = false) {
1180
1236
  }
1181
1237
  const needsVFlag = requiresVFlag(pattern);
1182
1238
  let flags = "";
1183
- if (ignoreCase) flags += "i";
1184
- if (needsVFlag) flags += "v";
1239
+ if (ignoreCase)
1240
+ flags += "i";
1241
+ if (needsVFlag)
1242
+ flags += "v";
1185
1243
  const regex = new RegExp(`^${pattern}$`, flags || void 0);
1186
1244
  return { regex, paramNames, hasWildcard };
1187
1245
  }
@@ -1202,7 +1260,8 @@ function testSearchParameters(searchPattern, actualSearch) {
1202
1260
  }
1203
1261
  function parseRawSearchParams(search) {
1204
1262
  const params = /* @__PURE__ */ new Map();
1205
- if (!search) return params;
1263
+ if (!search)
1264
+ return params;
1206
1265
  const parts = search.split("&");
1207
1266
  for (const part of parts) {
1208
1267
  const eqIdx = part.indexOf("=");
@@ -1237,7 +1296,8 @@ function parseSearchPattern(pattern) {
1237
1296
  const parts = pattern.split("&");
1238
1297
  for (const part of parts) {
1239
1298
  const [key, value] = part.split("=");
1240
- if (!key) continue;
1299
+ if (!key)
1300
+ continue;
1241
1301
  if (value === void 0) {
1242
1302
  params.set(key, { type: "wildcard" });
1243
1303
  continue;
@@ -1263,7 +1323,8 @@ function compileURLPatternInit(init, baseURL, options) {
1263
1323
  try {
1264
1324
  baseURLParsed = new URL(base);
1265
1325
  } catch (err) {
1266
- if (!(err instanceof TypeError)) throw err;
1326
+ if (!(err instanceof TypeError))
1327
+ throw err;
1267
1328
  }
1268
1329
  }
1269
1330
  const result = {};
@@ -1496,7 +1557,8 @@ var URLPattern = class {
1496
1557
  try {
1497
1558
  url = baseURL ? new URL(input, baseURL) : new URL(input);
1498
1559
  } catch (err) {
1499
- if (!(err instanceof TypeError)) throw err;
1560
+ if (!(err instanceof TypeError))
1561
+ throw err;
1500
1562
  return false;
1501
1563
  }
1502
1564
  } else {
@@ -1514,29 +1576,35 @@ var URLPattern = class {
1514
1576
  try {
1515
1577
  baseURLObj = new URL(base);
1516
1578
  } catch (err) {
1517
- if (!(err instanceof TypeError)) throw err;
1579
+ if (!(err instanceof TypeError))
1580
+ throw err;
1518
1581
  }
1519
1582
  }
1520
1583
  const protocol = input.protocol ?? baseURLObj?.protocol.replace(":", "") ?? void 0;
1521
- if (protocol !== void 0 && !isValidProtocol(protocol)) return false;
1584
+ if (protocol !== void 0 && !isValidProtocol(protocol))
1585
+ return false;
1522
1586
  if (this.#compiled.protocol) {
1523
1587
  if (protocol === void 0 || !this.#compiled.protocol.regex.test(protocol))
1524
1588
  return false;
1525
1589
  }
1526
1590
  if (this.#compiled.hostname) {
1527
1591
  let hostname = input.hostname ?? baseURLObj?.hostname;
1528
- if (hostname === void 0) return false;
1592
+ if (hostname === void 0)
1593
+ return false;
1529
1594
  hostname = toASCII(hostname);
1530
- if (!this.#compiled.hostname.regex.test(hostname)) return false;
1595
+ if (!this.#compiled.hostname.regex.test(hostname))
1596
+ return false;
1531
1597
  }
1532
1598
  let port = input.port ?? baseURLObj?.port;
1533
1599
  if (port !== void 0) {
1534
1600
  const canonical = canonicalizePort(port);
1535
- if (canonical === void 0) return false;
1601
+ if (canonical === void 0)
1602
+ return false;
1536
1603
  port = canonical;
1537
1604
  if (protocol) {
1538
1605
  const defaultPort = getDefaultPort(protocol);
1539
- if (defaultPort && port === defaultPort) port = "";
1606
+ if (defaultPort && port === defaultPort)
1607
+ port = "";
1540
1608
  }
1541
1609
  }
1542
1610
  if (this.#compiled.port) {
@@ -1562,27 +1630,36 @@ var URLPattern = class {
1562
1630
  pathname = basePath.slice(0, basePath.lastIndexOf("/") + 1) + pathname;
1563
1631
  }
1564
1632
  }
1565
- if (pathname.startsWith("/")) pathname = normalizePathname(pathname);
1633
+ if (pathname.startsWith("/"))
1634
+ pathname = normalizePathname(pathname);
1566
1635
  const shouldEncode = !protocol || isSpecialScheme(protocol);
1567
- if (shouldEncode) pathname = encodePathname(pathname);
1568
- if (!this.#compiled.pathname.regex.test(pathname)) return false;
1636
+ if (shouldEncode)
1637
+ pathname = encodePathname(pathname);
1638
+ if (!this.#compiled.pathname.regex.test(pathname))
1639
+ return false;
1569
1640
  if (this.#compiled.hash) {
1570
1641
  let hash = input.hash ?? baseURLObj?.hash.replace("#", "") ?? void 0;
1571
- if (hash === void 0) return false;
1572
- if (hash.startsWith("#")) hash = hash.slice(1);
1642
+ if (hash === void 0)
1643
+ return false;
1644
+ if (hash.startsWith("#"))
1645
+ hash = hash.slice(1);
1573
1646
  hash = encodeHash(hash);
1574
- if (!this.#compiled.hash.regex.test(hash)) return false;
1647
+ if (!this.#compiled.hash.regex.test(hash))
1648
+ return false;
1575
1649
  }
1576
1650
  if (this.#compiled.search) {
1577
1651
  let search = input.search ?? baseURLObj?.search?.replace("?", "") ?? "";
1578
- if (search.startsWith("?")) search = search.slice(1);
1652
+ if (search.startsWith("?"))
1653
+ search = search.slice(1);
1579
1654
  search = encodeSearch(search);
1580
- if (!this.#compiled.search.regex.test(search)) return false;
1655
+ if (!this.#compiled.search.regex.test(search))
1656
+ return false;
1581
1657
  }
1582
1658
  return true;
1583
1659
  }
1584
1660
  exec(input, baseURL) {
1585
- if (!this.test(input, baseURL)) return null;
1661
+ if (!this.test(input, baseURL))
1662
+ return null;
1586
1663
  if (typeof input === "object" && !(input instanceof URL)) {
1587
1664
  return this.#execInit(input, baseURL);
1588
1665
  }
@@ -1640,7 +1717,8 @@ var URLPattern = class {
1640
1717
  try {
1641
1718
  baseURLObj = new URL(base);
1642
1719
  } catch (err) {
1643
- if (!(err instanceof TypeError)) throw err;
1720
+ if (!(err instanceof TypeError))
1721
+ throw err;
1644
1722
  }
1645
1723
  }
1646
1724
  let pathname = input.pathname ?? baseURLObj?.pathname ?? "/";
@@ -1661,7 +1739,8 @@ var URLPattern = class {
1661
1739
  }
1662
1740
  if (this.#compiled.search) {
1663
1741
  let search2 = input.search ?? baseURLObj?.search?.replace("?", "") ?? "";
1664
- if (search2.startsWith("?")) search2 = search2.slice(1);
1742
+ if (search2.startsWith("?"))
1743
+ search2 = search2.slice(1);
1665
1744
  const searchMatch = this.#compiled.search.regex.exec(search2);
1666
1745
  if (searchMatch) {
1667
1746
  for (let i = 0; i < this.#compiled.search.paramNames.length; i++) {
@@ -1677,7 +1756,8 @@ var URLPattern = class {
1677
1756
  const protocol = input.protocol ?? baseURLObj?.protocol.replace(":", "") ?? "";
1678
1757
  const hostname = input.hostname ?? baseURLObj?.hostname ?? "";
1679
1758
  let port = input.port ?? baseURLObj?.port ?? "";
1680
- if (port) port = canonicalizePort(port) || "";
1759
+ if (port)
1760
+ port = canonicalizePort(port) || "";
1681
1761
  const hash = input.hash ?? baseURLObj?.hash?.replace("#", "") ?? "";
1682
1762
  const search = input.search ?? baseURLObj?.search?.replace("?", "") ?? "";
1683
1763
  return {
@@ -1746,7 +1826,8 @@ var MatchPattern = class {
1746
1826
  try {
1747
1827
  url = baseURL ? new URL(input, baseURL) : new URL(input);
1748
1828
  } catch (err) {
1749
- if (!(err instanceof TypeError)) throw err;
1829
+ if (!(err instanceof TypeError))
1830
+ throw err;
1750
1831
  return false;
1751
1832
  }
1752
1833
  } else {
@@ -1768,29 +1849,35 @@ var MatchPattern = class {
1768
1849
  try {
1769
1850
  baseURLObj = new URL(base);
1770
1851
  } catch (err) {
1771
- if (!(err instanceof TypeError)) throw err;
1852
+ if (!(err instanceof TypeError))
1853
+ throw err;
1772
1854
  }
1773
1855
  }
1774
1856
  const protocol = input.protocol ?? baseURLObj?.protocol.replace(":", "") ?? void 0;
1775
- if (protocol !== void 0 && !isValidProtocol(protocol)) return false;
1857
+ if (protocol !== void 0 && !isValidProtocol(protocol))
1858
+ return false;
1776
1859
  if (this.#compiled.protocol) {
1777
1860
  if (protocol === void 0 || !this.#compiled.protocol.regex.test(protocol))
1778
1861
  return false;
1779
1862
  }
1780
1863
  if (this.#compiled.hostname) {
1781
1864
  let hostname = input.hostname ?? baseURLObj?.hostname;
1782
- if (hostname === void 0) return false;
1865
+ if (hostname === void 0)
1866
+ return false;
1783
1867
  hostname = toASCII(hostname);
1784
- if (!this.#compiled.hostname.regex.test(hostname)) return false;
1868
+ if (!this.#compiled.hostname.regex.test(hostname))
1869
+ return false;
1785
1870
  }
1786
1871
  let port = input.port ?? baseURLObj?.port;
1787
1872
  if (port !== void 0) {
1788
1873
  const canonical = canonicalizePort(port);
1789
- if (canonical === void 0) return false;
1874
+ if (canonical === void 0)
1875
+ return false;
1790
1876
  port = canonical;
1791
1877
  if (protocol) {
1792
1878
  const defaultPort = getDefaultPort(protocol);
1793
- if (defaultPort && port === defaultPort) port = "";
1879
+ if (defaultPort && port === defaultPort)
1880
+ port = "";
1794
1881
  }
1795
1882
  }
1796
1883
  if (this.#compiled.port) {
@@ -1813,7 +1900,8 @@ var MatchPattern = class {
1813
1900
  const resolved = new URL(pathname, baseURLObj.href);
1814
1901
  pathname = resolved.pathname;
1815
1902
  } catch (err) {
1816
- if (!(err instanceof TypeError)) throw err;
1903
+ if (!(err instanceof TypeError))
1904
+ throw err;
1817
1905
  const basePath = baseURLObj.pathname;
1818
1906
  if (basePath.endsWith("/")) {
1819
1907
  pathname = basePath + pathname;
@@ -1822,20 +1910,27 @@ var MatchPattern = class {
1822
1910
  }
1823
1911
  }
1824
1912
  }
1825
- if (pathname.startsWith("/")) pathname = normalizePathname(pathname);
1913
+ if (pathname.startsWith("/"))
1914
+ pathname = normalizePathname(pathname);
1826
1915
  const shouldEncode = !protocol || isSpecialScheme(protocol);
1827
- if (shouldEncode) pathname = encodePathname(pathname);
1828
- if (!this.#compiled.pathname.regex.test(pathname)) return false;
1916
+ if (shouldEncode)
1917
+ pathname = encodePathname(pathname);
1918
+ if (!this.#compiled.pathname.regex.test(pathname))
1919
+ return false;
1829
1920
  if (this.#compiled.hash) {
1830
1921
  let hash = input.hash ?? baseURLObj?.hash.replace("#", "") ?? void 0;
1831
- if (hash === void 0) return false;
1832
- if (hash.startsWith("#")) hash = hash.slice(1);
1922
+ if (hash === void 0)
1923
+ return false;
1924
+ if (hash.startsWith("#"))
1925
+ hash = hash.slice(1);
1833
1926
  hash = encodeHash(hash);
1834
- if (!this.#compiled.hash.regex.test(hash)) return false;
1927
+ if (!this.#compiled.hash.regex.test(hash))
1928
+ return false;
1835
1929
  }
1836
1930
  if (this.#searchPattern) {
1837
1931
  let search = input.search ?? baseURLObj?.search?.replace("?", "") ?? "";
1838
- if (search.startsWith("?")) search = search.slice(1);
1932
+ if (search.startsWith("?"))
1933
+ search = search.slice(1);
1839
1934
  search = encodeSearch(search);
1840
1935
  if (!this.#searchPattern.includes("=")) {
1841
1936
  if (this.#compiled.search) {
@@ -1848,7 +1943,8 @@ var MatchPattern = class {
1848
1943
  return true;
1849
1944
  }
1850
1945
  exec(input, baseURL) {
1851
- if (!this.test(input, baseURL)) return null;
1946
+ if (!this.test(input, baseURL))
1947
+ return null;
1852
1948
  if (typeof input === "object" && !(input instanceof URL)) {
1853
1949
  return this.#execInit(input, baseURL);
1854
1950
  }
@@ -1905,7 +2001,8 @@ var MatchPattern = class {
1905
2001
  try {
1906
2002
  baseURLObj = new URL(base);
1907
2003
  } catch (err) {
1908
- if (!(err instanceof TypeError)) throw err;
2004
+ if (!(err instanceof TypeError))
2005
+ throw err;
1909
2006
  }
1910
2007
  }
1911
2008
  let pathname = input.pathname ?? baseURLObj?.pathname ?? "/";
@@ -1936,7 +2033,8 @@ var MatchPattern = class {
1936
2033
  const protocol = input.protocol ?? baseURLObj?.protocol.replace(":", "") ?? "";
1937
2034
  const hostname = input.hostname ?? baseURLObj?.hostname ?? "";
1938
2035
  let port = input.port ?? baseURLObj?.port ?? "";
1939
- if (port) port = canonicalizePort(port) || "";
2036
+ if (port)
2037
+ port = canonicalizePort(port) || "";
1940
2038
  const hash = input.hash ?? baseURLObj?.hash?.replace("#", "") ?? "";
1941
2039
  const search = input.search ?? baseURLObj?.search?.replace("?", "") ?? "";
1942
2040
  return {