complete-common 2.15.0 โ 2.16.1
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/functions/array.d.cts +2 -2
- package/dist/functions/array.d.mts +2 -2
- package/dist/functions/array.d.ts +2 -2
- package/dist/functions/array.d.ts.map +1 -1
- package/dist/functions/assert.d.cts +27 -9
- package/dist/functions/assert.d.mts +27 -9
- package/dist/functions/assert.d.ts +27 -9
- package/dist/functions/assert.d.ts.map +1 -1
- package/dist/functions/object.d.cts +7 -2
- package/dist/functions/object.d.mts +7 -2
- package/dist/functions/object.d.ts +7 -2
- package/dist/functions/object.d.ts.map +1 -1
- package/dist/functions/string.d.cts +2 -2
- package/dist/functions/string.d.mts +2 -2
- package/dist/functions/string.d.ts +2 -2
- package/dist/functions/string.d.ts.map +1 -1
- package/dist/index.cjs +37 -19
- package/dist/index.mjs +37 -20
- package/package.json +1 -1
- package/src/functions/array.ts +4 -4
- package/src/functions/assert.ts +88 -44
- package/src/functions/object.ts +18 -2
- package/src/functions/string.test.ts +24 -0
- package/src/functions/string.ts +9 -5
|
@@ -76,7 +76,7 @@ export declare function filterAsync<T>(array: readonly T[], predicate: (element:
|
|
|
76
76
|
* This is named `filterMap` after the Rust function:
|
|
77
77
|
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
78
78
|
*/
|
|
79
|
-
export declare function filterMap<OldT, NewT>(array: readonly OldT[],
|
|
79
|
+
export declare function filterMap<OldT, NewT>(array: readonly OldT[], predicate: (element: OldT) => NewT | undefined): readonly NewT[];
|
|
80
80
|
/**
|
|
81
81
|
* Helper function to perform a filter and a map at the same time. Similar to `Array.map`, provide a
|
|
82
82
|
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
@@ -96,7 +96,7 @@ export declare function filterMap<OldT, NewT>(array: readonly OldT[], func: (ele
|
|
|
96
96
|
*
|
|
97
97
|
* (This is an abstraction around `Promise.all`.)
|
|
98
98
|
*/
|
|
99
|
-
export declare function filterMapAsync<OldT, NewT>(array: readonly OldT[],
|
|
99
|
+
export declare function filterMapAsync<OldT, NewT>(array: readonly OldT[], predicate: (element: OldT, index: number, array: readonly OldT[]) => Promise<NewT | undefined>): Promise<readonly NewT[]>;
|
|
100
100
|
/**
|
|
101
101
|
* Helper function to get a random element from the provided array.
|
|
102
102
|
*
|
|
@@ -76,7 +76,7 @@ export declare function filterAsync<T>(array: readonly T[], predicate: (element:
|
|
|
76
76
|
* This is named `filterMap` after the Rust function:
|
|
77
77
|
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
78
78
|
*/
|
|
79
|
-
export declare function filterMap<OldT, NewT>(array: readonly OldT[],
|
|
79
|
+
export declare function filterMap<OldT, NewT>(array: readonly OldT[], predicate: (element: OldT) => NewT | undefined): readonly NewT[];
|
|
80
80
|
/**
|
|
81
81
|
* Helper function to perform a filter and a map at the same time. Similar to `Array.map`, provide a
|
|
82
82
|
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
@@ -96,7 +96,7 @@ export declare function filterMap<OldT, NewT>(array: readonly OldT[], func: (ele
|
|
|
96
96
|
*
|
|
97
97
|
* (This is an abstraction around `Promise.all`.)
|
|
98
98
|
*/
|
|
99
|
-
export declare function filterMapAsync<OldT, NewT>(array: readonly OldT[],
|
|
99
|
+
export declare function filterMapAsync<OldT, NewT>(array: readonly OldT[], predicate: (element: OldT, index: number, array: readonly OldT[]) => Promise<NewT | undefined>): Promise<readonly NewT[]>;
|
|
100
100
|
/**
|
|
101
101
|
* Helper function to get a random element from the provided array.
|
|
102
102
|
*
|
|
@@ -76,7 +76,7 @@ export declare function filterAsync<T>(array: readonly T[], predicate: (element:
|
|
|
76
76
|
* This is named `filterMap` after the Rust function:
|
|
77
77
|
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
78
78
|
*/
|
|
79
|
-
export declare function filterMap<OldT, NewT>(array: readonly OldT[],
|
|
79
|
+
export declare function filterMap<OldT, NewT>(array: readonly OldT[], predicate: (element: OldT) => NewT | undefined): readonly NewT[];
|
|
80
80
|
/**
|
|
81
81
|
* Helper function to perform a filter and a map at the same time. Similar to `Array.map`, provide a
|
|
82
82
|
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
@@ -96,7 +96,7 @@ export declare function filterMap<OldT, NewT>(array: readonly OldT[], func: (ele
|
|
|
96
96
|
*
|
|
97
97
|
* (This is an abstraction around `Promise.all`.)
|
|
98
98
|
*/
|
|
99
|
-
export declare function filterMapAsync<OldT, NewT>(array: readonly OldT[],
|
|
99
|
+
export declare function filterMapAsync<OldT, NewT>(array: readonly OldT[], predicate: (element: OldT, index: number, array: readonly OldT[]) => Promise<NewT | undefined>): Promise<readonly NewT[]>;
|
|
100
100
|
/**
|
|
101
101
|
* Helper function to get a random element from the provided array.
|
|
102
102
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/functions/array.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAI7D;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EACvC,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC,GACjC,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC,CAQ7B;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,MAAM,EAAE,SAAS,CAAC,EAAE,EACpB,MAAM,EAAE,SAAS,CAAC,EAAE,GACnB,OAAO,CAST;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,aAAa,EAAE,SAAS,CAAC,EAAE,EAC3B,GAAG,gBAAgB,EAAE,SAAS,CAAC,EAAE,GAChC,SAAS,CAAC,EAAE,CAWd;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAErC,KAAK,EAAE,CAAC,EA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C,CAAC,GACvE,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAKvB;AAED,qFAAqF;AACrF,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,CAElE;AAED,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAEzD"}
|
|
@@ -5,29 +5,41 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { TranspiledEnum } from "../types/TranspiledEnum.js";
|
|
7
7
|
/** Helper function to throw an error if the provided value is not an array. */
|
|
8
|
-
export declare function assertArray(value:
|
|
8
|
+
export declare function assertArray<T>(value: T, ...[msg]: [T] extends [readonly unknown[]] ? [
|
|
9
|
+
"The assertion is useless because the provided value is already an array."
|
|
10
|
+
] : [string]): asserts value is T & unknown[];
|
|
9
11
|
/**
|
|
10
12
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
11
13
|
* a boolean.
|
|
12
14
|
*/
|
|
13
|
-
export declare function assertArrayBoolean(value:
|
|
15
|
+
export declare function assertArrayBoolean<T>(value: T, ...[msg]: [T] extends [readonly boolean[]] ? [
|
|
16
|
+
"The assertion is useless because the provided value is already a boolean array."
|
|
17
|
+
] : [string]): asserts value is T & boolean[];
|
|
14
18
|
/**
|
|
15
19
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
16
20
|
* a number.
|
|
17
21
|
*/
|
|
18
|
-
export declare function assertArrayNumber(value:
|
|
22
|
+
export declare function assertArrayNumber<T>(value: T, ...[msg]: [T] extends [readonly number[]] ? [
|
|
23
|
+
"The assertion is useless because the provided value is already a number array."
|
|
24
|
+
] : [string]): asserts value is T & number[];
|
|
19
25
|
/**
|
|
20
26
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
21
27
|
* an object (i.e. a TypeScript record).
|
|
22
28
|
*/
|
|
23
|
-
export declare function assertArrayObject(value:
|
|
29
|
+
export declare function assertArrayObject<T>(value: T, ...[msg]: [T] extends [ReadonlyArray<Record<string, unknown>>] ? [
|
|
30
|
+
"The assertion is useless because the provided value is already an object array."
|
|
31
|
+
] : [string]): asserts value is T & Array<Record<string, unknown>>;
|
|
24
32
|
/**
|
|
25
33
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
26
34
|
* a string.
|
|
27
35
|
*/
|
|
28
|
-
export declare function assertArrayString(value:
|
|
36
|
+
export declare function assertArrayString<T>(value: T, ...[msg]: [T] extends [readonly string[]] ? [
|
|
37
|
+
"The assertion is useless because the provided value is already a string array."
|
|
38
|
+
] : [string]): asserts value is T & string[];
|
|
29
39
|
/** Helper function to throw an error if the provided value is not a boolean. */
|
|
30
|
-
export declare function assertBoolean(value:
|
|
40
|
+
export declare function assertBoolean<T>(value: T, ...[msg]: [T] extends [boolean] ? [
|
|
41
|
+
"The assertion is useless because the provided value is already a boolean."
|
|
42
|
+
] : [string]): asserts value is T & boolean;
|
|
31
43
|
/**
|
|
32
44
|
* Helper function to throw an error if the provided value is equal to `undefined`.
|
|
33
45
|
*
|
|
@@ -64,7 +76,9 @@ export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T]
|
|
|
64
76
|
"The assertion is useless because the provided value does not contain null."
|
|
65
77
|
]): asserts value is Exclude<T, null>;
|
|
66
78
|
/** Helper function to throw an error if the provided value is not a number. */
|
|
67
|
-
export declare function assertNumber(value:
|
|
79
|
+
export declare function assertNumber<T>(value: T, ...[msg]: [T] extends [number] ? [
|
|
80
|
+
"The assertion is useless because the provided value is already a number."
|
|
81
|
+
] : [string]): asserts value is T & number;
|
|
68
82
|
/**
|
|
69
83
|
* Helper function to throw an error if the provided value is not an object (i.e. a TypeScript
|
|
70
84
|
* record).
|
|
@@ -74,9 +88,13 @@ export declare function assertNumber(value: unknown, msg: string): asserts value
|
|
|
74
88
|
*
|
|
75
89
|
* Under the hood, this function uses the `isObject` helper function.
|
|
76
90
|
*/
|
|
77
|
-
export declare function assertObject(value:
|
|
91
|
+
export declare function assertObject<T>(value: T, ...[msg]: [T] extends [Record<string, unknown>] ? [
|
|
92
|
+
"The assertion is useless because the provided value is already an object."
|
|
93
|
+
] : [string]): asserts value is T & Record<string, unknown>;
|
|
78
94
|
/** Helper function to throw an error if the provided value is not a string. */
|
|
79
|
-
export declare function assertString(value:
|
|
95
|
+
export declare function assertString<T>(value: T, ...[msg]: [T] extends [string] ? [
|
|
96
|
+
"The assertion is useless because the provided value is already a string."
|
|
97
|
+
] : [string]): asserts value is T & string;
|
|
80
98
|
/** Helper function to throw an error if the provided value is not a string or an empty string. */
|
|
81
99
|
export declare function assertStringNotEmpty(value: unknown, msg: string): asserts value is string;
|
|
82
100
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -5,29 +5,41 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { TranspiledEnum } from "../types/TranspiledEnum.js";
|
|
7
7
|
/** Helper function to throw an error if the provided value is not an array. */
|
|
8
|
-
export declare function assertArray(value:
|
|
8
|
+
export declare function assertArray<T>(value: T, ...[msg]: [T] extends [readonly unknown[]] ? [
|
|
9
|
+
"The assertion is useless because the provided value is already an array."
|
|
10
|
+
] : [string]): asserts value is T & unknown[];
|
|
9
11
|
/**
|
|
10
12
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
11
13
|
* a boolean.
|
|
12
14
|
*/
|
|
13
|
-
export declare function assertArrayBoolean(value:
|
|
15
|
+
export declare function assertArrayBoolean<T>(value: T, ...[msg]: [T] extends [readonly boolean[]] ? [
|
|
16
|
+
"The assertion is useless because the provided value is already a boolean array."
|
|
17
|
+
] : [string]): asserts value is T & boolean[];
|
|
14
18
|
/**
|
|
15
19
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
16
20
|
* a number.
|
|
17
21
|
*/
|
|
18
|
-
export declare function assertArrayNumber(value:
|
|
22
|
+
export declare function assertArrayNumber<T>(value: T, ...[msg]: [T] extends [readonly number[]] ? [
|
|
23
|
+
"The assertion is useless because the provided value is already a number array."
|
|
24
|
+
] : [string]): asserts value is T & number[];
|
|
19
25
|
/**
|
|
20
26
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
21
27
|
* an object (i.e. a TypeScript record).
|
|
22
28
|
*/
|
|
23
|
-
export declare function assertArrayObject(value:
|
|
29
|
+
export declare function assertArrayObject<T>(value: T, ...[msg]: [T] extends [ReadonlyArray<Record<string, unknown>>] ? [
|
|
30
|
+
"The assertion is useless because the provided value is already an object array."
|
|
31
|
+
] : [string]): asserts value is T & Array<Record<string, unknown>>;
|
|
24
32
|
/**
|
|
25
33
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
26
34
|
* a string.
|
|
27
35
|
*/
|
|
28
|
-
export declare function assertArrayString(value:
|
|
36
|
+
export declare function assertArrayString<T>(value: T, ...[msg]: [T] extends [readonly string[]] ? [
|
|
37
|
+
"The assertion is useless because the provided value is already a string array."
|
|
38
|
+
] : [string]): asserts value is T & string[];
|
|
29
39
|
/** Helper function to throw an error if the provided value is not a boolean. */
|
|
30
|
-
export declare function assertBoolean(value:
|
|
40
|
+
export declare function assertBoolean<T>(value: T, ...[msg]: [T] extends [boolean] ? [
|
|
41
|
+
"The assertion is useless because the provided value is already a boolean."
|
|
42
|
+
] : [string]): asserts value is T & boolean;
|
|
31
43
|
/**
|
|
32
44
|
* Helper function to throw an error if the provided value is equal to `undefined`.
|
|
33
45
|
*
|
|
@@ -64,7 +76,9 @@ export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T]
|
|
|
64
76
|
"The assertion is useless because the provided value does not contain null."
|
|
65
77
|
]): asserts value is Exclude<T, null>;
|
|
66
78
|
/** Helper function to throw an error if the provided value is not a number. */
|
|
67
|
-
export declare function assertNumber(value:
|
|
79
|
+
export declare function assertNumber<T>(value: T, ...[msg]: [T] extends [number] ? [
|
|
80
|
+
"The assertion is useless because the provided value is already a number."
|
|
81
|
+
] : [string]): asserts value is T & number;
|
|
68
82
|
/**
|
|
69
83
|
* Helper function to throw an error if the provided value is not an object (i.e. a TypeScript
|
|
70
84
|
* record).
|
|
@@ -74,9 +88,13 @@ export declare function assertNumber(value: unknown, msg: string): asserts value
|
|
|
74
88
|
*
|
|
75
89
|
* Under the hood, this function uses the `isObject` helper function.
|
|
76
90
|
*/
|
|
77
|
-
export declare function assertObject(value:
|
|
91
|
+
export declare function assertObject<T>(value: T, ...[msg]: [T] extends [Record<string, unknown>] ? [
|
|
92
|
+
"The assertion is useless because the provided value is already an object."
|
|
93
|
+
] : [string]): asserts value is T & Record<string, unknown>;
|
|
78
94
|
/** Helper function to throw an error if the provided value is not a string. */
|
|
79
|
-
export declare function assertString(value:
|
|
95
|
+
export declare function assertString<T>(value: T, ...[msg]: [T] extends [string] ? [
|
|
96
|
+
"The assertion is useless because the provided value is already a string."
|
|
97
|
+
] : [string]): asserts value is T & string;
|
|
80
98
|
/** Helper function to throw an error if the provided value is not a string or an empty string. */
|
|
81
99
|
export declare function assertStringNotEmpty(value: unknown, msg: string): asserts value is string;
|
|
82
100
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -5,29 +5,41 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { TranspiledEnum } from "../types/TranspiledEnum.js";
|
|
7
7
|
/** Helper function to throw an error if the provided value is not an array. */
|
|
8
|
-
export declare function assertArray(value:
|
|
8
|
+
export declare function assertArray<T>(value: T, ...[msg]: [T] extends [readonly unknown[]] ? [
|
|
9
|
+
"The assertion is useless because the provided value is already an array."
|
|
10
|
+
] : [string]): asserts value is T & unknown[];
|
|
9
11
|
/**
|
|
10
12
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
11
13
|
* a boolean.
|
|
12
14
|
*/
|
|
13
|
-
export declare function assertArrayBoolean(value:
|
|
15
|
+
export declare function assertArrayBoolean<T>(value: T, ...[msg]: [T] extends [readonly boolean[]] ? [
|
|
16
|
+
"The assertion is useless because the provided value is already a boolean array."
|
|
17
|
+
] : [string]): asserts value is T & boolean[];
|
|
14
18
|
/**
|
|
15
19
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
16
20
|
* a number.
|
|
17
21
|
*/
|
|
18
|
-
export declare function assertArrayNumber(value:
|
|
22
|
+
export declare function assertArrayNumber<T>(value: T, ...[msg]: [T] extends [readonly number[]] ? [
|
|
23
|
+
"The assertion is useless because the provided value is already a number array."
|
|
24
|
+
] : [string]): asserts value is T & number[];
|
|
19
25
|
/**
|
|
20
26
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
21
27
|
* an object (i.e. a TypeScript record).
|
|
22
28
|
*/
|
|
23
|
-
export declare function assertArrayObject(value:
|
|
29
|
+
export declare function assertArrayObject<T>(value: T, ...[msg]: [T] extends [ReadonlyArray<Record<string, unknown>>] ? [
|
|
30
|
+
"The assertion is useless because the provided value is already an object array."
|
|
31
|
+
] : [string]): asserts value is T & Array<Record<string, unknown>>;
|
|
24
32
|
/**
|
|
25
33
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
26
34
|
* a string.
|
|
27
35
|
*/
|
|
28
|
-
export declare function assertArrayString(value:
|
|
36
|
+
export declare function assertArrayString<T>(value: T, ...[msg]: [T] extends [readonly string[]] ? [
|
|
37
|
+
"The assertion is useless because the provided value is already a string array."
|
|
38
|
+
] : [string]): asserts value is T & string[];
|
|
29
39
|
/** Helper function to throw an error if the provided value is not a boolean. */
|
|
30
|
-
export declare function assertBoolean(value:
|
|
40
|
+
export declare function assertBoolean<T>(value: T, ...[msg]: [T] extends [boolean] ? [
|
|
41
|
+
"The assertion is useless because the provided value is already a boolean."
|
|
42
|
+
] : [string]): asserts value is T & boolean;
|
|
31
43
|
/**
|
|
32
44
|
* Helper function to throw an error if the provided value is equal to `undefined`.
|
|
33
45
|
*
|
|
@@ -64,7 +76,9 @@ export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T]
|
|
|
64
76
|
"The assertion is useless because the provided value does not contain null."
|
|
65
77
|
]): asserts value is Exclude<T, null>;
|
|
66
78
|
/** Helper function to throw an error if the provided value is not a number. */
|
|
67
|
-
export declare function assertNumber(value:
|
|
79
|
+
export declare function assertNumber<T>(value: T, ...[msg]: [T] extends [number] ? [
|
|
80
|
+
"The assertion is useless because the provided value is already a number."
|
|
81
|
+
] : [string]): asserts value is T & number;
|
|
68
82
|
/**
|
|
69
83
|
* Helper function to throw an error if the provided value is not an object (i.e. a TypeScript
|
|
70
84
|
* record).
|
|
@@ -74,9 +88,13 @@ export declare function assertNumber(value: unknown, msg: string): asserts value
|
|
|
74
88
|
*
|
|
75
89
|
* Under the hood, this function uses the `isObject` helper function.
|
|
76
90
|
*/
|
|
77
|
-
export declare function assertObject(value:
|
|
91
|
+
export declare function assertObject<T>(value: T, ...[msg]: [T] extends [Record<string, unknown>] ? [
|
|
92
|
+
"The assertion is useless because the provided value is already an object."
|
|
93
|
+
] : [string]): asserts value is T & Record<string, unknown>;
|
|
78
94
|
/** Helper function to throw an error if the provided value is not a string. */
|
|
79
|
-
export declare function assertString(value:
|
|
95
|
+
export declare function assertString<T>(value: T, ...[msg]: [T] extends [string] ? [
|
|
96
|
+
"The assertion is useless because the provided value is already a string."
|
|
97
|
+
] : [string]): asserts value is T & string;
|
|
80
98
|
/** Helper function to throw an error if the provided value is not a string or an empty string. */
|
|
81
99
|
export declare function assertStringNotEmpty(value: unknown, msg: string): asserts value is string;
|
|
82
100
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/functions/assert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAIjE,+EAA+E;AAC/E,wBAAgB,WAAW,
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/functions/assert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAIjE,+EAA+E;AAC/E,wBAAgB,W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K,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,MAAM,CAMzB"}
|
|
@@ -6,13 +6,18 @@
|
|
|
6
6
|
import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
7
7
|
/**
|
|
8
8
|
* Helper function to get the values in an object that match an arbitrary condition. Similar to the
|
|
9
|
-
* `Array.
|
|
9
|
+
* `Array.filter` method, but works for objects.
|
|
10
10
|
*
|
|
11
11
|
* This is efficient such that it avoids converting the object values into an array.
|
|
12
12
|
*/
|
|
13
13
|
export declare function objectFilter<K extends string | number | symbol, V>(object: ReadonlyRecord<K, V>, predicate: (value: V) => boolean): readonly V[];
|
|
14
14
|
/**
|
|
15
|
-
* Helper function to
|
|
15
|
+
* Helper function to map the values in an object to another object with new values. Similar to the
|
|
16
|
+
* `Array.map` method, but works for objects.
|
|
17
|
+
*/
|
|
18
|
+
export declare function objectMap<K extends string | number | symbol, V, U>(object: Record<K, V>, callback: (key: K, value: V) => U): ReadonlyRecord<K, U>;
|
|
19
|
+
/**
|
|
20
|
+
* Helper function to convert an object to a `Map`.
|
|
16
21
|
*
|
|
17
22
|
* This is useful when you need to construct a type safe object with the `satisfies` operator, but
|
|
18
23
|
* then later on you need to query it in a way where you expect the return value to be T or
|
|
@@ -6,13 +6,18 @@
|
|
|
6
6
|
import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
7
7
|
/**
|
|
8
8
|
* Helper function to get the values in an object that match an arbitrary condition. Similar to the
|
|
9
|
-
* `Array.
|
|
9
|
+
* `Array.filter` method, but works for objects.
|
|
10
10
|
*
|
|
11
11
|
* This is efficient such that it avoids converting the object values into an array.
|
|
12
12
|
*/
|
|
13
13
|
export declare function objectFilter<K extends string | number | symbol, V>(object: ReadonlyRecord<K, V>, predicate: (value: V) => boolean): readonly V[];
|
|
14
14
|
/**
|
|
15
|
-
* Helper function to
|
|
15
|
+
* Helper function to map the values in an object to another object with new values. Similar to the
|
|
16
|
+
* `Array.map` method, but works for objects.
|
|
17
|
+
*/
|
|
18
|
+
export declare function objectMap<K extends string | number | symbol, V, U>(object: Record<K, V>, callback: (key: K, value: V) => U): ReadonlyRecord<K, U>;
|
|
19
|
+
/**
|
|
20
|
+
* Helper function to convert an object to a `Map`.
|
|
16
21
|
*
|
|
17
22
|
* This is useful when you need to construct a type safe object with the `satisfies` operator, but
|
|
18
23
|
* then later on you need to query it in a way where you expect the return value to be T or
|
|
@@ -6,13 +6,18 @@
|
|
|
6
6
|
import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
7
7
|
/**
|
|
8
8
|
* Helper function to get the values in an object that match an arbitrary condition. Similar to the
|
|
9
|
-
* `Array.
|
|
9
|
+
* `Array.filter` method, but works for objects.
|
|
10
10
|
*
|
|
11
11
|
* This is efficient such that it avoids converting the object values into an array.
|
|
12
12
|
*/
|
|
13
13
|
export declare function objectFilter<K extends string | number | symbol, V>(object: ReadonlyRecord<K, V>, predicate: (value: V) => boolean): readonly V[];
|
|
14
14
|
/**
|
|
15
|
-
* Helper function to
|
|
15
|
+
* Helper function to map the values in an object to another object with new values. Similar to the
|
|
16
|
+
* `Array.map` method, but works for objects.
|
|
17
|
+
*/
|
|
18
|
+
export declare function objectMap<K extends string | number | symbol, V, U>(object: Record<K, V>, callback: (key: K, value: V) => U): ReadonlyRecord<K, U>;
|
|
19
|
+
/**
|
|
20
|
+
* Helper function to convert an object to a `Map`.
|
|
16
21
|
*
|
|
17
22
|
* This is useful when you need to construct a type safe object with the `satisfies` operator, but
|
|
18
23
|
* then later on you need to query it in a way where you expect the return value to be T or
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/functions/object.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,MAA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AC,GAChC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAOtB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EAC/D,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACnB,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAQnB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAClC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAClC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAQzC"}
|
|
@@ -87,7 +87,7 @@ export declare function parseSemanticVersion(versionString: string): {
|
|
|
87
87
|
*
|
|
88
88
|
* For example, by using a marker of "@foo":
|
|
89
89
|
*
|
|
90
|
-
* ```
|
|
90
|
+
* ```txt
|
|
91
91
|
* line1
|
|
92
92
|
* # @foo-start
|
|
93
93
|
* line2
|
|
@@ -98,7 +98,7 @@ export declare function parseSemanticVersion(versionString: string): {
|
|
|
98
98
|
*
|
|
99
99
|
* Would return:
|
|
100
100
|
*
|
|
101
|
-
* ```
|
|
101
|
+
* ```txt
|
|
102
102
|
* line1
|
|
103
103
|
* line4
|
|
104
104
|
* ```
|
|
@@ -87,7 +87,7 @@ export declare function parseSemanticVersion(versionString: string): {
|
|
|
87
87
|
*
|
|
88
88
|
* For example, by using a marker of "@foo":
|
|
89
89
|
*
|
|
90
|
-
* ```
|
|
90
|
+
* ```txt
|
|
91
91
|
* line1
|
|
92
92
|
* # @foo-start
|
|
93
93
|
* line2
|
|
@@ -98,7 +98,7 @@ export declare function parseSemanticVersion(versionString: string): {
|
|
|
98
98
|
*
|
|
99
99
|
* Would return:
|
|
100
100
|
*
|
|
101
|
-
* ```
|
|
101
|
+
* ```txt
|
|
102
102
|
* line1
|
|
103
103
|
* line4
|
|
104
104
|
* ```
|
|
@@ -87,7 +87,7 @@ export declare function parseSemanticVersion(versionString: string): {
|
|
|
87
87
|
*
|
|
88
88
|
* For example, by using a marker of "@foo":
|
|
89
89
|
*
|
|
90
|
-
* ```
|
|
90
|
+
* ```txt
|
|
91
91
|
* line1
|
|
92
92
|
* # @foo-start
|
|
93
93
|
* line2
|
|
@@ -98,7 +98,7 @@ export declare function parseSemanticVersion(versionString: string): {
|
|
|
98
98
|
*
|
|
99
99
|
* Would return:
|
|
100
100
|
*
|
|
101
|
-
* ```
|
|
101
|
+
* ```txt
|
|
102
102
|
* line1
|
|
103
103
|
* line4
|
|
104
104
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/functions/string.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/functions/string.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA8BH,kEAAkE;AAClE,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAU5D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAO3D;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAqBlE;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAOpD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAErD;AAED,+EAA+E;AAC/E,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE5C;AAED;;;GAGG;AACH,wBAAgB,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qF;AACrF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAK3D;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,UAAQ,GACd,MAAM,CAWR;AAED,gGAAgG;AAChG,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAOjE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAMxE"}
|
package/dist/index.cjs
CHANGED
|
@@ -36,36 +36,44 @@ function isObject(variable) {
|
|
|
36
36
|
return typeof variable === "object" && variable !== null && !Array.isArray(variable);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
function assertArray(value, msg) {
|
|
39
|
+
function assertArray(value, ...[msg]) {
|
|
40
40
|
if (!Array.isArray(value)) {
|
|
41
41
|
throw new TypeError(msg);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
function assertArrayBoolean(value, msg) {
|
|
45
|
-
|
|
44
|
+
function assertArrayBoolean(value, ...[msg]) {
|
|
45
|
+
if (!Array.isArray(value)) {
|
|
46
|
+
throw new TypeError(msg);
|
|
47
|
+
}
|
|
46
48
|
if (value.some((element) => typeof element !== "boolean")) {
|
|
47
49
|
throw new TypeError(msg);
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
|
-
function assertArrayNumber(value, msg) {
|
|
51
|
-
|
|
52
|
+
function assertArrayNumber(value, ...[msg]) {
|
|
53
|
+
if (!Array.isArray(value)) {
|
|
54
|
+
throw new TypeError(msg);
|
|
55
|
+
}
|
|
52
56
|
if (value.some((element) => typeof element !== "number")) {
|
|
53
57
|
throw new TypeError(msg);
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
|
-
function assertArrayObject(value, msg) {
|
|
57
|
-
|
|
60
|
+
function assertArrayObject(value, ...[msg]) {
|
|
61
|
+
if (!Array.isArray(value)) {
|
|
62
|
+
throw new TypeError(msg);
|
|
63
|
+
}
|
|
58
64
|
if (value.some((element) => !isObject(element))) {
|
|
59
65
|
throw new TypeError(msg);
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
|
-
function assertArrayString(value, msg) {
|
|
63
|
-
|
|
68
|
+
function assertArrayString(value, ...[msg]) {
|
|
69
|
+
if (!Array.isArray(value)) {
|
|
70
|
+
throw new TypeError(msg);
|
|
71
|
+
}
|
|
64
72
|
if (value.some((element) => typeof element !== "string")) {
|
|
65
73
|
throw new TypeError(msg);
|
|
66
74
|
}
|
|
67
75
|
}
|
|
68
|
-
function assertBoolean(value, msg) {
|
|
76
|
+
function assertBoolean(value, ...[msg]) {
|
|
69
77
|
if (typeof value !== "boolean") {
|
|
70
78
|
throw new TypeError(msg);
|
|
71
79
|
}
|
|
@@ -95,17 +103,17 @@ function assertNotNull(value, ...[msg]) {
|
|
|
95
103
|
throw new TypeError(msg);
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
|
-
function assertNumber(value, msg) {
|
|
106
|
+
function assertNumber(value, ...[msg]) {
|
|
99
107
|
if (typeof value !== "number") {
|
|
100
108
|
throw new TypeError(msg);
|
|
101
109
|
}
|
|
102
110
|
}
|
|
103
|
-
function assertObject(value, msg) {
|
|
111
|
+
function assertObject(value, ...[msg]) {
|
|
104
112
|
if (!isObject(value)) {
|
|
105
113
|
throw new TypeError(msg);
|
|
106
114
|
}
|
|
107
115
|
}
|
|
108
|
-
function assertString(value, msg) {
|
|
116
|
+
function assertString(value, ...[msg]) {
|
|
109
117
|
if (typeof value !== "string") {
|
|
110
118
|
throw new TypeError(msg);
|
|
111
119
|
}
|
|
@@ -194,19 +202,19 @@ async function filterAsync(array, predicate) {
|
|
|
194
202
|
);
|
|
195
203
|
return array.filter((_, index) => results[index] === true);
|
|
196
204
|
}
|
|
197
|
-
function filterMap(array,
|
|
205
|
+
function filterMap(array, predicate) {
|
|
198
206
|
const filteredArray = [];
|
|
199
207
|
for (const element of array) {
|
|
200
|
-
const newElement =
|
|
208
|
+
const newElement = predicate(element);
|
|
201
209
|
if (newElement !== void 0) {
|
|
202
210
|
filteredArray.push(newElement);
|
|
203
211
|
}
|
|
204
212
|
}
|
|
205
213
|
return filteredArray;
|
|
206
214
|
}
|
|
207
|
-
async function filterMapAsync(array,
|
|
215
|
+
async function filterMapAsync(array, predicate) {
|
|
208
216
|
const promises = array.map(
|
|
209
|
-
async (element, index) => await
|
|
217
|
+
async (element, index) => await predicate(element, index, array)
|
|
210
218
|
);
|
|
211
219
|
const results = await Promise.all(promises);
|
|
212
220
|
return results.filter((item) => item !== void 0);
|
|
@@ -310,6 +318,14 @@ function objectFilter(object, predicate) {
|
|
|
310
318
|
}
|
|
311
319
|
return array;
|
|
312
320
|
}
|
|
321
|
+
function objectMap(object, callback) {
|
|
322
|
+
const entries = Object.entries(object);
|
|
323
|
+
const mappedEntries = entries.map(([key, value]) => [
|
|
324
|
+
key,
|
|
325
|
+
callback(key, value)
|
|
326
|
+
]);
|
|
327
|
+
return Object.fromEntries(mappedEntries);
|
|
328
|
+
}
|
|
313
329
|
function objectToMap(object) {
|
|
314
330
|
const map = /* @__PURE__ */ new Map();
|
|
315
331
|
for (const [key, value] of Object.entries(object)) {
|
|
@@ -441,7 +457,8 @@ const EMOJI_REGEX = /(\p{Extended_Pictographic}|[#*0-9]\uFE0F?\u20E3)/u;
|
|
|
441
457
|
const FIRST_LETTER_CAPITALIZED_REGEX = /^\p{Lu}/u;
|
|
442
458
|
const KEBAB_CASE_REGEX = /^[\da-z]+(?:-[\da-z]+)*$/;
|
|
443
459
|
const SEMANTIC_VERSION_REGEX = /^v*(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/;
|
|
444
|
-
const WHITESPACE_REGEX = /\s
|
|
460
|
+
const WHITESPACE_REGEX = /\s/;
|
|
461
|
+
const WHITESPACE_GLOBAL_REGEX = /\s/g;
|
|
445
462
|
const TITLE_CASE_BOUNDARY_REGEX = /(?<=[\da-z])(?=[A-Z])/g;
|
|
446
463
|
const UPPERCASE_REGEX = /^[A-Z]*$/;
|
|
447
464
|
const LOWERCASE_REGEX = /^[a-z]*$/;
|
|
@@ -566,7 +583,7 @@ function removeNonPrintableCharacters(string) {
|
|
|
566
583
|
return string.replaceAll(/\p{C}/gu, "");
|
|
567
584
|
}
|
|
568
585
|
function removeWhitespace(string) {
|
|
569
|
-
return string.replaceAll(
|
|
586
|
+
return string.replaceAll(WHITESPACE_GLOBAL_REGEX, "");
|
|
570
587
|
}
|
|
571
588
|
function titleCaseToKebabCase(string) {
|
|
572
589
|
return string.replaceAll(TITLE_CASE_BOUNDARY_REGEX, "-").replaceAll(/ +/g, "-").toLowerCase();
|
|
@@ -685,6 +702,7 @@ exports.noop = noop;
|
|
|
685
702
|
exports.normalizeString = normalizeString;
|
|
686
703
|
exports.objectFilter = objectFilter;
|
|
687
704
|
exports.objectKeysToSet = objectKeysToSet;
|
|
705
|
+
exports.objectMap = objectMap;
|
|
688
706
|
exports.objectToMap = objectToMap;
|
|
689
707
|
exports.objectToReverseMap = objectToReverseMap;
|
|
690
708
|
exports.objectValuesToSet = objectValuesToSet;
|
package/dist/index.mjs
CHANGED
|
@@ -34,36 +34,44 @@ function isObject(variable) {
|
|
|
34
34
|
return typeof variable === "object" && variable !== null && !Array.isArray(variable);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
function assertArray(value, msg) {
|
|
37
|
+
function assertArray(value, ...[msg]) {
|
|
38
38
|
if (!Array.isArray(value)) {
|
|
39
39
|
throw new TypeError(msg);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
function assertArrayBoolean(value, msg) {
|
|
43
|
-
|
|
42
|
+
function assertArrayBoolean(value, ...[msg]) {
|
|
43
|
+
if (!Array.isArray(value)) {
|
|
44
|
+
throw new TypeError(msg);
|
|
45
|
+
}
|
|
44
46
|
if (value.some((element) => typeof element !== "boolean")) {
|
|
45
47
|
throw new TypeError(msg);
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
|
-
function assertArrayNumber(value, msg) {
|
|
49
|
-
|
|
50
|
+
function assertArrayNumber(value, ...[msg]) {
|
|
51
|
+
if (!Array.isArray(value)) {
|
|
52
|
+
throw new TypeError(msg);
|
|
53
|
+
}
|
|
50
54
|
if (value.some((element) => typeof element !== "number")) {
|
|
51
55
|
throw new TypeError(msg);
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
|
-
function assertArrayObject(value, msg) {
|
|
55
|
-
|
|
58
|
+
function assertArrayObject(value, ...[msg]) {
|
|
59
|
+
if (!Array.isArray(value)) {
|
|
60
|
+
throw new TypeError(msg);
|
|
61
|
+
}
|
|
56
62
|
if (value.some((element) => !isObject(element))) {
|
|
57
63
|
throw new TypeError(msg);
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
|
-
function assertArrayString(value, msg) {
|
|
61
|
-
|
|
66
|
+
function assertArrayString(value, ...[msg]) {
|
|
67
|
+
if (!Array.isArray(value)) {
|
|
68
|
+
throw new TypeError(msg);
|
|
69
|
+
}
|
|
62
70
|
if (value.some((element) => typeof element !== "string")) {
|
|
63
71
|
throw new TypeError(msg);
|
|
64
72
|
}
|
|
65
73
|
}
|
|
66
|
-
function assertBoolean(value, msg) {
|
|
74
|
+
function assertBoolean(value, ...[msg]) {
|
|
67
75
|
if (typeof value !== "boolean") {
|
|
68
76
|
throw new TypeError(msg);
|
|
69
77
|
}
|
|
@@ -93,17 +101,17 @@ function assertNotNull(value, ...[msg]) {
|
|
|
93
101
|
throw new TypeError(msg);
|
|
94
102
|
}
|
|
95
103
|
}
|
|
96
|
-
function assertNumber(value, msg) {
|
|
104
|
+
function assertNumber(value, ...[msg]) {
|
|
97
105
|
if (typeof value !== "number") {
|
|
98
106
|
throw new TypeError(msg);
|
|
99
107
|
}
|
|
100
108
|
}
|
|
101
|
-
function assertObject(value, msg) {
|
|
109
|
+
function assertObject(value, ...[msg]) {
|
|
102
110
|
if (!isObject(value)) {
|
|
103
111
|
throw new TypeError(msg);
|
|
104
112
|
}
|
|
105
113
|
}
|
|
106
|
-
function assertString(value, msg) {
|
|
114
|
+
function assertString(value, ...[msg]) {
|
|
107
115
|
if (typeof value !== "string") {
|
|
108
116
|
throw new TypeError(msg);
|
|
109
117
|
}
|
|
@@ -192,19 +200,19 @@ async function filterAsync(array, predicate) {
|
|
|
192
200
|
);
|
|
193
201
|
return array.filter((_, index) => results[index] === true);
|
|
194
202
|
}
|
|
195
|
-
function filterMap(array,
|
|
203
|
+
function filterMap(array, predicate) {
|
|
196
204
|
const filteredArray = [];
|
|
197
205
|
for (const element of array) {
|
|
198
|
-
const newElement =
|
|
206
|
+
const newElement = predicate(element);
|
|
199
207
|
if (newElement !== void 0) {
|
|
200
208
|
filteredArray.push(newElement);
|
|
201
209
|
}
|
|
202
210
|
}
|
|
203
211
|
return filteredArray;
|
|
204
212
|
}
|
|
205
|
-
async function filterMapAsync(array,
|
|
213
|
+
async function filterMapAsync(array, predicate) {
|
|
206
214
|
const promises = array.map(
|
|
207
|
-
async (element, index) => await
|
|
215
|
+
async (element, index) => await predicate(element, index, array)
|
|
208
216
|
);
|
|
209
217
|
const results = await Promise.all(promises);
|
|
210
218
|
return results.filter((item) => item !== void 0);
|
|
@@ -308,6 +316,14 @@ function objectFilter(object, predicate) {
|
|
|
308
316
|
}
|
|
309
317
|
return array;
|
|
310
318
|
}
|
|
319
|
+
function objectMap(object, callback) {
|
|
320
|
+
const entries = Object.entries(object);
|
|
321
|
+
const mappedEntries = entries.map(([key, value]) => [
|
|
322
|
+
key,
|
|
323
|
+
callback(key, value)
|
|
324
|
+
]);
|
|
325
|
+
return Object.fromEntries(mappedEntries);
|
|
326
|
+
}
|
|
311
327
|
function objectToMap(object) {
|
|
312
328
|
const map = /* @__PURE__ */ new Map();
|
|
313
329
|
for (const [key, value] of Object.entries(object)) {
|
|
@@ -439,7 +455,8 @@ const EMOJI_REGEX = /(\p{Extended_Pictographic}|[#*0-9]\uFE0F?\u20E3)/u;
|
|
|
439
455
|
const FIRST_LETTER_CAPITALIZED_REGEX = /^\p{Lu}/u;
|
|
440
456
|
const KEBAB_CASE_REGEX = /^[\da-z]+(?:-[\da-z]+)*$/;
|
|
441
457
|
const SEMANTIC_VERSION_REGEX = /^v*(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/;
|
|
442
|
-
const WHITESPACE_REGEX = /\s
|
|
458
|
+
const WHITESPACE_REGEX = /\s/;
|
|
459
|
+
const WHITESPACE_GLOBAL_REGEX = /\s/g;
|
|
443
460
|
const TITLE_CASE_BOUNDARY_REGEX = /(?<=[\da-z])(?=[A-Z])/g;
|
|
444
461
|
const UPPERCASE_REGEX = /^[A-Z]*$/;
|
|
445
462
|
const LOWERCASE_REGEX = /^[a-z]*$/;
|
|
@@ -564,7 +581,7 @@ function removeNonPrintableCharacters(string) {
|
|
|
564
581
|
return string.replaceAll(/\p{C}/gu, "");
|
|
565
582
|
}
|
|
566
583
|
function removeWhitespace(string) {
|
|
567
|
-
return string.replaceAll(
|
|
584
|
+
return string.replaceAll(WHITESPACE_GLOBAL_REGEX, "");
|
|
568
585
|
}
|
|
569
586
|
function titleCaseToKebabCase(string) {
|
|
570
587
|
return string.replaceAll(TITLE_CASE_BOUNDARY_REGEX, "-").replaceAll(/ +/g, "-").toLowerCase();
|
|
@@ -609,4 +626,4 @@ function* tupleKeys(tuple) {
|
|
|
609
626
|
|
|
610
627
|
const ReadonlyMap = Map;
|
|
611
628
|
|
|
612
|
-
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveAllInPlace, arrayRemoveInPlace, assertArray, assertArrayBoolean, assertArrayNumber, assertArrayObject, assertArrayString, assertBoolean, assertDefined, assertEnumValue, assertInteger, assertIs, assertNotNull, assertNumber, assertObject, assertString, assertStringNotEmpty, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterAsync, filterMap, filterMapAsync, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, includesAny, interfaceSatisfiesEnum, isASCII, isArray, isArrayBoolean, isArrayNumber, isArrayString, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isLowerCase, isObject, isSemanticVersion, isUpperCase, kebabCaseToCamelCase, kebabCaseToPascalCase, mapAsync, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToSet, objectToMap, objectToReverseMap, objectValuesToSet, parseFloatSafe, parseIntSafe, parseSemanticVersion, removeLinesBetweenMarkers, removeLinesMatching, removeNonPrintableCharacters, removeWhitespace, repeat, setAdd, setHas, sortCaseInsensitive, sumArray, titleCaseToKebabCase, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys };
|
|
629
|
+
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveAllInPlace, arrayRemoveInPlace, assertArray, assertArrayBoolean, assertArrayNumber, assertArrayObject, assertArrayString, assertBoolean, assertDefined, assertEnumValue, assertInteger, assertIs, assertNotNull, assertNumber, assertObject, assertString, assertStringNotEmpty, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterAsync, filterMap, filterMapAsync, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, includesAny, interfaceSatisfiesEnum, isASCII, isArray, isArrayBoolean, isArrayNumber, isArrayString, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isLowerCase, isObject, isSemanticVersion, isUpperCase, kebabCaseToCamelCase, kebabCaseToPascalCase, mapAsync, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToSet, objectMap, objectToMap, objectToReverseMap, objectValuesToSet, parseFloatSafe, parseIntSafe, parseSemanticVersion, removeLinesBetweenMarkers, removeLinesMatching, removeNonPrintableCharacters, removeWhitespace, repeat, setAdd, setHas, sortCaseInsensitive, sumArray, titleCaseToKebabCase, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys };
|
package/package.json
CHANGED
package/src/functions/array.ts
CHANGED
|
@@ -177,12 +177,12 @@ export async function filterAsync<T>(
|
|
|
177
177
|
*/
|
|
178
178
|
export function filterMap<OldT, NewT>(
|
|
179
179
|
array: readonly OldT[],
|
|
180
|
-
|
|
180
|
+
predicate: (element: OldT) => NewT | undefined,
|
|
181
181
|
): readonly NewT[] {
|
|
182
182
|
const filteredArray: NewT[] = [];
|
|
183
183
|
|
|
184
184
|
for (const element of array) {
|
|
185
|
-
const newElement =
|
|
185
|
+
const newElement = predicate(element);
|
|
186
186
|
if (newElement !== undefined) {
|
|
187
187
|
filteredArray.push(newElement);
|
|
188
188
|
}
|
|
@@ -212,14 +212,14 @@ export function filterMap<OldT, NewT>(
|
|
|
212
212
|
*/
|
|
213
213
|
export async function filterMapAsync<OldT, NewT>(
|
|
214
214
|
array: readonly OldT[],
|
|
215
|
-
|
|
215
|
+
predicate: (
|
|
216
216
|
element: OldT,
|
|
217
217
|
index: number,
|
|
218
218
|
array: readonly OldT[],
|
|
219
219
|
) => Promise<NewT | undefined>,
|
|
220
220
|
): Promise<readonly NewT[]> {
|
|
221
221
|
const promises = array.map(
|
|
222
|
-
async (element, index) => await
|
|
222
|
+
async (element, index) => await predicate(element, index, array),
|
|
223
223
|
);
|
|
224
224
|
const results = await Promise.all(promises);
|
|
225
225
|
return results.filter((item) => item !== undefined);
|
package/src/functions/assert.ts
CHANGED
|
@@ -9,10 +9,14 @@ import { isEnumValue } from "./enums.js";
|
|
|
9
9
|
import { isObject } from "./types.js";
|
|
10
10
|
|
|
11
11
|
/** Helper function to throw an error if the provided value is not an array. */
|
|
12
|
-
export function assertArray(
|
|
13
|
-
value:
|
|
14
|
-
msg:
|
|
15
|
-
|
|
12
|
+
export function assertArray<T>(
|
|
13
|
+
value: T,
|
|
14
|
+
...[msg]: [T] extends [readonly unknown[]]
|
|
15
|
+
? [
|
|
16
|
+
"The assertion is useless because the provided value is already an array.",
|
|
17
|
+
]
|
|
18
|
+
: [string]
|
|
19
|
+
): asserts value is T & unknown[] {
|
|
16
20
|
if (!Array.isArray(value)) {
|
|
17
21
|
throw new TypeError(msg);
|
|
18
22
|
}
|
|
@@ -22,13 +26,19 @@ export function assertArray(
|
|
|
22
26
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
23
27
|
* a boolean.
|
|
24
28
|
*/
|
|
25
|
-
export function assertArrayBoolean(
|
|
26
|
-
value:
|
|
27
|
-
msg:
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
export function assertArrayBoolean<T>(
|
|
30
|
+
value: T,
|
|
31
|
+
...[msg]: [T] extends [readonly boolean[]]
|
|
32
|
+
? [
|
|
33
|
+
"The assertion is useless because the provided value is already a boolean array.",
|
|
34
|
+
]
|
|
35
|
+
: [string]
|
|
36
|
+
): asserts value is T & boolean[] {
|
|
37
|
+
if (!Array.isArray(value)) {
|
|
38
|
+
throw new TypeError(msg);
|
|
39
|
+
}
|
|
30
40
|
|
|
31
|
-
if (value.some((element) => typeof element !== "boolean")) {
|
|
41
|
+
if ((value as unknown[]).some((element) => typeof element !== "boolean")) {
|
|
32
42
|
throw new TypeError(msg);
|
|
33
43
|
}
|
|
34
44
|
}
|
|
@@ -37,13 +47,19 @@ export function assertArrayBoolean(
|
|
|
37
47
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
38
48
|
* a number.
|
|
39
49
|
*/
|
|
40
|
-
export function assertArrayNumber(
|
|
41
|
-
value:
|
|
42
|
-
msg:
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
export function assertArrayNumber<T>(
|
|
51
|
+
value: T,
|
|
52
|
+
...[msg]: [T] extends [readonly number[]]
|
|
53
|
+
? [
|
|
54
|
+
"The assertion is useless because the provided value is already a number array.",
|
|
55
|
+
]
|
|
56
|
+
: [string]
|
|
57
|
+
): asserts value is T & number[] {
|
|
58
|
+
if (!Array.isArray(value)) {
|
|
59
|
+
throw new TypeError(msg);
|
|
60
|
+
}
|
|
45
61
|
|
|
46
|
-
if (value.some((element) => typeof element !== "number")) {
|
|
62
|
+
if ((value as unknown[]).some((element) => typeof element !== "number")) {
|
|
47
63
|
throw new TypeError(msg);
|
|
48
64
|
}
|
|
49
65
|
}
|
|
@@ -52,13 +68,19 @@ export function assertArrayNumber(
|
|
|
52
68
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
53
69
|
* an object (i.e. a TypeScript record).
|
|
54
70
|
*/
|
|
55
|
-
export function assertArrayObject(
|
|
56
|
-
value:
|
|
57
|
-
msg: string,
|
|
58
|
-
|
|
59
|
-
|
|
71
|
+
export function assertArrayObject<T>(
|
|
72
|
+
value: T,
|
|
73
|
+
...[msg]: [T] extends [ReadonlyArray<Record<string, unknown>>]
|
|
74
|
+
? [
|
|
75
|
+
"The assertion is useless because the provided value is already an object array.",
|
|
76
|
+
]
|
|
77
|
+
: [string]
|
|
78
|
+
): asserts value is T & Array<Record<string, unknown>> {
|
|
79
|
+
if (!Array.isArray(value)) {
|
|
80
|
+
throw new TypeError(msg);
|
|
81
|
+
}
|
|
60
82
|
|
|
61
|
-
if (value.some((element) => !isObject(element))) {
|
|
83
|
+
if ((value as unknown[]).some((element) => !isObject(element))) {
|
|
62
84
|
throw new TypeError(msg);
|
|
63
85
|
}
|
|
64
86
|
}
|
|
@@ -67,22 +89,32 @@ export function assertArrayObject(
|
|
|
67
89
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
68
90
|
* a string.
|
|
69
91
|
*/
|
|
70
|
-
export function assertArrayString(
|
|
71
|
-
value:
|
|
72
|
-
msg: string
|
|
73
|
-
|
|
74
|
-
|
|
92
|
+
export function assertArrayString<T>(
|
|
93
|
+
value: T,
|
|
94
|
+
...[msg]: [T] extends [readonly string[]]
|
|
95
|
+
? [
|
|
96
|
+
"The assertion is useless because the provided value is already a string array.",
|
|
97
|
+
]
|
|
98
|
+
: [string]
|
|
99
|
+
): asserts value is T & string[] {
|
|
100
|
+
if (!Array.isArray(value)) {
|
|
101
|
+
throw new TypeError(msg);
|
|
102
|
+
}
|
|
75
103
|
|
|
76
|
-
if (value.some((element) => typeof element !== "string")) {
|
|
104
|
+
if ((value as unknown[]).some((element) => typeof element !== "string")) {
|
|
77
105
|
throw new TypeError(msg);
|
|
78
106
|
}
|
|
79
107
|
}
|
|
80
108
|
|
|
81
109
|
/** Helper function to throw an error if the provided value is not a boolean. */
|
|
82
|
-
export function assertBoolean(
|
|
83
|
-
value:
|
|
84
|
-
msg:
|
|
85
|
-
|
|
110
|
+
export function assertBoolean<T>(
|
|
111
|
+
value: T,
|
|
112
|
+
...[msg]: [T] extends [boolean]
|
|
113
|
+
? [
|
|
114
|
+
"The assertion is useless because the provided value is already a boolean.",
|
|
115
|
+
]
|
|
116
|
+
: [string]
|
|
117
|
+
): asserts value is T & boolean {
|
|
86
118
|
if (typeof value !== "boolean") {
|
|
87
119
|
throw new TypeError(msg);
|
|
88
120
|
}
|
|
@@ -175,10 +207,14 @@ export function assertNotNull<T>(
|
|
|
175
207
|
}
|
|
176
208
|
|
|
177
209
|
/** Helper function to throw an error if the provided value is not a number. */
|
|
178
|
-
export function assertNumber(
|
|
179
|
-
value:
|
|
180
|
-
msg:
|
|
181
|
-
|
|
210
|
+
export function assertNumber<T>(
|
|
211
|
+
value: T,
|
|
212
|
+
...[msg]: [T] extends [number]
|
|
213
|
+
? [
|
|
214
|
+
"The assertion is useless because the provided value is already a number.",
|
|
215
|
+
]
|
|
216
|
+
: [string]
|
|
217
|
+
): asserts value is T & number {
|
|
182
218
|
if (typeof value !== "number") {
|
|
183
219
|
throw new TypeError(msg);
|
|
184
220
|
}
|
|
@@ -193,20 +229,28 @@ export function assertNumber(
|
|
|
193
229
|
*
|
|
194
230
|
* Under the hood, this function uses the `isObject` helper function.
|
|
195
231
|
*/
|
|
196
|
-
export function assertObject(
|
|
197
|
-
value:
|
|
198
|
-
msg: string,
|
|
199
|
-
|
|
232
|
+
export function assertObject<T>(
|
|
233
|
+
value: T,
|
|
234
|
+
...[msg]: [T] extends [Record<string, unknown>]
|
|
235
|
+
? [
|
|
236
|
+
"The assertion is useless because the provided value is already an object.",
|
|
237
|
+
]
|
|
238
|
+
: [string]
|
|
239
|
+
): asserts value is T & Record<string, unknown> {
|
|
200
240
|
if (!isObject(value)) {
|
|
201
241
|
throw new TypeError(msg);
|
|
202
242
|
}
|
|
203
243
|
}
|
|
204
244
|
|
|
205
245
|
/** Helper function to throw an error if the provided value is not a string. */
|
|
206
|
-
export function assertString(
|
|
207
|
-
value:
|
|
208
|
-
msg: string
|
|
209
|
-
|
|
246
|
+
export function assertString<T>(
|
|
247
|
+
value: T,
|
|
248
|
+
...[msg]: [T] extends [string]
|
|
249
|
+
? [
|
|
250
|
+
"The assertion is useless because the provided value is already a string.",
|
|
251
|
+
]
|
|
252
|
+
: [string]
|
|
253
|
+
): asserts value is T & string {
|
|
210
254
|
if (typeof value !== "string") {
|
|
211
255
|
throw new TypeError(msg);
|
|
212
256
|
}
|
package/src/functions/object.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Helper function to get the values in an object that match an arbitrary condition. Similar to the
|
|
11
|
-
* `Array.
|
|
11
|
+
* `Array.filter` method, but works for objects.
|
|
12
12
|
*
|
|
13
13
|
* This is efficient such that it avoids converting the object values into an array.
|
|
14
14
|
*/
|
|
@@ -31,7 +31,23 @@ export function objectFilter<K extends string | number | symbol, V>(
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* Helper function to
|
|
34
|
+
* Helper function to map the values in an object to another object with new values. Similar to the
|
|
35
|
+
* `Array.map` method, but works for objects.
|
|
36
|
+
*/
|
|
37
|
+
export function objectMap<K extends string | number | symbol, V, U>(
|
|
38
|
+
object: Record<K, V>,
|
|
39
|
+
callback: (key: K, value: V) => U,
|
|
40
|
+
): ReadonlyRecord<K, U> {
|
|
41
|
+
const entries = Object.entries(object);
|
|
42
|
+
const mappedEntries = entries.map(([key, value]) => [
|
|
43
|
+
key,
|
|
44
|
+
callback(key as K, value as V),
|
|
45
|
+
]);
|
|
46
|
+
return Object.fromEntries(mappedEntries) as Record<K, U>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Helper function to convert an object to a `Map`.
|
|
35
51
|
*
|
|
36
52
|
* This is useful when you need to construct a type safe object with the `satisfies` operator, but
|
|
37
53
|
* then later on you need to query it in a way where you expect the return value to be T or
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
/* eslint-disable complete/require-ascii */
|
|
2
|
+
|
|
1
3
|
import { equal } from "node:assert";
|
|
2
4
|
import { describe, test } from "node:test";
|
|
3
5
|
import {
|
|
4
6
|
hasDiacritic,
|
|
5
7
|
hasEmoji,
|
|
8
|
+
isASCII,
|
|
6
9
|
isKebabCase,
|
|
7
10
|
titleCaseToKebabCase,
|
|
8
11
|
trimPrefix,
|
|
@@ -61,6 +64,27 @@ describe("hasDiacritic", () => {
|
|
|
61
64
|
});
|
|
62
65
|
});
|
|
63
66
|
|
|
67
|
+
describe("isASCII", () => {
|
|
68
|
+
test("should return true for ASCII strings", () => {
|
|
69
|
+
equal(isASCII("Hello World"), true);
|
|
70
|
+
equal(isASCII("1234567890"), true);
|
|
71
|
+
equal(isASCII("!@#$%^&*()_+"), true);
|
|
72
|
+
equal(isASCII(" \n\t\r"), true);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("should return false for non-ASCII strings", () => {
|
|
76
|
+
equal(isASCII("Hello World ๐"), false);
|
|
77
|
+
equal(isASCII("รก"), false);
|
|
78
|
+
equal(isASCII("รจ"), false);
|
|
79
|
+
equal(isASCII("รด"), false);
|
|
80
|
+
equal(isASCII("๐"), false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("should handle empty string", () => {
|
|
84
|
+
equal(isASCII(""), true);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
64
88
|
describe("isKebabCase", () => {
|
|
65
89
|
test("should return true for valid kebab-case strings", () => {
|
|
66
90
|
equal(isKebabCase("hello-world"), true);
|
package/src/functions/string.ts
CHANGED
|
@@ -7,8 +7,11 @@
|
|
|
7
7
|
import { parseIntSafe } from "./utils.js";
|
|
8
8
|
|
|
9
9
|
// When regular expressions are located at the root instead of inside the function, the functions
|
|
10
|
-
// are tested to perform 11% faster.
|
|
10
|
+
// are tested to perform 11% faster. However, since the global flag makes a regex stateful, care has
|
|
11
|
+
// to be taken to ensure that regexes used for validation do not use the global flag. Otherwise,
|
|
12
|
+
// they will return inconsistent results due to the `lastIndex` property persisting between calls.
|
|
11
13
|
|
|
14
|
+
/** We use a "*" instead of a "+" so that an empty string will match. */
|
|
12
15
|
// eslint-disable-next-line no-control-regex
|
|
13
16
|
const ASCII_REGEX = /^[\u0000-\u007F]*$/;
|
|
14
17
|
|
|
@@ -23,7 +26,8 @@ const EMOJI_REGEX = /(\p{Extended_Pictographic}|[#*0-9]\uFE0F?\u20E3)/u;
|
|
|
23
26
|
const FIRST_LETTER_CAPITALIZED_REGEX = /^\p{Lu}/u;
|
|
24
27
|
const KEBAB_CASE_REGEX = /^[\da-z]+(?:-[\da-z]+)*$/;
|
|
25
28
|
const SEMANTIC_VERSION_REGEX = /^v*(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/;
|
|
26
|
-
const WHITESPACE_REGEX = /\s
|
|
29
|
+
const WHITESPACE_REGEX = /\s/;
|
|
30
|
+
const WHITESPACE_GLOBAL_REGEX = /\s/g;
|
|
27
31
|
const TITLE_CASE_BOUNDARY_REGEX = /(?<=[\da-z])(?=[A-Z])/g;
|
|
28
32
|
const UPPERCASE_REGEX = /^[A-Z]*$/;
|
|
29
33
|
const LOWERCASE_REGEX = /^[a-z]*$/;
|
|
@@ -245,7 +249,7 @@ export function parseSemanticVersion(versionString: string):
|
|
|
245
249
|
*
|
|
246
250
|
* For example, by using a marker of "@foo":
|
|
247
251
|
*
|
|
248
|
-
* ```
|
|
252
|
+
* ```txt
|
|
249
253
|
* line1
|
|
250
254
|
* # @foo-start
|
|
251
255
|
* line2
|
|
@@ -256,7 +260,7 @@ export function parseSemanticVersion(versionString: string):
|
|
|
256
260
|
*
|
|
257
261
|
* Would return:
|
|
258
262
|
*
|
|
259
|
-
* ```
|
|
263
|
+
* ```txt
|
|
260
264
|
* line1
|
|
261
265
|
* line4
|
|
262
266
|
* ```
|
|
@@ -309,7 +313,7 @@ export function removeNonPrintableCharacters(string: string): string {
|
|
|
309
313
|
|
|
310
314
|
/** Helper function to remove all whitespace characters from a string. */
|
|
311
315
|
export function removeWhitespace(string: string): string {
|
|
312
|
-
return string.replaceAll(
|
|
316
|
+
return string.replaceAll(WHITESPACE_GLOBAL_REGEX, "");
|
|
313
317
|
}
|
|
314
318
|
|
|
315
319
|
/** Helper function to convert a string from TitleCase (PascalCase) to kebab-case. */
|