trousse 3.17.1 → 3.18.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,62 +13,3 @@ 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/arrays.d.ts CHANGED
@@ -1,2 +1,4 @@
1
- import { Nullish } from "./types.js";
2
- export declare const omitEmpty: <T>(array: Array<Nullish<T>>) => Array<T> | undefined;
1
+ import { Nullish, TrimOptions } from "./types.js";
2
+ export declare const trimArray: <T>(array: Array<Nullish<T>>, options?: TrimOptions) => Array<T> | undefined;
3
+ /** @deprecated Use `trimArray` instead. */
4
+ export declare const omitEmpty: typeof trimArray;
package/dist/arrays.js CHANGED
@@ -1,9 +1,16 @@
1
+ import { createTrimPredicate } from "./internal.js";
1
2
  import { isPresent } from "./is.js";
2
3
  // src/arrays.ts
3
- const omitEmpty = (array) => {
4
+ const isFilled = (value) => {
5
+ return value !== "";
6
+ };
7
+ const trimArray = (array, options = {}) => {
8
+ const keep = createTrimPredicate(options, isFilled);
4
9
  const result = [];
5
- for (const item of array) if (isPresent(item) && item !== "") result.push(item);
10
+ for (const item of array) if (isPresent(item) && keep(item)) result.push(item);
6
11
  if (!result.length) return;
7
12
  return result;
8
13
  };
9
- export { omitEmpty };
14
+ /** @deprecated Use `trimArray` instead. */
15
+ const omitEmpty = trimArray;
16
+ export { omitEmpty, trimArray };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
- import { omitEmpty } from "./arrays.js";
1
+ import { omitEmpty, trimArray } from "./arrays.js";
2
2
  import { coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString } from "./coercions.js";
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
6
  import { escapeHtml, isLocale, isLocaleOrRegion, isLocaleSegment, isRegion, isRegionSegment, t, tx } from "./locales.js";
7
- import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, isSameText, startsWithAnyOf } from "./matching.js";
7
+ import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, isLooseMatch, 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
+ import { trimString } from "./strings.js";
10
11
  import { sleep } from "./timers.js";
11
- import { AnyOf, DeepOmit, IsPlainObject, LocaleOptions, LocaleSegmentOptions, MaybePromise, NormalizeOptions, Nullish, ParamOptions, ParamSource, PartialNullish, Pattern, QueryParamPredicate, RegistrableDomainOptions, WeightedMimeType } from "./types.js";
12
+ import { AnyOf, DeepOmit, IsPlainObject, LocaleOptions, LocaleSegmentOptions, MaybePromise, NormalizeOptions, Nullish, ParamOptions, ParamSource, PartialNullish, Pattern, QueryParamPredicate, RegistrableDomainOptions, TrimOptions, TrimPredicate, WeightedMimeType } from "./types.js";
12
13
  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, isBrandDomainOf, 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 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, isBrandDomainOf, 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 };
14
+ 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 TrimOptions, type TrimPredicate, 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, isBrandDomainOf, isFiniteNumber, isFunction, isHostOf, isHostOrSubdomainOf, isHostname, isHttpUrl, isInteger, isIpAddress, isJsonLike, isLocale, isLocaleOrRegion, isLocaleSegment, isLooseMatch, 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, trimArray, trimObject, trimString, trimUrlValues, tx, upgradeProtocol, upgradeScheme, videoExtensions, webAudioExtensions, webImageExtensions, webVideoExtensions };
package/dist/index.js CHANGED
@@ -1,12 +1,13 @@
1
- import { omitEmpty } from "./arrays.js";
1
+ import { omitEmpty, trimArray } from "./arrays.js";
2
2
  import { coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString } from "./coercions.js";
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
6
  import { escapeHtml, isLocale, isLocaleOrRegion, isLocaleSegment, isRegion, isRegionSegment, t, tx } from "./locales.js";
7
- import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, isSameText, startsWithAnyOf } from "./matching.js";
7
+ import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, isLooseMatch, 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
+ import { trimString } from "./strings.js";
10
11
  import { sleep } from "./timers.js";
