trousse 2.2.1 → 2.4.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
@@ -4,8 +4,8 @@ import { coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, c
4
4
  import { isBoolean, isFunction, isNonEmptyString, isNullish, isNumber, isObject, isPlainObject, isPresent, isString, isValidDate } from "./is.js";
5
5
  import { isJsonLike, isParseableJson } from "./json.js";
6
6
  import { escapeHtml, t, tx } from "./locales.js";
7
- import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, includesAnyOf, isAnyOf, startsWithAnyOf } from "./matching.js";
7
+ import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, startsWithAnyOf } from "./matching.js";
8
8
  import { omit, pick, toMap, trimObject } from "./objects.js";
9
9
  import { sleep } from "./timers.js";
10
10
  import { decodeSegment, getPathSegments, getSubdomain, isHostOf, isHostOrSubdomainOf, isHttpUrl, isSubdomainOf, parseUrl } from "./urls.js";
11
- export { type AnyOf, type DeepOmit, type IsPlainObject, type MaybePromise, type Nullish, type PartialNullish, type Pattern, anyWordMatchesAnyOf, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, decodeSegment, endsWithAnyOf, escapeHtml, escapeRegex, getPathSegments, getSubdomain, includesAnyOf, isAnyOf, isBoolean, isFunction, isHostOf, isHostOrSubdomainOf, isHttpUrl, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isString, isSubdomainOf, isValidDate, omit, omitEmpty, parseUrl, pick, sleep, startsWithAnyOf, t, toMap, trimObject, tx };
11
+ export { type AnyOf, type DeepOmit, type IsPlainObject, type MaybePromise, type Nullish, type PartialNullish, type Pattern, anyWordMatchesAnyOf, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, decodeSegment, endsWithAnyOf, escapeHtml, escapeRegex, getAnyOf, getPathSegments, getSubdomain, includesAnyOf, isAnyOf, isBoolean, isFunction, isHostOf, isHostOrSubdomainOf, isHttpUrl, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isString, isSubdomainOf, isValidDate, omit, omitEmpty, parseUrl, pick, sleep, startsWithAnyOf, t, toMap, trimObject, tx };
package/dist/index.js CHANGED
@@ -3,8 +3,8 @@ import { omitEmpty } from "./arrays.js";
3
3
  import { coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString } from "./coercions.js";
4
4
  import { isJsonLike, isParseableJson } from "./json.js";
5
5
  import { escapeHtml, t, tx } from "./locales.js";
6
- import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, includesAnyOf, isAnyOf, startsWithAnyOf } from "./matching.js";
6
+ import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, startsWithAnyOf } from "./matching.js";
7
7
  import { omit, pick, toMap, trimObject } from "./objects.js";
8
8
  import { sleep } from "./timers.js";
9
9
  import { decodeSegment, getPathSegments, getSubdomain, isHostOf, isHostOrSubdomainOf, isHttpUrl, isSubdomainOf, parseUrl } from "./urls.js";
10
- export { anyWordMatchesAnyOf, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, decodeSegment, endsWithAnyOf, escapeHtml, escapeRegex, getPathSegments, getSubdomain, includesAnyOf, isAnyOf, isBoolean, isFunction, isHostOf, isHostOrSubdomainOf, isHttpUrl, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isString, isSubdomainOf, isValidDate, omit, omitEmpty, parseUrl, pick, sleep, startsWithAnyOf, t, toMap, trimObject, tx };
10
+ export { anyWordMatchesAnyOf, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, decodeSegment, endsWithAnyOf, escapeHtml, escapeRegex, getAnyOf, getPathSegments, getSubdomain, includesAnyOf, isAnyOf, isBoolean, isFunction, isHostOf, isHostOrSubdomainOf, isHttpUrl, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isString, isSubdomainOf, isValidDate, omit, omitEmpty, parseUrl, pick, sleep, startsWithAnyOf, t, toMap, trimObject, tx };
@@ -1,8 +1,9 @@
1
1
  import { Pattern } from "./types.js";
2
2
  //#region src/matching.d.ts
3
3
  export declare const escapeRegex: (value: string) => string;
