trousse 2.2.0 → 2.3.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,7 +1,8 @@
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;
4
+ export declare const isAnyOf: (value: string, patterns: Pattern | ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
5
+ export declare const getAnyOf: <T extends string>(value: string, patterns: ReadonlyArray<T>, parser?: (value: string) => string) => T | undefined;
5
6
  export declare const includesAnyOf: (value: string, 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;
package/dist/matching.js CHANGED
@@ -6,11 +6,15 @@ const escapeRegex = (value) => {
6
6
  };
7
7
  const isAnyOf = (value, patterns, parser) => {
8
8
  const parsedValue = parser ? parser(value) : value?.toLowerCase()?.trim();
9
- return patterns.some((pattern) => {
9
+ return (typeof patterns === "string" || patterns instanceof RegExp ? [patterns] : patterns).some((pattern) => {
10
10
  if (pattern instanceof RegExp) return pattern.test(parsedValue);
11
11
  return parsedValue === pattern.toLowerCase().trim();
12
12
  });
13
13
  };
14
+ const getAnyOf = (value, patterns, parser) => {
15
+ const parsedValue = parser ? parser(value) : value?.toLowerCase()?.trim();
16
+ return patterns.find((pattern) => parsedValue === pattern.toLowerCase().trim());
17
+ };
14
18
  const includesAnyOf = (value, patterns, parser) => {
15
19
  const parsedValue = parser ? parser(value) : value?.toLowerCase();
16
20
  return patterns.some((pattern) => {
@@ -45,4 +49,4 @@ const anyWordMatchesAnyOf = (value, patterns) => {
45
49
  return false;
46
50
  };
47
51
  //#endregion
48
- export { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, includesAnyOf, isAnyOf, startsWithAnyOf };
52
+ export { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, startsWithAnyOf };
package/dist/urls.js CHANGED
@@ -29,7 +29,7 @@ const isHostOrSubdomainOf = (url, domains) => {
29
29
  return isHostOf(url, domains) || isSubdomainOf(url, domains);
30
30
  };
31
31
  const getSubdomain = (url, domains) => {
32
- const hostname = parseUrl(url)?.hostname;
32
+ const hostname = parseUrl(url)?.hostname.toLowerCase();
33
33
  if (!hostname) return;
34
34
  const list = typeof domains === "string" ? [domains] : domains;
35
35
  for (const domain of list) {
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.0"
46
+ "version": "2.3.0"
44
47
  }