trousse 3.14.0 → 3.16.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/README.md CHANGED
@@ -13,3 +13,62 @@ npm add trousse
13
13
  ```
14
14
 
15
15
  In published packages, prefer adding it as a dev dependency and bundling it at build time so it adds no runtime dependency.
16
+
17
+ ## API
18
+
19
+ ### `normalizeUrl`
20
+
21
+ Builds a key for comparing URLs, so two spellings of one address come out the same. The result is not meant for fetching: `stripScheme` and `stripRootSlash` produce strings no URL parser reads back, and `sortQueryParams` or `lowercaseQuery` can produce a URL the server answers differently.
22
+
23
+ ```typescript
24
+ import { normalizeUrl } from 'trousse'
25
+
26
+ normalizeUrl('https://www.example.com/feed/?utm_source=x&b=2&a=1#top', {
27
+ stripWww: true,
28
+ stripTrailingSlash: true,
29
+ stripHash: true,
30
+ sortQueryParams: true,
31
+ stripQueryParams: ['utm_source'],
32
+ })
33
+ // 'https://example.com/feed?a=1&b=2'
34
+ ```
35
+
36
+ There are no defaults. Every option is off unless set, so `normalizeUrl(url, {})` applies none of them. The URL still goes through the URL parser, which lowercases the host, drops a default port and resolves `..` segments. A string that does not parse comes back unchanged.
37
+
38
+ | Option | Type | What it does |
39
+ |--------|------|--------------|
40
+ | `stripScheme` | `boolean` | Removes `http://` or `https://`, so both schemes compare the same |
41
+ | `stripProtocol` | `boolean` | Deprecated alias of `stripScheme`, which wins when both are set |
42
+ | `stripHostTrailingDot` | `boolean` | `example.com.` → `example.com`, the DNS absolute form |
43
+ | `stripAuthentication` | `boolean` | Removes `user:pass@` |
44
+ | `stripWww` | `boolean` | Removes every leading `www.` label, except the last one before a bare top-level domain, so `www.com` stays |
45
+ | `stripTrailingSlash` | `boolean` | `/feed/` → `/feed`, leaving the root `/` alone |
46
+ | `stripRootSlash` | `boolean` | `https://example.com/` → `https://example.com` |
47
+ | `collapseSlashes` | `boolean` | `///` → `/` in the path, except right after a `:`, so a URL inside the path keeps its `//` |
48
+ | `stripHash` | `boolean` | Removes the `#fragment` |
49
+ | `sortQueryParams` | `boolean` | Sorts query pairs by decoded name and drops empty pairs |
50
+ | `stripQueryParams` | `ReadonlyArray<string> \| QueryParamPredicate` | Removes query pairs by name or by a function, see below |
51
+ | `stripQuery` | `boolean` | Removes the whole query |
52
+ | `stripEmptyQuery` | `boolean` | `/feed?` → `/feed` |
53
+ | `lowercaseQuery` | `boolean` | Lowercases query names and values, leaving percent escapes as they are |
54
+ | `normalizeEncoding` | `boolean` | Uppercases `%xx` hex and decodes needless escapes in the path, query and fragment. In the query, `q=a%3Ab` and `q=a:b` come out the same, while `%26` keeps a value whole |
55
+ | `normalizeUnicode` | `boolean` | Applies NFC to the raw input before parsing |
56
+
57
+ #### `stripQueryParams`
58
+
59
+ A list of names removes every pair with one of those names, matched case-insensitively against the decoded name. The list is cached by identity, so build it once and never mutate it.
60
+
61
+ A function decides pair by pair and returns `true` to remove one. It gets three arguments:
62
+
63
+ - `name`: the decoded name, in its original case.
64
+ - `value`: the decoded value, or `undefined` for a pair with no `=`.
65
+ - `url`: the URL as normalized so far, so with `stripWww` the host arrives without its `www.`.
66
+
67
+ ```typescript
68
+ normalizeUrl('https://example.com/feed?utm_source=x&page=1&ref=', {
69
+ stripQueryParams: (name, value) => name.startsWith('utm_') || value === '',
70
+ })
71
+ // 'https://example.com/feed?page=1'
72
+ ```
73
+
74
+ In both forms, empty pairs go too, and the pairs that stay are written back as written, in their original encoding, or the one `normalizeEncoding` gave them. A query left with no pairs loses its `?`.
package/dist/index.d.ts CHANGED
@@ -3,11 +3,11 @@ import { coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, c
3
3
  import { archiveExtensions, audioExtensions, codeExtensions, documentExtensions, flashExtensions, fontExtensions, imageExtensions, installerExtensions, subtitleExtensions, videoExtensions, webAudioExtensions, webImageExtensions, webVideoExtensions } from "./files.js";
4
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
- import { escapeHtml, isLocaleSegment, isRegionSegment, t, tx } from "./locales.js";
6
+ import { escapeHtml, isLocale, isLocaleOrRegion, isLocaleSegment, isRegion, isRegionSegment, t, tx } from "./locales.js";
7
7
  import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, isSameText, startsWithAnyOf } from "./matching.js";