4
- export declare const isAnyOf: (value: string, patterns: ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
5
- export declare const includesAnyOf: (value: string, patterns: ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
4
+ export declare const isAnyOf: (value: string | undefined, patterns: Pattern | ReadonlyArray<Pattern>, parser?: (value: string) => string) => 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: ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
6
7
  export declare const startsWithAnyOf: (value: string, patterns: ReadonlyArray<Pattern>) => boolean;
7
8
  export declare const endsWithAnyOf: (value: string, patterns: ReadonlyArray<Pattern>) => boolean;
8
9
  export declare const anyWordMatchesAnyOf: (value: string, patterns: ReadonlyArray<Pattern>) => boolean;
package/dist/matching.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { isNullish } from "./is.js";
1
2
  //#region src/matching.ts
2
3
  const whitespaceRegex = /\s+/;
3
4
  const regexMetaCharsRegex = /[.*+?^${}()|[\]\\-]/g;
@@ -5,17 +6,24 @@ const escapeRegex = (value) => {
5
6
  return value.replace(regexMetaCharsRegex, "\\$&");
6
7
  };
7
8
  const isAnyOf = (value, patterns, parser) => {
8
- const parsedValue = parser ? parser(value) : value?.toLowerCase()?.trim();
9
- return patterns.some((pattern) => {
9
+ if (isNullish(value)) return false;
10
+ const parsedValue = parser ? parser(value) : value.toLowerCase().trim();
11
+ return (typeof patterns === "string" || patterns instanceof RegExp ? [patterns] : patterns).some((pattern) => {
10
12
  if (pattern instanceof RegExp) return pattern.test(parsedValue);
11
13
  return parsedValue === pattern.toLowerCase().trim();
12
14
  });
13
15
  };
16
+ const getAnyOf = (value, patterns, parser) => {
17
+ if (isNullish(value)) return;
18
+ const parsedValue = parser ? parser(value) : value.toLowerCase().trim();
19
+ return patterns.find((pattern) => parsedValue === pattern.toLowerCase().trim());
20
+ };
14
21
  const includesAnyOf = (value, patterns, parser) => {
15
- const parsedValue = parser ? parser(value) : value?.toLowerCase();
22
+ if (isNullish(value)) return false;
23
+ const parsedValue = parser ? parser(value) : value.toLowerCase();
16
24
  return patterns.some((pattern) => {
17
25
  if (pattern instanceof RegExp) return pattern.test(parsedValue);
18
- return pattern && parsedValue?.includes(pattern.toLowerCase());
26
+ return pattern && parsedValue.includes(pattern.toLowerCase());
19
27
  });
20
28
  };
21
29
  const startsWithAnyOf = (value, patterns) => {
@@ -45,4 +53,4 @@ const anyWordMatchesAnyOf = (value, patterns) => {
45
53
  return false;
46
54
  };
47
55
  //#endregion
48
- export { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, includesAnyOf, isAnyOf, startsWithAnyOf };
56
+ export { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, startsWithAnyOf };
package/dist/urls.js CHANGED
@@ -13,7 +13,7 @@ const getPathSegments = (value) => {
13
13
  const isHostOf = (url, hosts) => {
14
14
  const hostname = parseUrl(url)?.hostname;
15
15
  if (!hostname) return false;
16
- return isAnyOf(hostname, typeof hosts === "string" ? [hosts] : hosts);
16
+ return isAnyOf(hostname, hosts);
17
17
  };
18
18
  const isSubdomainOf = (url, domains) => {
19
19
  const hostname = parseUrl(url)?.hostname;
package/package.json CHANGED
@@ -30,15 +30,18 @@
30
30
  "files": [
31
31
  "dist"
32
32
  ],
33
+ "engines": {
34
+ "node": ">=18"
35
+ },
33
36
  "scripts": {
34
37
  "prepare": "lefthook install",
35
38
  "build": "tsdown src/index.ts --format esm --dts --clean --unbundle --no-fixed-extension",
36
39
  "test": "bun test"
37
40
  },
38
41
  "devDependencies": {
39
- "@types/bun": "^1.4.1",
40
- "kvalita": "^1.21.0",
42
+ "@types/bun": "^1.4.2",
43
+ "kvalita": "^1.24.0",
41
44
  "tsdown": "^0.23.0"
42
45
  },
43
- "version": "2.2.1"
46
+ "version": "2.4.0"
44
47
  }