trousse 3.17.0 → 3.17.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.
package/dist/is.js CHANGED
@@ -29,7 +29,7 @@ const isObject = (value) => {
29
29
  const isPlainObject = (value) => {
30
30
  return isObject(value) && Object.getPrototypeOf(value) === Object.prototype;
31
31
  };
32
- const whitespaceOnlyRegex = /^\p{White_Space}*$/u;
32
+ const whitespaceOnlyRegex = /^[\p{White_Space}\uFEFF]*$/u;
33
33
  const isNonEmptyString = (value) => {
34
34
  if (!isString(value) || !value) return false;
35
35
  const code = value.charCodeAt(0);
package/dist/urls.js CHANGED
@@ -37,6 +37,17 @@ const getParentDomains = (hostname) => {
37
37
  return parents;
38
38
  };
39
39
  const keepValue = (value) => value;
40
+ const lowerDomainCacheLimit = 1e3;
41
+ const lowerDomainCache = /* @__PURE__ */ new Map();
42
+ const toLowerDomain = (domain) => {
43
+ let lowerDomain = lowerDomainCache.get(domain);
44
+ if (lowerDomain === void 0) {
45
+ lowerDomain = normalizeDomain(domain).toLowerCase();
46
+ if (lowerDomainCache.size >= lowerDomainCacheLimit) lowerDomainCache.clear();
47
+ lowerDomainCache.set(domain, lowerDomain);
48
+ }
49
+ return lowerDomain;
50
+ };
40
51
  const endsWithDomain = (lowerHostname, domain) => {
41
52
  const lowerDomain = domain.toLowerCase();
42
53
  if (lowerHostname.at(-lowerDomain.length - 1) !== ".") return false;
@@ -51,7 +62,7 @@ const isHostOf = (url, hosts) => {
51
62
  if (isAnyOf(hostname, host)) return true;
52
63
  continue;
53
64
  }
54
- if (isAnyOf(lowerHostname, normalizeDomain(host).toLowerCase(), keepValue)) return true;
65
+ if (isAnyOf(lowerHostname, toLowerDomain(host), keepValue)) return true;
55
66
  }
56
67
  return false;
57
68
  };
@@ -65,7 +76,7 @@ const isSubdomainOf = (url, domains) => {
65
76
  patterns.push(domain);
66
77
  continue;
67
78
  }
68
- if (endsWithDomain(lowerHostname, normalizeDomain(domain))) return true;
79
+ if (endsWithDomain(lowerHostname, toLowerDomain(domain))) return true;
69
80
  }
70
81
  if (patterns.length === 0) return false;
71
82
  return getParentDomains(hostname).some((parent) => isAnyOf(parent, patterns));
@@ -84,7 +95,7 @@ const getSubdomain = (url, domains) => {
84
95
  let parents;
85
96
  for (const domain of toPatternList(domains)) {
86
97
  if (isString(domain)) {
87
- const name = normalizeDomain(domain);
98
+ const name = toLowerDomain(domain);
88
99
  if (name && endsWithDomain(hostname, name)) return hostname.slice(0, -name.length - 1);
89
100
  continue;
90
101
  }
@@ -760,7 +771,7 @@ const getRegistrableDomain = (url, options) => {
760
771
  const isBrandDomainOf = (url, brands, options) => {
761
772
  const domain = getRegistrableDomain(url, options);
762
773
  if (!domain || isIpAddress(domain)) return false;
763
- return isAnyOf(domain.slice(0, domain.indexOf(".")), brands);
774
+ return isAnyOf(domain.split(".")[0], brands);
764
775
  };
765
776
  /** @deprecated Use `fixMalformedScheme` instead. */
766
777
  const fixMalformedProtocol = fixMalformedScheme;
package/package.json CHANGED
@@ -46,5 +46,5 @@
46
46
  "dependencies": {
47
47
  "entities": "^9.0.0"
48
48
  },
49
- "version": "3.17.0"
49
+ "version": "3.17.1"
50
50
  }