8
8
  import { createAcceptHeader, feedMimeTypes, genericFeedMimeTypes, genericHtmlMimeTypes, htmlMimeTypes } from "./mimes.js";
9
9
  import { omit, pick, toMap, trimObject } from "./objects.js";
10
10
  import { sleep } from "./timers.js";
11
- import { AnyOf, DeepOmit, IsPlainObject, LocaleSegmentOptions, MaybePromise, NormalizeOptions, Nullish, ParamOptions, ParamSource, PartialNullish, Pattern, QueryParamPredicate, RegistrableDomainOptions, WeightedMimeType } from "./types.js";
11
+ import { AnyOf, DeepOmit, IsPlainObject, LocaleOptions, LocaleSegmentOptions, MaybePromise, NormalizeOptions, Nullish, ParamOptions, ParamSource, PartialNullish, Pattern, QueryParamPredicate, RegistrableDomainOptions, WeightedMimeType } from "./types.js";
12
12
  import { addMissingProtocol, addMissingScheme, composeFragment, composeQuery, createUrlSpellings, createUrlVariants, decodeBase64, decodeBase64Binary, decodeBase64Url, decodeBase64UrlBinary, decodePercent, decodeSegment, encodePathSegment, fixMalformedHost, fixMalformedProtocol, fixMalformedQuery, fixMalformedScheme, getFragmentParam, getFragmentParamValues, getFragmentParams, getOrigin, getPathSegments, getQueryParam, getQueryParamValues, getQueryParams, getRegistrableDomain, getSubdomain, hasFragmentParam, hasQueryParam, isHostOf, isHostOrSubdomainOf, isHostname, isHttpUrl, isIpAddress, isSubdomainOf, isUtf8Binary, normalizeUrl, parseUrl, resolveFeedProtocol, resolveFeedScheme, resolveUrl, stripWww, trimUrlValues, upgradeProtocol, upgradeScheme } from "./urls.js";
