complete-common 2.16.0 โ 2.17.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/functions/array.d.cts +11 -0
- package/dist/functions/array.d.mts +11 -0
- package/dist/functions/array.d.ts +11 -0
- 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/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 +49 -15
- package/dist/index.mjs +49 -16
- package/package.json +1 -1
- package/src/functions/array.ts +45 -0
- package/src/functions/assert.ts +88 -44
- package/src/functions/string.test.ts +24 -0
- package/src/functions/string.ts +9 -5
|
@@ -153,6 +153,17 @@ export declare function isArrayString(variable: unknown): variable is string[];
|
|
|
153
153
|
* (This is an abstraction around `Promise.all`.)
|
|
154
154
|
*/
|
|
155
155
|
export declare function mapAsync<T, U>(array: readonly T[], callback: (element: T, index: number, array: readonly T[]) => Promise<U>): Promise<readonly U[]>;
|
|
156
|
+
/**
|
|
157
|
+
* Helper function to perform an asynchronous map. This is the same thing as the `mapAsync`
|
|
158
|
+
* function, but allows for limiting the number of array elements that should be worked on at a
|
|
159
|
+
* time. This is useful to prevent the system from running out of memory in situations with large
|
|
160
|
+
* arrays and/or expensive functions.
|
|
161
|
+
*
|
|
162
|
+
* @param array The array to map.
|
|
163
|
+
* @param limit The maximum number of concurrent executions that should happen at once.
|
|
164
|
+
* @param callback The map function.
|
|
165
|
+
*/
|
|
166
|
+
export declare function mapAsyncLimit<T, U>(array: readonly T[], limit: number, callback: (item: T) => Promise<U>): Promise<readonly U[]>;
|
|
156
167
|
/** Initializes an array with all elements containing the specified default value. */
|
|
157
168
|
export declare function newArray<T>(length: number, value: T): readonly T[];
|
|
158
169
|
/** Helper function to sum every value in an array together. */
|
|
@@ -153,6 +153,17 @@ export declare function isArrayString(variable: unknown): variable is string[];
|
|
|
153
153
|
* (This is an abstraction around `Promise.all`.)
|
|
154
154
|
*/
|
|
155
155
|
export declare function mapAsync<T, U>(array: readonly T[], callback: (element: T, index: number, array: readonly T[]) => Promise<U>): Promise<readonly U[]>;
|
|
156
|
+
/**
|
|
157
|
+
* Helper function to perform an asynchronous map. This is the same thing as the `mapAsync`
|
|
158
|
+
* function, but allows for limiting the number of array elements that should be worked on at a
|
|
159
|
+
* time. This is useful to prevent the system from running out of memory in situations with large
|
|
160
|
+
* arrays and/or expensive functions.
|
|
161
|
+
*
|
|
162
|
+
* @param array The array to map.
|
|
163
|
+
* @param limit The maximum number of concurrent executions that should happen at once.
|
|
164
|
+
* @param callback The map function.
|
|
165
|
+
*/
|
|
166
|
+
export declare function mapAsyncLimit<T, U>(array: readonly T[], limit: number, callback: (item: T) => Promise<U>): Promise<readonly U[]>;
|
|
156
167
|
/** Initializes an array with all elements containing the specified default value. */
|
|
157
168
|
export declare function newArray<T>(length: number, value: T): readonly T[];
|
|
158
169
|
/** Helper function to sum every value in an array together. */
|
|
@@ -153,6 +153,17 @@ export declare function isArrayString(variable: unknown): variable is string[];
|
|
|
153
153
|
* (This is an abstraction around `Promise.all`.)
|
|
154
154
|
*/
|
|
155
155
|
export declare function mapAsync<T, U>(array: readonly T[], callback: (element: T, index: number, array: readonly T[]) => Promise<U>): Promise<readonly U[]>;
|
|
156
|
+
/**
|
|
157
|
+
* Helper function to perform an asynchronous map. This is the same thing as the `mapAsync`
|
|
158
|
+
* function, but allows for limiting the number of array elements that should be worked on at a
|
|
159
|
+
* time. This is useful to prevent the system from running out of memory in situations with large
|
|
160
|
+
* arrays and/or expensive functions.
|
|
161
|
+
*
|
|
162
|
+
* @param array The array to map.
|
|
163
|
+
* @param limit The maximum number of concurrent executions that should happen at once.
|
|
164
|
+
* @param callback The map function.
|
|
165
|
+
*/
|
|
166
|
+
export declare function mapAsyncLimit<T, U>(array: readonly T[], limit: number, callback: (item: T) => Promise<U>): Promise<readonly U[]>;
|
|
156
167
|
/** Initializes an array with all elements containing the specified default value. */
|
|
157
168
|
export declare function newArray<T>(length: number, value: T): readonly T[];
|
|
158
169
|
/** Helper function to sum every value in an array together. */
|
|
@@ -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,EAAE,EACV,GAAG,gBAAgB,EAAE,SAAS,CAAC,EAAE,GAChC,OAAO,CAeT;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAElC,KAAK,EAAE,CAAC,EAAE,EACV,GAAG,gBAAgB,EAAE,SAAS,CAAC,EAAE,GAChC,SAAS,CAAC,EAAE,CAYd;AAED,0EAA0E;AAE1E,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAEjD;AAED;;;;;;;;;;;;GAYG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AI,MAAM,EAAE,CAMrE;AAED,iFAAiF;AACjF,wBAAgB,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,MAAM,EAAE,CAMrE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAAE,CAAC,EACjC,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,GACvE,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAKvB;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,CAAC,EACtC,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAChC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CA6BvB;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,WAAW,CAAC,CAAC,EAC3B,KAAK,EAAE,CAAC,EACR,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,OAAO,EAAE,CAAC,GACtC;IACE,0EAA0E;CAC3E,GACD,CAAC,MAAM,CAAC,GACX,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,OAAO,EAAE,CAIhC;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,KAAK,EAAE,CAAC,EACR,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,OAAO,EAAE,CAAC,GACtC;IACE,iFAAiF;CAClF,GACD,CAAC,MAAM,CAAC,GACX,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,OAAO,EAAE,CAQhC;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,KAAK,EAAE,CAAC,EACR,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,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;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,KAAK,EAAE,CAAC,EACR,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC3C;IACE,2EAA2E;CAC5E,GACD,CAAC,MAAM,CAAC,GACX,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAI9C;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,CAAC,CAAC,EAC5B,KAAK,EAAE,CAAC,EACR,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,GAC1B;IACE,0EAA0E;CAC3E,GACD,CAAC,MAAM,CAAC,GACX,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,MAAM,CAI7B;AAED,kGAAkG;AAClG,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,MAAM,CAMzB"}
|
|
@@ -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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MAAM,CAIzE;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED,yEAAyE;AACzE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,qFAAqF;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
|
}
|
|
@@ -268,6 +276,30 @@ async function mapAsync(array, callback) {
|
|
|
268
276
|
);
|
|
269
277
|
return await Promise.all(promises);
|
|
270
278
|
}
|
|
279
|
+
async function mapAsyncLimit(array, limit, callback) {
|
|
280
|
+
if (limit < 1) {
|
|
281
|
+
throw new RangeError("The limit argument must be at least 1.");
|
|
282
|
+
}
|
|
283
|
+
const results = [];
|
|
284
|
+
let currentIndex = 0;
|
|
285
|
+
let hasFailed = false;
|
|
286
|
+
async function worker() {
|
|
287
|
+
while (currentIndex < array.length && !hasFailed) {
|
|
288
|
+
const index = currentIndex;
|
|
289
|
+
currentIndex++;
|
|
290
|
+
try {
|
|
291
|
+
results[index] = await callback(array[index]);
|
|
292
|
+
} catch (error) {
|
|
293
|
+
hasFailed = true;
|
|
294
|
+
throw error;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
await Promise.all(
|
|
299
|
+
Array.from({ length: Math.min(limit, array.length) }, worker)
|
|
300
|
+
);
|
|
301
|
+
return results;
|
|
302
|
+
}
|
|
271
303
|
function newArray(length, value) {
|
|
272
304
|
return Array.from({ length }, () => value);
|
|
273
305
|
}
|
|
@@ -449,7 +481,8 @@ const EMOJI_REGEX = /(\p{Extended_Pictographic}|[#*0-9]\uFE0F?\u20E3)/u;
|
|
|
449
481
|
const FIRST_LETTER_CAPITALIZED_REGEX = /^\p{Lu}/u;
|
|
450
482
|
const KEBAB_CASE_REGEX = /^[\da-z]+(?:-[\da-z]+)*$/;
|
|
451
483
|
const SEMANTIC_VERSION_REGEX = /^v*(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/;
|
|
452
|
-
const WHITESPACE_REGEX = /\s
|
|
484
|
+
const WHITESPACE_REGEX = /\s/;
|
|
485
|
+
const WHITESPACE_GLOBAL_REGEX = /\s/g;
|
|
453
486
|
const TITLE_CASE_BOUNDARY_REGEX = /(?<=[\da-z])(?=[A-Z])/g;
|
|
454
487
|
const UPPERCASE_REGEX = /^[A-Z]*$/;
|
|
455
488
|
const LOWERCASE_REGEX = /^[a-z]*$/;
|
|
@@ -574,7 +607,7 @@ function removeNonPrintableCharacters(string) {
|
|
|
574
607
|
return string.replaceAll(/\p{C}/gu, "");
|
|
575
608
|
}
|
|
576
609
|
function removeWhitespace(string) {
|
|
577
|
-
return string.replaceAll(
|
|
610
|
+
return string.replaceAll(WHITESPACE_GLOBAL_REGEX, "");
|
|
578
611
|
}
|
|
579
612
|
function titleCaseToKebabCase(string) {
|
|
580
613
|
return string.replaceAll(TITLE_CASE_BOUNDARY_REGEX, "-").replaceAll(/ +/g, "-").toLowerCase();
|
|
@@ -686,6 +719,7 @@ exports.isUpperCase = isUpperCase;
|
|
|
686
719
|
exports.kebabCaseToCamelCase = kebabCaseToCamelCase;
|
|
687
720
|
exports.kebabCaseToPascalCase = kebabCaseToPascalCase;
|
|
688
721
|
exports.mapAsync = mapAsync;
|
|
722
|
+
exports.mapAsyncLimit = mapAsyncLimit;
|
|
689
723
|
exports.mapFilter = mapFilter;
|
|
690
724
|
exports.mapFind = mapFind;
|
|
691
725
|
exports.newArray = newArray;
|
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
|
}
|
|
@@ -266,6 +274,30 @@ async function mapAsync(array, callback) {
|
|
|
266
274
|
);
|
|
267
275
|
return await Promise.all(promises);
|
|
268
276
|
}
|
|
277
|
+
async function mapAsyncLimit(array, limit, callback) {
|
|
278
|
+
if (limit < 1) {
|
|
279
|
+
throw new RangeError("The limit argument must be at least 1.");
|
|
280
|
+
}
|
|
281
|
+
const results = [];
|
|
282
|
+
let currentIndex = 0;
|
|
283
|
+
let hasFailed = false;
|
|
284
|
+
async function worker() {
|
|
285
|
+
while (currentIndex < array.length && !hasFailed) {
|
|
286
|
+
const index = currentIndex;
|
|
287
|
+
currentIndex++;
|
|
288
|
+
try {
|
|
289
|
+
results[index] = await callback(array[index]);
|
|
290
|
+
} catch (error) {
|
|
291
|
+
hasFailed = true;
|
|
292
|
+
throw error;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
await Promise.all(
|
|
297
|
+
Array.from({ length: Math.min(limit, array.length) }, worker)
|
|
298
|
+
);
|
|
299
|
+
return results;
|
|
300
|
+
}
|
|
269
301
|
function newArray(length, value) {
|
|
270
302
|
return Array.from({ length }, () => value);
|
|
271
303
|
}
|
|
@@ -447,7 +479,8 @@ const EMOJI_REGEX = /(\p{Extended_Pictographic}|[#*0-9]\uFE0F?\u20E3)/u;
|
|
|
447
479
|
const FIRST_LETTER_CAPITALIZED_REGEX = /^\p{Lu}/u;
|
|
448
480
|
const KEBAB_CASE_REGEX = /^[\da-z]+(?:-[\da-z]+)*$/;
|
|
449
481
|
const SEMANTIC_VERSION_REGEX = /^v*(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/;
|
|
450
|
-
const WHITESPACE_REGEX = /\s
|
|
482
|
+
const WHITESPACE_REGEX = /\s/;
|
|
483
|
+
const WHITESPACE_GLOBAL_REGEX = /\s/g;
|
|
451
484
|
const TITLE_CASE_BOUNDARY_REGEX = /(?<=[\da-z])(?=[A-Z])/g;
|
|
452
485
|
const UPPERCASE_REGEX = /^[A-Z]*$/;
|
|
453
486
|
const LOWERCASE_REGEX = /^[a-z]*$/;
|
|
@@ -572,7 +605,7 @@ function removeNonPrintableCharacters(string) {
|
|
|
572
605
|
return string.replaceAll(/\p{C}/gu, "");
|
|
573
606
|
}
|
|
574
607
|
function removeWhitespace(string) {
|
|
575
|
-
return string.replaceAll(
|
|
608
|
+
return string.replaceAll(WHITESPACE_GLOBAL_REGEX, "");
|
|
576
609
|
}
|
|
577
610
|
function titleCaseToKebabCase(string) {
|
|
578
611
|
return string.replaceAll(TITLE_CASE_BOUNDARY_REGEX, "-").replaceAll(/ +/g, "-").toLowerCase();
|
|
@@ -617,4 +650,4 @@ function* tupleKeys(tuple) {
|
|
|
617
650
|
|
|
618
651
|
const ReadonlyMap = Map;
|
|
619
652
|
|
|
620
|
-
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 };
|
|
653
|
+
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, mapAsyncLimit, 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
|
@@ -360,6 +360,51 @@ export async function mapAsync<T, U>(
|
|
|
360
360
|
return await Promise.all(promises);
|
|
361
361
|
}
|
|
362
362
|
|
|
363
|
+
/**
|
|
364
|
+
* Helper function to perform an asynchronous map. This is the same thing as the `mapAsync`
|
|
365
|
+
* function, but allows for limiting the number of array elements that should be worked on at a
|
|
366
|
+
* time. This is useful to prevent the system from running out of memory in situations with large
|
|
367
|
+
* arrays and/or expensive functions.
|
|
368
|
+
*
|
|
369
|
+
* @param array The array to map.
|
|
370
|
+
* @param limit The maximum number of concurrent executions that should happen at once.
|
|
371
|
+
* @param callback The map function.
|
|
372
|
+
*/
|
|
373
|
+
export async function mapAsyncLimit<T, U>(
|
|
374
|
+
array: readonly T[],
|
|
375
|
+
limit: number,
|
|
376
|
+
callback: (item: T) => Promise<U>,
|
|
377
|
+
): Promise<readonly U[]> {
|
|
378
|
+
if (limit < 1) {
|
|
379
|
+
throw new RangeError("The limit argument must be at least 1.");
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const results: U[] = [];
|
|
383
|
+
let currentIndex = 0;
|
|
384
|
+
let hasFailed = false;
|
|
385
|
+
|
|
386
|
+
async function worker() {
|
|
387
|
+
// Stop processing if the queue is empty or if another worker failed.
|
|
388
|
+
while (currentIndex < array.length && !hasFailed) {
|
|
389
|
+
const index = currentIndex;
|
|
390
|
+
currentIndex++;
|
|
391
|
+
try {
|
|
392
|
+
// eslint-disable-next-line no-await-in-loop, @typescript-eslint/no-non-null-assertion
|
|
393
|
+
results[index] = await callback(array[index]!);
|
|
394
|
+
} catch (error) {
|
|
395
|
+
hasFailed = true; // Signal other workers to stop taking new items.
|
|
396
|
+
throw error; // Bubble the error up to Promise.all.
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
await Promise.all(
|
|
402
|
+
Array.from({ length: Math.min(limit, array.length) }, worker),
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
return results;
|
|
406
|
+
}
|
|
407
|
+
|
|
363
408
|
/** Initializes an array with all elements containing the specified default value. */
|
|
364
409
|
export function newArray<T>(length: number, value: T): readonly T[] {
|
|
365
410
|
return Array.from({ length }, () => value);
|
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
|
}
|
|
@@ -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. */
|