trousse 3.7.0 → 3.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/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { omitEmpty } from "./arrays.js";
2
- import { AnyOf, DeepOmit, IsPlainObject, MaybePromise, NormalizeOptions, Nullish, ParamOptions, ParamSource, PartialNullish, Pattern, RegistrableDomainOptions, WeightedMimeType } from "./types.js";
3
2
  import { coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString } from "./coercions.js";
4
3
  import { archiveExtensions, audioExtensions, codeExtensions, documentExtensions, flashExtensions, fontExtensions, imageExtensions, installerExtensions, subtitleExtensions, videoExtensions, webAudioExtensions, webImageExtensions, webVideoExtensions } from "./files.js";
5
4
  import { isBoolean, isFiniteNumber, isFunction, isInteger, isNonEmptyString, isNullish, isNumber, isObject, isPlainObject, isPresent, isString, isValidDate } from "./is.js";
@@ -9,5 +8,6 @@ import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyO
9
8
  import { createAcceptHeader, feedMimeTypes, genericFeedMimeTypes, genericHtmlMimeTypes, htmlMimeTypes } from "./mimes.js";
10
9
  import { omit, pick, toMap, trimObject } from "./objects.js";
11
10
  import { sleep } from "./timers.js";
11
+ import { AnyOf, DeepOmit, IsPlainObject, MaybePromise, NormalizeOptions, Nullish, ParamOptions, ParamSource, PartialNullish, Pattern, RegistrableDomainOptions, WeightedMimeType } from "./types.js";
12
12
  import { addMissingProtocol, addMissingScheme, composeFragment, composeQuery, createUrlSpellings, createUrlVariants, decodePercent, decodeSegment, encodePathSegment, fixMalformedProtocol, fixMalformedQuery, fixMalformedScheme, getFragmentParam, getFragmentParamValues, getFragmentParams, getOrigin, getPathSegments, getQueryParam, getQueryParamValues, getQueryParams, getRegistrableDomain, getSubdomain, hasFragmentParam, hasQueryParam, isHostOf, isHostOrSubdomainOf, isHttpUrl, isIpAddress, isSubdomainOf, normalizeUrl, parseUrl, resolveFeedProtocol, resolveFeedScheme, resolveUrl, stripWww, trimUrlValues, upgradeProtocol, upgradeScheme } from "./urls.js";
13
13
  export { type AnyOf, type DeepOmit, type IsPlainObject, type MaybePromise, type NormalizeOptions, type Nullish, type ParamOptions, type ParamSource, type PartialNullish, type Pattern, type RegistrableDomainOptions, type WeightedMimeType, addMissingProtocol, addMissingScheme, anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, composeFragment, composeQuery, createAcceptHeader, createUrlSpellings, createUrlVariants, decodePercent, decodeSegment, documentExtensions, encodePathSegment, endsWithAnyOf, escapeHtml, escapeRegex, feedMimeTypes, fixMalformedProtocol, fixMalformedQuery, fixMalformedScheme, flashExtensions, fontExtensions, genericFeedMimeTypes, genericHtmlMimeTypes, getAnyOf, getFragmentParam, getFragmentParamValues, getFragmentParams, getOrigin, getPathSegments, getQueryParam, getQueryParamValues, getQueryParams, getRegistrableDomain, getSubdomain, hasFragmentParam, hasQueryParam, htmlMimeTypes, imageExtensions, includesAnyOf, installerExtensions, isAnyOf, isBoolean, isFiniteNumber, isFunction, isHostOf, isHostOrSubdomainOf, isHttpUrl, isInteger, isIpAddress, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isSameText, isString, isSubdomainOf, isValidDate, normalizeUrl, omit, omitEmpty, parseJson, parseUrl, pick, resolveFeedProtocol, resolveFeedScheme, resolveUrl, sleep, startsWithAnyOf, stripWww, subtitleExtensions, t, toMap, trimObject, trimUrlValues, tx, upgradeProtocol, upgradeScheme, videoExtensions, webAudioExtensions, webImageExtensions, webVideoExtensions };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { isBoolean, isFiniteNumber, isFunction, isInteger, isNonEmptyString, isNullish, isNumber, isObject, isPlainObject, isPresent, isString, isValidDate } from "./is.js";
2
1
  import { omitEmpty } from "./arrays.js";
3
2
  import { coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString } from "./coercions.js";
4
3
  import { archiveExtensions, audioExtensions, codeExtensions, documentExtensions, flashExtensions, fontExtensions, imageExtensions, installerExtensions, subtitleExtensions, videoExtensions, webAudioExtensions, webImageExtensions, webVideoExtensions } from "./files.js";
4
+ import { isBoolean, isFiniteNumber, isFunction, isInteger, isNonEmptyString, isNullish, isNumber, isObject, isPlainObject, isPresent, isString, isValidDate } from "./is.js";
5
5
  import { isJsonLike, isParseableJson, parseJson } from "./json.js";
6
6
  import { escapeHtml, t, tx } from "./locales.js";
7
7
  import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, isSameText, startsWithAnyOf } from "./matching.js";
package/dist/matching.js CHANGED
@@ -83,4 +83,4 @@ const anyWordMatchesAnyOf = (value, patterns) => {
83
83
  }
84
84
  return false;
85
85
  };
