trousse 1.2.0 → 1.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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![npm version](https://img.shields.io/npm/v/trousse.svg)](https://www.npmjs.com/package/trousse)
5
5
  [![license](https://img.shields.io/npm/l/trousse.svg)](https://github.com/macieklamberski/trousse/blob/main/LICENSE)
6
6
 
7
- Personal toolbox of shared TypeScript utilities used across my projects: type guards, coercions, matching, array and locale interpolation helpers.
7
+ Personal toolbox of shared TypeScript utilities used across my projects: type guards, coercions, matching, array, object and locale interpolation helpers.
8
8
 
9
9
  ## Installation
10
10
 
package/dist/index.d.ts CHANGED
@@ -4,7 +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, includesAnyOf, isAnyOf, startsWithAnyOf } from "./matching.js";
7
+ import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, includesAnyOf, isAnyOf, startsWithAnyOf } from "./matching.js";
8
+ import { omit, pick } from "./objects.js";
8
9
  import { sleep } from "./timers.js";
9
10
  import { getPathSegments, isHostOf, isSubdomainOf, parseUrl } from "./urls.js";
10
- export { type MaybePromise, type Nullish, type PartialNullish, type Pattern, anyWordMatchesAnyOf, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, endsWithAnyOf, escapeHtml, getPathSegments, includesAnyOf, isAnyOf, isBoolean, isFunction, isHostOf, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isString, isSubdomainOf, isValidDate, omitEmpty, parseUrl, sleep, startsWithAnyOf, t, tx };
11
+ export { type MaybePromise, type Nullish, type PartialNullish, type Pattern, anyWordMatchesAnyOf, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, endsWithAnyOf, escapeHtml, escapeRegex, getPathSegments, includesAnyOf, isAnyOf, isBoolean, isFunction, isHostOf, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isString, isSubdomainOf, isValidDate, omit, omitEmpty, parseUrl, pick, sleep, startsWithAnyOf, t, tx };
package/dist/index.js CHANGED
@@ -3,7 +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, includesAnyOf, isAnyOf, startsWithAnyOf } from "./matching.js";
6
+ import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, includesAnyOf, isAnyOf, startsWithAnyOf } from "./matching.js";
7
+ import { omit, pick } from "./objects.js";
7
8
  import { sleep } from "./timers.js";
8
9
  import { getPathSegments, isHostOf, isSubdomainOf, parseUrl } from "./urls.js";
9
- export { anyWordMatchesAnyOf, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, endsWithAnyOf, escapeHtml, getPathSegments, includesAnyOf, isAnyOf, isBoolean, isFunction, isHostOf, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isString, isSubdomainOf, isValidDate, omitEmpty, parseUrl, sleep, startsWithAnyOf, t, tx };
10
+ export { anyWordMatchesAnyOf, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, endsWithAnyOf, escapeHtml, escapeRegex, getPathSegments, includesAnyOf, isAnyOf, isBoolean, isFunction, isHostOf, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isString, isSubdomainOf, isValidDate, omit, omitEmpty, parseUrl, pick, sleep, startsWithAnyOf, t, tx };
@@ -1,10 +1,11 @@
1
1
  import { Pattern } from "./types.js";
2
2
 
3
3
  //#region src/matching.d.ts
4
+ declare const escapeRegex: (value: string) => string;
4
5
  declare const isAnyOf: (value: string, patterns: ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
5
6
  declare const includesAnyOf: (value: string, patterns: ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
6
7
  declare const startsWithAnyOf: (value: string, patterns: ReadonlyArray<Pattern>) => boolean;
7
8
  declare const endsWithAnyOf: (value: string, patterns: ReadonlyArray<Pattern>) => boolean;
8
9
  declare const anyWordMatchesAnyOf: (value: string, patterns: ReadonlyArray<Pattern>) => boolean;
9
10
  //#endregion
10
- export { anyWordMatchesAnyOf, endsWithAnyOf, includesAnyOf, isAnyOf, startsWithAnyOf };
11
+ export { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, includesAnyOf, isAnyOf, startsWithAnyOf };
package/dist/matching.js CHANGED
@@ -1,5 +1,9 @@
1
1
  //#region src/matching.ts
2
2
  const whitespaceRegex = /\s+/;
3
+ const regexMetaCharsRegex = /[.*+?^${}()|[\]\\-]/g;
4
+ const escapeRegex = (value) => {
5
+ return value.replace(regexMetaCharsRegex, "\\$&");
6
+ };
3
7
  const isAnyOf = (value, patterns, parser) => {
4
8
  const parsedValue = parser ? parser(value) : value?.toLowerCase()?.trim();
5
9
  return patterns.some((pattern) => {
@@ -41,4 +45,4 @@ const anyWordMatchesAnyOf = (value, patterns) => {
41
45
  return false;
42
46
  };
43
47
  //#endregion
44
- export { anyWordMatchesAnyOf, endsWithAnyOf, includesAnyOf, isAnyOf, startsWithAnyOf };
48
+ export { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, includesAnyOf, isAnyOf, startsWithAnyOf };
@@ -0,0 +1,5 @@
1
+ //#region src/objects.d.ts
2
+ declare const pick: <T extends object, K extends keyof T>(object: T, keys: ReadonlyArray<K>) => Pick<T, K>;
3
+ declare const omit: <T extends object, K extends keyof T>(object: T, keys: ReadonlyArray<K>) => Omit<T, K>;
4
+ //#endregion
5
+ export { omit, pick };
@@ -0,0 +1,13 @@
1
+ //#region src/objects.ts
2
+ const pick = (object, keys) => {
3
+ const result = {};
4
+ for (const key of keys) if (key in object) result[key] = object[key];
5
+ return result;
6
+ };
7
+ const omit = (object, keys) => {
8
+ const result = { ...object };
9
+ for (const key of keys) delete result[key];
10
+ return result;
11
+ };
12
+ //#endregion
13
+ export { omit, pick };
package/package.json CHANGED
@@ -40,5 +40,5 @@
40
40
  "kvalita": "^1.15.0",
41
41
  "tsdown": "^0.22.2"
42
42
  },
43
- "version": "1.2.0"
43
+ "version": "1.4.0"
44
44
  }