trousse 1.3.0 → 1.5.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 +4 -4
- package/dist/index.js +3 -3
- package/dist/matching.d.ts +2 -1
- package/dist/matching.js +5 -1
- package/dist/objects.d.ts +4 -1
- package/dist/objects.js +19 -1
- package/dist/types.d.ts +4 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { omitEmpty } from "./arrays.js";
|
|
2
|
-
import { MaybePromise, Nullish, PartialNullish, Pattern } from "./types.js";
|
|
2
|
+
import { AnyOf, DeepOmit, IsPlainObject, MaybePromise, Nullish, PartialNullish, Pattern } from "./types.js";
|
|
3
3
|
import { coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString } from "./coercions.js";
|
|
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";
|
|
8
|
-
import { omit, pick } from "./objects.js";
|
|
7
|
+
import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, includesAnyOf, isAnyOf, startsWithAnyOf } from "./matching.js";
|
|
8
|
+
import { omit, pick, trimObject } from "./objects.js";
|
|
9
9
|
import { sleep } from "./timers.js";
|
|
10
10
|
import { getPathSegments, isHostOf, isSubdomainOf, parseUrl } from "./urls.js";
|
|
11
|
-
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, omit, omitEmpty, parseUrl, pick, sleep, startsWithAnyOf, t, tx };
|
|
11
|
+
export { type AnyOf, type DeepOmit, type IsPlainObject, 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, 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, includesAnyOf, isAnyOf, startsWithAnyOf } from "./matching.js";
|
|
7
|
-
import { omit, pick } from "./objects.js";
|
|
6
|
+
import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, includesAnyOf, isAnyOf, startsWithAnyOf } from "./matching.js";
|
|
7
|
+
import { omit, pick, trimObject } from "./objects.js";
|
|
8
8
|
import { sleep } from "./timers.js";
|
|
9
9
|
import { getPathSegments, isHostOf, isSubdomainOf, parseUrl } from "./urls.js";
|
|
10
|
-
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, omit, omitEmpty, parseUrl, pick, 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, trimObject, tx };
|
package/dist/matching.d.ts
CHANGED
|
@@ -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 };
|
package/dist/objects.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { AnyOf } from "./types.js";
|
|
2
|
+
|
|
1
3
|
//#region src/objects.d.ts
|
|
2
4
|
declare const pick: <T extends object, K extends keyof T>(object: T, keys: ReadonlyArray<K>) => Pick<T, K>;
|
|
3
5
|
declare const omit: <T extends object, K extends keyof T>(object: T, keys: ReadonlyArray<K>) => Omit<T, K>;
|
|
6
|
+
declare const trimObject: <T extends Record<string, unknown>>(object: T, keep?: (value: unknown) => boolean) => AnyOf<T> | undefined;
|
|
4
7
|
//#endregion
|
|
5
|
-
export { omit, pick };
|
|
8
|
+
export { omit, pick, trimObject };
|
package/dist/objects.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isPresent } from "./is.js";
|
|
1
2
|
//#region src/objects.ts
|
|
2
3
|
const pick = (object, keys) => {
|
|
3
4
|
const result = {};
|
|
@@ -9,5 +10,22 @@ const omit = (object, keys) => {
|
|
|
9
10
|
for (const key of keys) delete result[key];
|
|
10
11
|
return result;
|
|
11
12
|
};
|
|
13
|
+
const trimObject = (object, keep = isPresent) => {
|
|
14
|
+
let hasKept = false;
|
|
15
|
+
let hasDropped = false;
|
|
16
|
+
for (const key in object) {
|
|
17
|
+
if (keep(object[key])) hasKept = true;
|
|
18
|
+
else hasDropped = true;
|
|
19
|
+
if (hasKept && hasDropped) break;
|
|
20
|
+
}
|
|
21
|
+
if (!hasKept) return;
|
|
22
|
+
if (!hasDropped) return object;
|
|
23
|
+
const result = {};
|
|
24
|
+
for (const key in object) {
|
|
25
|
+
const value = object[key];
|
|
26
|
+
if (keep(value)) result[key] = value;
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
12
30
|
//#endregion
|
|
13
|
-
export { omit, pick };
|
|
31
|
+
export { omit, pick, trimObject };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
//#region src/types.d.ts
|
|
2
|
+
type AnyOf<T> = Partial<{ [Key in keyof T]-?: NonNullable<T[Key]> }> & { [Key in keyof T]-?: Pick<{ [InnerKey in keyof T]-?: NonNullable<T[InnerKey]> }, Key> }[keyof T];
|
|
3
|
+
type IsPlainObject<T> = T extends Array<unknown> ? false : T extends ((...args: Array<unknown>) => unknown) ? false : T extends Date ? false : T extends object ? T extends null ? false : true : false;
|
|
4
|
+
type DeepOmit<T, Keys extends string> = T extends Array<infer Item> ? Array<DeepOmit<Item, Keys>> : IsPlainObject<T> extends true ? Pick<{ [Key in keyof T]: DeepOmit<T[Key], Keys> }, Exclude<keyof T, Keys>> : T;
|
|
2
5
|
type Nullish<T> = T | null | undefined;
|
|
3
6
|
type PartialNullish<T> = { [Key in keyof T]?: Nullish<T[Key]> };
|
|
4
7
|
type MaybePromise<T> = T | Promise<T>;
|
|
5
8
|
type Pattern = string | RegExp;
|
|
6
9
|
//#endregion
|
|
7
|
-
export { MaybePromise, Nullish, PartialNullish, Pattern };
|
|
10
|
+
export { AnyOf, DeepOmit, IsPlainObject, MaybePromise, Nullish, PartialNullish, Pattern };
|
package/package.json
CHANGED