86
- export { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, isSameText, startsWithAnyOf };
86
+ export { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, isSameText, startsWithAnyOf, toPatternList };
package/dist/urls.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { NormalizeOptions, Nullish, ParamOptions, ParamSource, RegistrableDomainOptions } from "./types.js";
1
+ import { NormalizeOptions, Nullish, ParamOptions, ParamSource, Pattern, RegistrableDomainOptions } from "./types.js";
2
2
  export declare const parseUrl: (value: Nullish<string | URL>, base?: string | URL) => URL | undefined;
3
3
  export declare const getPathSegments: (value: string | URL) => Array<string>;
4
4
  export declare const getOrigin: (value: Nullish<string | URL>) => string | undefined;
5
- export declare const isHostOf: (url: string | URL, hosts: string | ReadonlyArray<string>) => boolean;
6
- export declare const isSubdomainOf: (url: string | URL, domains: string | ReadonlyArray<string>) => boolean;
5
+ export declare const isHostOf: (url: string | URL, hosts: Pattern | ReadonlyArray<Pattern>) => boolean;
6
+ export declare const isSubdomainOf: (url: string | URL, domains: Pattern | ReadonlyArray<Pattern>) => boolean;
7
7
  export declare const isHttpUrl: (url: string | URL) => boolean;
8
- export declare const isHostOrSubdomainOf: (url: string | URL, domains: string | ReadonlyArray<string>) => boolean;
9
- export declare const getSubdomain: (url: string | URL, domains: string | ReadonlyArray<string>) => string | undefined;
8
+ export declare const isHostOrSubdomainOf: (url: string | URL, domains: Pattern | ReadonlyArray<Pattern>) => boolean;
9
+ export declare const getSubdomain: (url: string | URL, domains: Pattern | ReadonlyArray<Pattern>) => string | undefined;
10
10
  export declare const decodeSegment: (segment: string | undefined) => string | undefined;
11
11
  export declare const decodePercent: (value: string) => string;
12
12
  export declare const encodePathSegment: (value: string) => string;
package/dist/urls.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { isNullish } from "./is.js";
2
- import { endsWithAnyOf, isAnyOf } from "./matching.js";
2
+ import { isAnyOf, toPatternList } from "./matching.js";
3
3
  import { decodeHTMLStrict } from "entities";
4
4
  // src/urls.ts
5
5
  const httpSchemes = ["http:", "https:"];
@@ -31,15 +31,24 @@ const normalizeDomain = (domain) => {
31
31
  if (!nonAsciiRegex.test(bare)) return bare;
32
32
  return parseUrl(`http://${bare}`)?.hostname ?? bare;
33
33
  };
34
+ const normalizeHostPattern = (pattern) => {
35
+ return pattern instanceof RegExp ? pattern : normalizeDomain(pattern);
36
+ };
37
+ const getParentDomains = (hostname) => {
38
+ const parents = [];
39
+ for (let index = hostname.indexOf("."); index !== -1; index = hostname.indexOf(".", index + 1)) parents.push(hostname.slice(index + 1));
40
+ return parents;
41
+ };
34
42
  const isHostOf = (url, hosts) => {
35
43
  const hostname = getHostname(url);
36
44
  if (!hostname) return false;
37
- return isAnyOf(hostname, (typeof hosts === "string" ? [hosts] : hosts).map(normalizeDomain));
45
+ return isAnyOf(hostname, toPatternList(hosts).map(normalizeHostPattern));
38
46
  };
39
47
  const isSubdomainOf = (url, domains) => {
40
48
  const hostname = getHostname(url);
41
49
  if (!hostname) return false;
42
- return endsWithAnyOf(hostname, (typeof domains === "string" ? [domains] : domains).map((domain) => `.${normalizeDomain(domain)}`));
50
+ const list = toPatternList(domains).map(normalizeHostPattern);
51
+ return getParentDomains(hostname).some((parent) => isAnyOf(parent, list));
43
52
  };
44
53
  const isHttpUrl = (url) => {
45
54
  const scheme = parseUrl(url)?.protocol;
@@ -52,10 +61,11 @@ const isHostOrSubdomainOf = (url, domains) => {
52
61
  const getSubdomain = (url, domains) => {
53
62
  const hostname = getHostname(url)?.toLowerCase();
54
63
  if (!hostname) return;
55
- const list = typeof domains === "string" ? [domains] : domains;
56
- for (const domain of list) {
57
- const suffix = `.${normalizeDomain(domain).toLowerCase()}`;
58
- if (hostname.endsWith(suffix) && hostname.length > suffix.length) return hostname.slice(0, -suffix.length);
64
+ const parents = getParentDomains(hostname);
65
+ for (const domain of toPatternList(domains)) {
66
+ const pattern = normalizeHostPattern(domain);
67
+ const parent = parents.find((candidate) => isAnyOf(candidate, pattern));
68
+ if (parent) return hostname.slice(0, -parent.length - 1);
59
69
  }
60
70
  };
61
71
  const decodeSegment = (segment) => {
package/package.json CHANGED
@@ -39,12 +39,12 @@
39
39
  "test": "bun test"
40
40
  },
41
41
  "devDependencies": {
42
- "@types/bun": "^1.4.2",
43
- "kvalita": "^1.31.0",
44
- "tsdown": "0.23.1"
42
+ "@types/bun": "^1.4.4",
43
+ "kvalita": "^1.35.0",
44
+ "tsdown": "0.23.7"
45
45
  },
46
46
  "dependencies": {
47
- "entities": "^8.1.0"
47
+ "entities": "^9.0.0"
48
48
  },
49
- "version": "3.7.0"
49
+ "version": "3.8.0"
50
50
  }