trousse 2.7.0 → 2.8.0

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.
package/dist/types.d.ts CHANGED
@@ -13,6 +13,7 @@ export type NormalizeOptions = {
13
13
  stripScheme?: boolean;
14
14
  /** @deprecated Use `stripScheme` instead, which wins when both are set. */
15
15
  stripProtocol?: boolean;
16
+ stripHostTrailingDot?: boolean;
16
17
  stripAuthentication?: boolean;
17
18
  stripWww?: boolean;
18
19
  stripTrailingSlash?: boolean;
package/dist/urls.js CHANGED
@@ -68,7 +68,7 @@ const getStrippedParamsSet = (params) => {
68
68
  };
69
69
  const ipv4Regex = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
70
70
  const ipv6Regex = /^([0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}$/i;
71
- const wwwPrefixRegex = /^www\./;
71
+ const wwwPrefixRegex = /^(?:www\.)+(?=.*\.)/;
72
72
  const ipv6BracketsRegex = /^\[|\]$/g;
73
73
  const unreservedCharsRegex = /[a-zA-Z0-9._~-]/;
74
74
  const httpsLetterRegex = /s/i;
@@ -94,7 +94,7 @@ const missingColonSchemeRegex = /^https?[\s=.\\]*\/\//i;
94
94
  const validUrlRegex = /^https?:\/\/(?:www\.|[a-vx-z0-9])/i;
95
95
  const schemeSeparator = String.raw`\.*[:\s=\\/][:\s=.\\/]*`;
96
96
  const leadingSchemeSeparator = String.raw`\.*(?::[:\s=.\\/]*|[\s=\\/][:\s=.\\/]+)`;
97
- const doubledSchemeRegex = /* @__PURE__ */ new RegExp(String.raw`^\/?[htps]{2,7}${leadingSchemeSeparator}([htps]{2,7})(?!:\d)(${schemeSeparator})[.,:/]*(www[./]+)?`, "i");
97
+ const doubledSchemeRegex = /* @__PURE__ */ new RegExp(String.raw`^\/?[htps]{2,7}${leadingSchemeSeparator}([htps]{2,7})(?!:\d|[^/?#\\]*@)(${schemeSeparator})[.,:/]*(www[./]+)?`, "i");
98
98
  const singleMalformedRegex = /* @__PURE__ */ new RegExp(String.raw`^\/?(h[htps():]{1,10}|t{1,2}ps?)(${leadingSchemeSeparator})[.,:/]*(www[./]+)?`, "i");
99
99
  const isSchemeToken = (token, separator) => {
100
100
  const lowered = token.toLowerCase();
@@ -225,6 +225,7 @@ const lowercaseQueryPair = (pair) => {
225
225
  const normalizeUrl = (url, options) => {
226
226
  try {
227
227
  const parsed = new URL(options.normalizeUnicode ? url.normalize("NFC") : url);
228
+ if (options.stripHostTrailingDot && parsed.hostname.endsWith(".")) parsed.hostname = parsed.hostname.slice(0, -1);
228
229
  if (options.stripAuthentication) {
229
230
  parsed.username = "";
230
231
  parsed.password = "";
@@ -259,8 +260,7 @@ const normalizeUrl = (url, options) => {
259
260
  }
260
261
  };
261
262
  const stripWww = (hostname) => {
262
- const stripped = hostname.replace(wwwPrefixRegex, "");
263
- return stripped.includes(".") ? stripped : hostname;
263
+ return hostname.replace(wwwPrefixRegex, "");
264
264
  };
265
265
  const isIpAddress = (hostname) => {
266
266
  return ipv4Regex.test(hostname) || ipv6Regex.test(hostname.replace(ipv6BracketsRegex, ""));
package/package.json CHANGED
@@ -46,5 +46,5 @@
46
46
  "dependencies": {
47
47
  "entities": "^8.1.0"
48
48
  },
49
- "version": "2.7.0"
49
+ "version": "2.8.0"
50
50
  }