11
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, isBrandDomainOf, 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, isBrandDomainOf, 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 };
13
+ 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, isBrandDomainOf, isFiniteNumber, isFunction, isHostOf, isHostOrSubdomainOf, isHostname, isHttpUrl, isInteger, isIpAddress, isJsonLike, isLocale, isLocaleOrRegion, isLocaleSegment, isLooseMatch, 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, trimArray, trimObject, trimString, trimUrlValues, tx, upgradeProtocol, upgradeScheme, videoExtensions, webAudioExtensions, webImageExtensions, webVideoExtensions };
@@ -0,0 +1,3 @@
1
+ // src/internal/blank.ts
2
+ const blankCharacterClass = "[\\p{White_Space}\\uFEFF]";
3
+ export { blankCharacterClass };
@@ -0,0 +1,16 @@
1
+ import { blankCharacterClass } from "./internal/blank.js";
2
+ import { isNonEmptyString, isNullish, isString } from "./is.js";
3
+ // src/internal.ts
4
+ const toPatternList = (patterns) => {
5
+ return isString(patterns) || patterns instanceof RegExp ? [patterns] : patterns;
6
+ };
7
+ const createTrimPredicate = (options, fallback) => {
8
+ const keep = options.keep ?? fallback;
9
+ const isBlankDropped = options.blank;
10
+ return (value) => {
11
+ if (isNullish(value)) return false;
12
+ if (isBlankDropped && isString(value) && !isNonEmptyString(value)) return false;
13
+ return keep(value);
14
+ };
15
+ };
16
+ export { blankCharacterClass, createTrimPredicate, toPatternList };
package/dist/is.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { blankCharacterClass } from "./internal/blank.js";
1
2
  // src/is.ts