13
- export { type AnyOf, type DeepOmit, type IsPlainObject, type LocaleSegmentOptions, type MaybePromise, type NormalizeOptions, type Nullish, type ParamOptions, type ParamSource, type PartialNullish, type Pattern, type QueryParamPredicate, type RegistrableDomainOptions, type WeightedMimeType, addMissingProtocol, addMissingScheme, anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, composeFragment, composeQuery, createAcceptHeader, createUrlSpellings, createUrlVariants, decodeBase64, decodeBase64Binary, decodeBase64Url, decodeBase64UrlBinary, decodePercent, decodeSegment, documentExtensions, encodePathSegment, endsWithAnyOf, escapeHtml, escapeRegex, feedMimeTypes, fixMalformedHost, 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, isHostname, isHttpUrl, isInteger, isIpAddress, isJsonLike, isLocaleSegment, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isRegionSegment, isSameText, isString, isSubdomainOf, isUtf8Binary, 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 };
13
+ export { type AnyOf, type DeepOmit, type IsPlainObject, type LocaleOptions, type LocaleSegmentOptions, type MaybePromise, type NormalizeOptions, type Nullish, type ParamOptions, type ParamSource, type PartialNullish, type Pattern, type QueryParamPredicate, type RegistrableDomainOptions, type WeightedMimeType, addMissingProtocol, addMissingScheme, anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, composeFragment, composeQuery, createAcceptHeader, createUrlSpellings, createUrlVariants, decodeBase64, decodeBase64Binary, decodeBase64Url, decodeBase64UrlBinary, decodePercent, decodeSegment, documentExtensions, encodePathSegment, endsWithAnyOf, escapeHtml, escapeRegex, feedMimeTypes, fixMalformedHost, 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, isHostname, isHttpUrl, isInteger, isIpAddress, isJsonLike, isLocale, isLocaleOrRegion, isLocaleSegment, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isRegion, isRegionSegment, isSameText, isString, isSubdomainOf, isUtf8Binary, 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
@@ -3,10 +3,10 @@ import { coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, c
3
3
  import { archiveExtensions, audioExtensions, codeExtensions, documentExtensions, flashExtensions, fontExtensions, imageExtensions, installerExtensions, subtitleExtensions, videoExtensions, webAudioExtensions, webImageExtensions, webVideoExtensions } from "./files.js";
4
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
- import { escapeHtml, isLocaleSegment, isRegionSegment, t, tx } from "./locales.js";
6
+ import { escapeHtml, isLocale, isLocaleOrRegion, isLocaleSegment, isRegion, isRegionSegment, t, tx } from "./locales.js";
7
7
  import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, isSameText, startsWithAnyOf } from "./matching.js";
8
8
  import { createAcceptHeader, feedMimeTypes, genericFeedMimeTypes, genericHtmlMimeTypes, htmlMimeTypes } from "./mimes.js";
9
9
  import { omit, pick, toMap, trimObject } from "./objects.js";
10
10
  import { sleep } from "./timers.js";
11
11
  import { addMissingProtocol, addMissingScheme, composeFragment, composeQuery, createUrlSpellings, createUrlVariants, decodeBase64, decodeBase64Binary, decodeBase64Url, decodeBase64UrlBinary, decodePercent, decodeSegment, encodePathSegment, fixMalformedHost, fixMalformedProtocol, fixMalformedQuery, fixMalformedScheme, getFragmentParam, getFragmentParamValues, getFragmentParams, getOrigin, getPathSegments, getQueryParam, getQueryParamValues, getQueryParams, getRegistrableDomain, getSubdomain, hasFragmentParam, hasQueryParam, isHostOf, isHostOrSubdomainOf, isHostname, isHttpUrl, isIpAddress, isSubdomainOf, isUtf8Binary, normalizeUrl, parseUrl, resolveFeedProtocol, resolveFeedScheme, resolveUrl, stripWww, trimUrlValues, upgradeProtocol, upgradeScheme } from "./urls.js";
12
- export { addMissingProtocol, addMissingScheme, anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, composeFragment, composeQuery, createAcceptHeader, createUrlSpellings, createUrlVariants, decodeBase64, decodeBase64Binary, decodeBase64Url, decodeBase64UrlBinary, decodePercent, decodeSegment, documentExtensions, encodePathSegment, endsWithAnyOf, escapeHtml, escapeRegex, feedMimeTypes, fixMalformedHost, 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, isHostname, isHttpUrl, isInteger, isIpAddress, isJsonLike, isLocaleSegment, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isRegionSegment, isSameText, isString, isSubdomainOf, isUtf8Binary, 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 };
12
+ export { addMissingProtocol, addMissingScheme, anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, composeFragment, composeQuery, createAcceptHeader, createUrlSpellings, createUrlVariants, decodeBase64, decodeBase64Binary, decodeBase64Url, decodeBase64UrlBinary, decodePercent, decodeSegment, documentExtensions, encodePathSegment, endsWithAnyOf, escapeHtml, escapeRegex, feedMimeTypes, fixMalformedHost, 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, isHostname, isHttpUrl, isInteger, isIpAddress, isJsonLike, isLocale, isLocaleOrRegion, isLocaleSegment, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isRegion, isRegionSegment, isSameText, isString, isSubdomainOf, isUtf8Binary, 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/locales.d.ts CHANGED
@@ -1,6 +1,11 @@
1
- import { LocaleSegmentOptions } from "./types.js";
1
+ import { LocaleOptions } from "./types.js";
2
2
  export declare const escapeHtml: (value: string) => string;
3
3
  export declare const t: (template: string, params: Record<string, string | number>) => string;
4
4
  export declare const tx: (template: string, params: Record<string, string | number>) => string;
5
- export declare const isLocaleSegment: (segment: string, options?: LocaleSegmentOptions) => boolean;
6
- export declare const isRegionSegment: (segment: string) => boolean;
5
+ export declare const isLocale: (value: string, options?: LocaleOptions) => boolean;
6
+ export declare const isRegion: (value: string) => boolean;
7
+ export declare const isLocaleOrRegion: (value: string, options?: LocaleOptions) => boolean;
8
+ /** @deprecated Use `isLocale` instead. */
9
+ export declare const isLocaleSegment: typeof isLocale;
10
+ /** @deprecated Use `isRegion` instead. */
11
+ export declare const isRegionSegment: typeof isRegion;
package/dist/locales.js CHANGED
@@ -32,9 +32,9 @@ const specialPurposeCodes = [
32
32
  "mul",
33
33
  "zxx"
34
34
  ];
35
- const isLocaleSegment = (segment, options) => {
36
- if (isAnyOf(segment, specialPurposeCodes)) return false;
37
- const tag = options?.underscore ? segment.replaceAll("_", "-") : segment;
35
+ const isLocale = (value, options) => {
36
+ if (isAnyOf(value, specialPurposeCodes)) return false;
37
+ const tag = options?.underscore ? value.replaceAll("_", "-") : value;
38
38
  try {
39
39
  return languageNames.of(tag) !== void 0;
40
40
  } catch {
@@ -51,12 +51,19 @@ const specialPurposeRegions = [
51
51
  "xa",
52
52
  "xb"
53
53
  ];
54
- const isRegionSegment = (segment) => {
55
- if (isAnyOf(segment, specialPurposeRegions)) return false;
54
+ const isRegion = (value) => {
55
+ if (isAnyOf(value, specialPurposeRegions)) return false;
56
56
  try {
57
- return regionNames.of(segment.toUpperCase()) !== void 0;
57
+ return regionNames.of(value.toUpperCase()) !== void 0;
58
58
  } catch {
59
59
  return false;
60
60
  }
61
61
  };
62
- export { escapeHtml, isLocaleSegment, isRegionSegment, t, tx };
62
+ const isLocaleOrRegion = (value, options) => {
63
+ return isLocale(value, options) || isRegion(value);
64
+ };
65
+ /** @deprecated Use `isLocale` instead. */
66
+ const isLocaleSegment = isLocale;
67
+ /** @deprecated Use `isRegion` instead. */
68
+ const isRegionSegment = isRegion;
69
+ export { escapeHtml, isLocale, isLocaleOrRegion, isLocaleSegment, isRegion, isRegionSegment, t, tx };
@@ -1,9 +1,9 @@
1
- import { Pattern } from "./types.js";
1
+ import { Nullish, Pattern } from "./types.js";
2
2
  export declare const escapeRegex: (value: string) => string;
3
- export declare const isAnyOf: (value: string | undefined, patterns: Pattern | ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
4
- export declare const isSameText: (value: string | undefined, other: string | undefined) => boolean;
5
- export declare const getAnyOf: <T extends string>(value: string | undefined, patterns: ReadonlyArray<T>, parser?: (value: string) => string) => T | undefined;
6
- export declare const includesAnyOf: (value: string | undefined, patterns: Pattern | ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
7
- export declare const startsWithAnyOf: (value: string | undefined, patterns: Pattern | ReadonlyArray<Pattern>) => boolean;
8
- export declare const endsWithAnyOf: (value: string | undefined, patterns: Pattern | ReadonlyArray<Pattern>) => boolean;
3
+ export declare const isAnyOf: (value: Nullish<string>, patterns: Pattern | ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
4
+ export declare const isSameText: (value: Nullish<string>, other: Nullish<string>) => boolean;
5
+ export declare const getAnyOf: <T extends string>(value: Nullish<string>, patterns: ReadonlyArray<T>, parser?: (value: string) => string) => T | undefined;
6
+ export declare const includesAnyOf: (value: Nullish<string>, patterns: Pattern | ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
7
+ export declare const startsWithAnyOf: (value: Nullish<string>, patterns: Pattern | ReadonlyArray<Pattern>) => boolean;
8
+ export declare const endsWithAnyOf: (value: Nullish<string>, patterns: Pattern | ReadonlyArray<Pattern>) => boolean;
9
9
  export declare const anyWordMatchesAnyOf: (value: string, patterns: ReadonlyArray<Pattern>) => boolean;
package/dist/types.d.ts CHANGED
@@ -11,9 +11,11 @@ export type ParamOptions = {
11
11
  trimValues?: boolean;
12
12
  preserveEmptyValues?: boolean;
13
13
  };
14
- export type LocaleSegmentOptions = {
14
+ export type LocaleOptions = {
15
15
  underscore?: boolean;
16
16
  };
17
+ /** @deprecated Use `LocaleOptions` instead. */
18
+ export type LocaleSegmentOptions = LocaleOptions;
17
19
  export type RegistrableDomainOptions = {
18
20
  suffixes?: ReadonlyArray<string>;
19
21
  };
package/dist/urls.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { isFunction, isNullish, isString } from "./is.js";
2
- import { isAnyOf, toPatternList } from "./matching.js";
2
+ import { includesAnyOf, isAnyOf, toPatternList } from "./matching.js";
3
3
  import { decodeHTMLStrict } from "entities";
4
4
  // src/urls.ts
5
5
  const httpSchemes = ["http:", "https:"];
@@ -289,7 +289,6 @@ const ipv6BracketsRegex = /^\[|\]$/g;
289
289
  const hostnameLabelRegex = /^[a-z0-9_-]+$/i;
290
290
  const fileExtensionRegex = /\.[a-z][a-z0-9]{0,5}$/i;
291
291
  const unreservedCharsRegex = /[a-zA-Z0-9._~-]/;
292
- const httpsLetterRegex = /s/i;
293
292
  const schemePrefixRegex = /^https?:\/\//;
294
293
  const percentEscapeOrLettersRegex = /%[0-9A-Fa-f]{2}|[A-Z]+/g;
295
294
  const plusRegex = /\+/g;
@@ -301,6 +300,7 @@ const leadingWhitespaceChars = [
301
300
  " ",
302
301
  "\n"
303
302
  ];
303
+ const httpsLetter = "s";
304
304
  const relativeLeadChars = [
305
305
  "/",
306
306
  ".",
@@ -317,8 +317,7 @@ const leadingSchemeSeparator = String.raw`\.*(?::${separatorChar}*|[\s=\\/]${sep
317
317
  const doubledSchemeRegex = /* @__PURE__ */ new RegExp(String.raw`^\/?[htps]{2,7}${leadingSchemeSeparator}([htps]{2,7})(?!:\d|[^/?#\\]*@)(${schemeSeparator})(www[./]+)?`, "i");
318
318
  const singleMalformedRegex = /* @__PURE__ */ new RegExp(String.raw`^\/?(h[htps():]{1,10}|t{1,2}ps?)(${leadingSchemeSeparator})(www[./]+)?`, "i");
319
319
  const isSchemeToken = (token, separator) => {
320
- const lowered = token.toLowerCase();
321
- return `${token}${separator}`.includes(":") || lowered.includes("t") && lowered.includes("p");
320
+ return `${token}${separator}`.includes(":") || includesAnyOf(token, "t") && includesAnyOf(token, "p");
322
321
  };
323
322
  const brokenSlashEscapeRegex = /^[^/]*\/[,.]/;
324
323
  const fixMalformedScheme = (url) => {
@@ -329,7 +328,7 @@ const fixMalformedScheme = (url) => {
329
328
  const www = doubledMatch[3];
330
329
  const rest = url.slice(doubledMatch[0].length);
331
330
  if (brokenSlashEscapeRegex.test(`${doubledMatch[2]}${rest}`)) return url;
332
- return `${httpsLetterRegex.test(inner) ? "https://" : "http://"}${www ? "www." : ""}${rest}`;
331
+ return `${includesAnyOf(inner, httpsLetter) ? "https://" : "http://"}${www ? "www." : ""}${rest}`;
333
332
  }
334
333
  const singleMatch = singleMalformedRegex.exec(url);
335
334
  if (singleMatch && isSchemeToken(singleMatch[1], singleMatch[2])) {
@@ -337,7 +336,7 @@ const fixMalformedScheme = (url) => {
337
336
  const www = singleMatch[3];
338
337
  const rest = url.slice(fullMatch.length);
339
338
  if (brokenSlashEscapeRegex.test(`${singleMatch[2]}${rest}`)) return url;
340
- return `${httpsLetterRegex.test(fullMatch) ? "https://" : "http://"}${www ? "www." : ""}${rest}`;
339
+ return `${includesAnyOf(fullMatch, httpsLetter) ? "https://" : "http://"}${www ? "www." : ""}${rest}`;
341
340
  }
342
341
  return url;
343
342
  };
package/package.json CHANGED
@@ -46,5 +46,5 @@
46
46
  "dependencies": {
47
47
  "entities": "^9.0.0"
48
48
  },
49
- "version": "3.14.0"
49
+ "version": "3.16.0"
50
50
  }