2
3
  const isString = (value) => {
3
4
  return typeof value === "string";
@@ -29,7 +30,7 @@ const isObject = (value) => {
29
30
  const isPlainObject = (value) => {
30
31
  return isObject(value) && Object.getPrototypeOf(value) === Object.prototype;
31
32
  };
32
- const whitespaceOnlyRegex = /^[\p{White_Space}\uFEFF]*$/u;
33
+ const whitespaceOnlyRegex = new RegExp(`^${blankCharacterClass}*$`, "u");
33
34
  const isNonEmptyString = (value) => {
34
35
  if (!isString(value) || !value) return false;
35
36
  const code = value.charCodeAt(0);
@@ -1,7 +1,9 @@
1
1
  import { Nullish, Pattern } from "./types.js";
2
2
  export declare const escapeRegex: (value: string) => string;
3
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;
4
+ export declare const isLooseMatch: (value: Nullish<string>, other: Nullish<string>) => boolean;
5
+ /** @deprecated Use `isLooseMatch` instead. */
6
+ export declare const isSameText: typeof isLooseMatch;
5
7
  export declare const getAnyOf: <T extends string>(value: Nullish<string>, patterns: ReadonlyArray<T>, parser?: (value: string) => string) => T | undefined;
6
8
  export declare const includesAnyOf: (value: Nullish<string>, patterns: Pattern | ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
7
9
  export declare const startsWithAnyOf: (value: Nullish<string>, patterns: Pattern | ReadonlyArray<Pattern>) => boolean;
package/dist/matching.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { toPatternList } from "./internal.js";
1
2
  import { isNullish, isString } from "./is.js";
2
3
  // src/matching.ts
3
4
  const whitespaceRegex = /\s+/;
@@ -10,9 +11,6 @@ const testRegex = (regex, value) => {
10
11
  const testRegexAnyCase = (regex, lowerValue, value) => {
11
12
  return testRegex(regex, lowerValue) || lowerValue !== value && testRegex(regex, value);
12
13
  };
13
- const toPatternList = (patterns) => {
14
- return isString(patterns) || patterns instanceof RegExp ? [patterns] : patterns;
15
- };
16
14
  const escapeRegex = (value) => {
17
15
  return value.replace(regexEscapableCharsRegex, (char) => {
18
16
  if (regexSyntaxCharsRegex.test(char)) return `\\${char}`;
@@ -34,10 +32,12 @@ const isAnyOf = (value, patterns, parser) => {
34
32
  }
35
33
  return false;
36
34
  };
37
- const isSameText = (value, other) => {
35
+ const isLooseMatch = (value, other) => {
38
36
  if (isNullish(value) || isNullish(other)) return false;
39
37
  return value.toLowerCase().trim() === other.toLowerCase().trim();
40
38
  };
39
+ /** @deprecated Use `isLooseMatch` instead. */
40
+ const isSameText = isLooseMatch;
41
41
  const getAnyOf = (value, patterns, parser) => {
42
42
  if (isNullish(value)) return;
43
43
  const parsedValue = parser ? parser(value) : value.toLowerCase().trim();
@@ -101,4 +101,4 @@ const anyWordMatchesAnyOf = (value, patterns) => {
101
101
  }
102
102
  return false;
103
103
  };
104
- export { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, isSameText, startsWithAnyOf, toPatternList };
104
+ export { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, isLooseMatch, isSameText, startsWithAnyOf };
package/dist/mimes.js CHANGED
@@ -93,7 +93,7 @@ const genericHtmlMimeTypes = [{
93
93
  mime: "*/*",
94
94
  quality: .8
95
95
  }];
96
- const createAcceptHeader = (types) => {
96
+ const createAcceptHeader = /* @__NO_SIDE_EFFECTS__ */ (types) => {
97
97
  return types.map((type) => {
98
98
  if (type.quality === 1) return type.mime;
99
99
  return `${type.mime};q=${type.quality}`;
package/dist/objects.d.ts CHANGED
@@ -1,5 +1,11 @@
1
- import { AnyOf } from "./types.js";
1
+ import { AnyOf, TrimOptions, TrimPredicate } from "./types.js";
2
2
  export declare const pick: <T extends object, K extends keyof T>(object: T, keys: ReadonlyArray<K>) => Pick<T, K>;
3
3
  export declare const omit: <T extends object, K extends keyof T>(object: T, keys: ReadonlyArray<K>) => Omit<T, K>;
4
- export declare const trimObject: <T extends Record<string, unknown>>(object: T, keep?: (value: unknown) => boolean) => AnyOf<T> | undefined;
5
- export declare const toMap: <V>(record: Record<string, V>) => Map<string, V>;
4
+ type TrimObject = {
5
+ <T extends Record<string, unknown>>(object: T, options?: TrimOptions): AnyOf<T> | undefined;
6
+ /** @deprecated Pass `{ keep }` instead. */
7
+ <T extends Record<string, unknown>>(object: T, keep: TrimPredicate): AnyOf<T> | undefined;
8
+ };
9
+ export declare const trimObject: TrimObject;
10
+ export declare const toMap: <V>(record: Record<string, V>) => Map<string, V>;
11
+ export {};
package/dist/objects.js CHANGED
@@ -1,4 +1,5 @@
1
- import { isPresent } from "./is.js";
1
+ import { createTrimPredicate } from "./internal.js";
2
+ import { isFunction, isPresent } from "./is.js";
2
3
  // src/objects.ts
3
4
  const setKey = (object, key, value) => {
4
5
  if (key === "__proto__") {
@@ -22,7 +23,8 @@ const omit = (object, keys) => {
22
23
  for (const key of keys) delete result[key];
23
24
  return result;
24
25
  };
25
- const trimObject = (object, keep = isPresent) => {
26
+ const trimObject = (object, options = {}) => {
27
+ const keep = createTrimPredicate(isFunction(options) ? { keep: options } : options, isPresent);
26
28
  let hasKept = false;
27
29
  let hasDropped = false;
28
30
  for (const key in object) {
@@ -39,7 +41,7 @@ const trimObject = (object, keep = isPresent) => {
39
41
  }
40
42
  return result;
41
43
  };
42
- const toMap = (record) => {
44
+ const toMap = /* @__NO_SIDE_EFFECTS__ */ (record) => {
43
45
  return new Map(Object.entries(record));
44
46
  };
45
47
  export { omit, pick, toMap, trimObject };
@@ -0,0 +1 @@
1
+ export declare const trimString: (value: unknown) => string | undefined;
@@ -0,0 +1,14 @@
1
+ import { blankCharacterClass } from "./internal/blank.js";
2
+ import { isString } from "./is.js";
3
+ // src/strings.ts
4
+ const blankCharRegex = new RegExp(blankCharacterClass, "u");
5
+ const trimString = (value) => {
6
+ if (!isString(value)) return;
7
+ let start = 0;
8
+ let end = value.length;
9
+ while (start < end && blankCharRegex.test(value.charAt(start))) start++;
10
+ while (end > start && blankCharRegex.test(value.charAt(end - 1))) end--;
11
+ if (start === end) return;
12
+ return value.slice(start, end);
13
+ };
14
+ export { trimString };
package/dist/types.d.ts CHANGED
@@ -42,4 +42,9 @@ export type NormalizeOptions = {
42
42
  export type WeightedMimeType = {
43
43
  mime: string;
44
44
  quality: number;
45
+ };
46
+ export type TrimPredicate = (value: unknown) => boolean;
47
+ export type TrimOptions = {
48
+ keep?: TrimPredicate;
49
+ blank?: boolean;
45
50
  };
package/dist/urls.js CHANGED
@@ -1,5 +1,6 @@
1
+ import { toPatternList } from "./internal.js";
1
2
  import { isFunction, isNullish, isString } from "./is.js";
2
- import { includesAnyOf, isAnyOf, toPatternList } from "./matching.js";
3
+ import { includesAnyOf, isAnyOf } from "./matching.js";
3
4
  import { decodeHTMLStrict } from "entities";
4
5
  // src/urls.ts
5
6
  const httpSchemes = ["http:", "https:"];
package/package.json CHANGED
@@ -46,5 +46,5 @@
46
46
  "dependencies": {
47
47
  "entities": "^9.0.0"
48
48
  },
49
- "version": "3.17.1"
49
+ "version": "3.18.0"
50
50
  }