complete-common 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +12 -0
- package/dist/functions/assert.d.mts +12 -0
- package/dist/functions/assert.d.ts +12 -0
- package/dist/functions/assert.d.ts.map +1 -1
- package/dist/functions/enums.d.cts +1 -2
- package/dist/functions/enums.d.mts +1 -2
- package/dist/functions/enums.d.ts +1 -2
- package/dist/functions/enums.d.ts.map +1 -1
- package/dist/index.cjs +32 -26
- package/dist/index.mjs +32 -27
- package/package.json +5 -5
- package/src/functions/array.ts +3 -3
- package/src/functions/assert.ts +23 -0
- package/src/functions/enums.ts +1 -1
|
@@ -36,7 +36,7 @@ export declare function arrayRemove<T>(originalArray: readonly T[], ...elementsT
|
|
|
36
36
|
*/
|
|
37
37
|
export declare function arrayRemoveInPlace<T>(array: T[], ...elementsToRemove: readonly T[]): T[];
|
|
38
38
|
/** Helper function to remove all of the elements in an array in-place. */
|
|
39
|
-
export declare function emptyArray
|
|
39
|
+
export declare function emptyArray(array: unknown[]): void;
|
|
40
40
|
/**
|
|
41
41
|
* Helper function to perform a filter and a map at the same time. Similar to `Array.map`, provide a
|
|
42
42
|
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
@@ -66,7 +66,7 @@ export declare function getRandomArrayElement<T>(array: readonly T[], exceptions
|
|
|
66
66
|
* @param exceptions Optional. An array of indexes that will be skipped over when getting the random
|
|
67
67
|
* index. Default is an empty array.
|
|
68
68
|
*/
|
|
69
|
-
export declare function getRandomArrayIndex
|
|
69
|
+
export declare function getRandomArrayIndex(array: readonly unknown[], exceptions?: readonly number[]): number;
|
|
70
70
|
/**
|
|
71
71
|
* Similar to the `Array.includes` method, but works on a widened version of the array.
|
|
72
72
|
*
|
|
@@ -36,7 +36,7 @@ export declare function arrayRemove<T>(originalArray: readonly T[], ...elementsT
|
|
|
36
36
|
*/
|
|
37
37
|
export declare function arrayRemoveInPlace<T>(array: T[], ...elementsToRemove: readonly T[]): T[];
|
|
38
38
|
/** Helper function to remove all of the elements in an array in-place. */
|
|
39
|
-
export declare function emptyArray
|
|
39
|
+
export declare function emptyArray(array: unknown[]): void;
|
|
40
40
|
/**
|
|
41
41
|
* Helper function to perform a filter and a map at the same time. Similar to `Array.map`, provide a
|
|
42
42
|
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
@@ -66,7 +66,7 @@ export declare function getRandomArrayElement<T>(array: readonly T[], exceptions
|
|
|
66
66
|
* @param exceptions Optional. An array of indexes that will be skipped over when getting the random
|
|
67
67
|
* index. Default is an empty array.
|
|
68
68
|
*/
|
|
69
|
-
export declare function getRandomArrayIndex
|
|
69
|
+
export declare function getRandomArrayIndex(array: readonly unknown[], exceptions?: readonly number[]): number;
|
|
70
70
|
/**
|
|
71
71
|
* Similar to the `Array.includes` method, but works on a widened version of the array.
|
|
72
72
|
*
|
|
@@ -36,7 +36,7 @@ export declare function arrayRemove<T>(originalArray: readonly T[], ...elementsT
|
|
|
36
36
|
*/
|
|
37
37
|
export declare function arrayRemoveInPlace<T>(array: T[], ...elementsToRemove: readonly T[]): T[];
|
|
38
38
|
/** Helper function to remove all of the elements in an array in-place. */
|
|
39
|
-
export declare function emptyArray
|
|
39
|
+
export declare function emptyArray(array: unknown[]): void;
|
|
40
40
|
/**
|
|
41
41
|
* Helper function to perform a filter and a map at the same time. Similar to `Array.map`, provide a
|
|
42
42
|
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
@@ -66,7 +66,7 @@ export declare function getRandomArrayElement<T>(array: readonly T[], exceptions
|
|
|
66
66
|
* @param exceptions Optional. An array of indexes that will be skipped over when getting the random
|
|
67
67
|
* index. Default is an empty array.
|
|
68
68
|
*/
|
|
69
|
-
export declare function getRandomArrayIndex
|
|
69
|
+
export declare function getRandomArrayIndex(array: readonly unknown[], exceptions?: readonly number[]): number;
|
|
70
70
|
/**
|
|
71
71
|
* Similar to the `Array.includes` method, but works on a widened version of the array.
|
|
72
72
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/functions/array.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAKhD;;;GAGG;AAEH,wBAAgB,uBAAuB,CAAC,CAAC,EACvC,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC,GACjC,CAAC,EAAE,EAAE,CAQP;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,MAAM,EAAE,SAAS,CAAC,EAAE,EACpB,MAAM,EAAE,SAAS,CAAC,EAAE,GACnB,OAAO,CAST;AAED;;;;;;GAMG;AAEH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,aAAa,EAAE,SAAS,CAAC,EAAE,EAC3B,GAAG,gBAAgB,EAAE,SAAS,CAAC,EAAE,GAChC,CAAC,EAAE,CAWL;AAED;;;;;;;;;;;GAWG;AAEH,wBAAgB,kBAAkB,CAAC,CAAC,EAElC,KAAK,EAAE,CAAC,EAAE,EACV,GAAG,gBAAgB,EAAE,SAAS,CAAC,EAAE,GAChC,CAAC,EAAE,CAYL;AAED,0EAA0E;AAE1E,wBAAgB,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/functions/array.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAKhD;;;GAGG;AAEH,wBAAgB,uBAAuB,CAAC,CAAC,EACvC,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC,GACjC,CAAC,EAAE,EAAE,CAQP;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,MAAM,EAAE,SAAS,CAAC,EAAE,EACpB,MAAM,EAAE,SAAS,CAAC,EAAE,GACnB,OAAO,CAST;AAED;;;;;;GAMG;AAEH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,aAAa,EAAE,SAAS,CAAC,EAAE,EAC3B,GAAG,gBAAgB,EAAE,SAAS,CAAC,EAAE,GAChC,CAAC,EAAE,CAWL;AAED;;;;;;;;;;;GAWG;AAEH,wBAAgB,kBAAkB,CAAC,CAAC,EAElC,KAAK,EAAE,CAAC,EAAE,EACV,GAAG,gBAAgB,EAAE,SAAS,CAAC,EAAE,GAChC,CAAC,EAAE,CAYL;AAED,0EAA0E;AAE1E,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAEjD;AAED;;;;;;;;;;GAUG;AAEH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAClC,KAAK,EAAE,SAAS,IAAI,EAAE,EACtB,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,KAAK,IAAI,GAAG,SAAS,GACxC,IAAI,EAAE,CAWR;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,UAAU,GAAE,SAAS,CAAC,EAAO,GAC5B,CAAC,CAiBH;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,SAAS,OAAO,EAAE,EACzB,UAAU,GAAE,SAAS,MAAM,EAAO,GACjC,MAAM,CAQR;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,YAAY,SAAS,YAAY,CAAC,CAAC,CAAC,EAC9D,KAAK,EAAE,SAAS,YAAY,EAAE,EAC9B,aAAa,EAAE,YAAY,CAAC,CAAC,CAAC,GAC7B,aAAa,IAAI,YAAY,CAG/B;AAED,uFAAuF;AACvF,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,OAAO,EAAE,CAEtD;AAED,qFAAqF;AAErF,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAEzD;AAED,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAEzD"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
+
import type { TranspiledEnum } from "./enums.js";
|
|
6
7
|
/** Helper function to throw an error if the provided value is not an array. */
|
|
7
8
|
export declare function assertArray(value: unknown, msg: string): asserts value is unknown[];
|
|
8
9
|
/** Helper function to throw an error if the provided value is not a boolean. */
|
|
@@ -15,6 +16,17 @@ export declare function assertBoolean(value: unknown, msg: string): asserts valu
|
|
|
15
16
|
export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends [T] ? [string] : [
|
|
16
17
|
"The assertion is useless because the provided value does not contain undefined."
|
|
17
18
|
]): asserts value is Exclude<T, undefined>;
|
|
19
|
+
/**
|
|
20
|
+
* Helper function to throw an error if the provided value is not contained within an enum.
|
|
21
|
+
*
|
|
22
|
+
* @param value The value to check.
|
|
23
|
+
* @param transpiledEnum The enum to check against.
|
|
24
|
+
* @param msg The error message to throw if the check fails.
|
|
25
|
+
* @param set Optional. A set that contains all of the values of an enum. If provided, this function
|
|
26
|
+
* will check for existence using the set (instead of the enum itself). Using a set
|
|
27
|
+
* should be more performant for enums with around 52 or more elements.
|
|
28
|
+
*/
|
|
29
|
+
export declare function assertEnumValue<T extends TranspiledEnum>(value: number | string, transpiledEnum: T, msg: string, set?: ReadonlySet<string | number>): asserts value is T[keyof T];
|
|
18
30
|
/**
|
|
19
31
|
* Helper function to throw an error if the provided value is equal to `null`.
|
|
20
32
|
*
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
+
import type { TranspiledEnum } from "./enums.js";
|
|
6
7
|
/** Helper function to throw an error if the provided value is not an array. */
|
|
7
8
|
export declare function assertArray(value: unknown, msg: string): asserts value is unknown[];
|
|
8
9
|
/** Helper function to throw an error if the provided value is not a boolean. */
|
|
@@ -15,6 +16,17 @@ export declare function assertBoolean(value: unknown, msg: string): asserts valu
|
|
|
15
16
|
export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends [T] ? [string] : [
|
|
16
17
|
"The assertion is useless because the provided value does not contain undefined."
|
|
17
18
|
]): asserts value is Exclude<T, undefined>;
|
|
19
|
+
/**
|
|
20
|
+
* Helper function to throw an error if the provided value is not contained within an enum.
|
|
21
|
+
*
|
|
22
|
+
* @param value The value to check.
|
|
23
|
+
* @param transpiledEnum The enum to check against.
|
|
24
|
+
* @param msg The error message to throw if the check fails.
|
|
25
|
+
* @param set Optional. A set that contains all of the values of an enum. If provided, this function
|
|
26
|
+
* will check for existence using the set (instead of the enum itself). Using a set
|
|
27
|
+
* should be more performant for enums with around 52 or more elements.
|
|
28
|
+
*/
|
|
29
|
+
export declare function assertEnumValue<T extends TranspiledEnum>(value: number | string, transpiledEnum: T, msg: string, set?: ReadonlySet<string | number>): asserts value is T[keyof T];
|
|
18
30
|
/**
|
|
19
31
|
* Helper function to throw an error if the provided value is equal to `null`.
|
|
20
32
|
*
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
+
import type { TranspiledEnum } from "./enums.js";
|
|
6
7
|
/** Helper function to throw an error if the provided value is not an array. */
|
|
7
8
|
export declare function assertArray(value: unknown, msg: string): asserts value is unknown[];
|
|
8
9
|
/** Helper function to throw an error if the provided value is not a boolean. */
|
|
@@ -15,6 +16,17 @@ export declare function assertBoolean(value: unknown, msg: string): asserts valu
|
|
|
15
16
|
export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends [T] ? [string] : [
|
|
16
17
|
"The assertion is useless because the provided value does not contain undefined."
|
|
17
18
|
]): asserts value is Exclude<T, undefined>;
|
|
19
|
+
/**
|
|
20
|
+
* Helper function to throw an error if the provided value is not contained within an enum.
|
|
21
|
+
*
|
|
22
|
+
* @param value The value to check.
|
|
23
|
+
* @param transpiledEnum The enum to check against.
|
|
24
|
+
* @param msg The error message to throw if the check fails.
|
|
25
|
+
* @param set Optional. A set that contains all of the values of an enum. If provided, this function
|
|
26
|
+
* will check for existence using the set (instead of the enum itself). Using a set
|
|
27
|
+
* should be more performant for enums with around 52 or more elements.
|
|
28
|
+
*/
|
|
29
|
+
export declare function assertEnumValue<T extends TranspiledEnum>(value: number | string, transpiledEnum: T, msg: string, set?: ReadonlySet<string | number>): asserts value is T[keyof T];
|
|
18
30
|
/**
|
|
19
31
|
* Helper function to throw an error if the provided value is equal to `null`.
|
|
20
32
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/functions/assert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/functions/assert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjD,+EAA+E;AAC/E,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,OAAO,EAAE,CAI5B;AAED,gFAAgF;AAChF,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,OAAO,CAI1B;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,CAAC,EACR,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,GAC7B,CAAC,MAAM,CAAC,GACR;IACE,iFAAiF;CAClF,GACJ,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,CAIxC;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,cAAc,EACtD,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,cAAc,EAAE,CAAC,EACjB,GAAG,EAAE,MAAM,EACX,GAAG,CAAC,EAAE,WAAW,CAAC,MAAM,GAAG,MAAM,CAAC,GACjC,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAI7B;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,CAAC,EACR,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GACxB,CAAC,MAAM,CAAC,GACR;IACE,4EAA4E;CAC7E,GACJ,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,CAInC;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,MAAM,CAIzB;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAI1C;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,MAAM,CAIzB"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
type TranspiledEnum = Record<string, string | number>;
|
|
6
|
+
export type TranspiledEnum = Record<string, string | number>;
|
|
7
7
|
/**
|
|
8
8
|
* Helper function to get the entries of an enum.
|
|
9
9
|
*
|
|
@@ -69,5 +69,4 @@ export declare function interfaceSatisfiesEnum<T extends Record<Enum, unknown>,
|
|
|
69
69
|
* should be more performant for enums with around 52 or more elements.
|
|
70
70
|
*/
|
|
71
71
|
export declare function isEnumValue<T extends TranspiledEnum>(value: number | string, transpiledEnum: T, set?: ReadonlySet<string | number>): value is T[keyof T];
|
|
72
|
-
export {};
|
|
73
72
|
//# sourceMappingURL=enums.d.ts.map
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
type TranspiledEnum = Record<string, string | number>;
|
|
6
|
+
export type TranspiledEnum = Record<string, string | number>;
|
|
7
7
|
/**
|
|
8
8
|
* Helper function to get the entries of an enum.
|
|
9
9
|
*
|
|
@@ -69,5 +69,4 @@ export declare function interfaceSatisfiesEnum<T extends Record<Enum, unknown>,
|
|
|
69
69
|
* should be more performant for enums with around 52 or more elements.
|
|
70
70
|
*/
|
|
71
71
|
export declare function isEnumValue<T extends TranspiledEnum>(value: number | string, transpiledEnum: T, set?: ReadonlySet<string | number>): value is T[keyof T];
|
|
72
|
-
export {};
|
|
73
72
|
//# sourceMappingURL=enums.d.ts.map
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
type TranspiledEnum = Record<string, string | number>;
|
|
6
|
+
export type TranspiledEnum = Record<string, string | number>;
|
|
7
7
|
/**
|
|
8
8
|
* Helper function to get the entries of an enum.
|
|
9
9
|
*
|
|
@@ -69,5 +69,4 @@ export declare function interfaceSatisfiesEnum<T extends Record<Enum, unknown>,
|
|
|
69
69
|
* should be more performant for enums with around 52 or more elements.
|
|
70
70
|
*/
|
|
71
71
|
export declare function isEnumValue<T extends TranspiledEnum>(value: number | string, transpiledEnum: T, set?: ReadonlySet<string | number>): value is T[keyof T];
|
|
72
|
-
export {};
|
|
73
72
|
//# sourceMappingURL=enums.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../../src/functions/enums.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,
|
|
1
|
+
{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../../src/functions/enums.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;AAE7D;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,cAAc,EACrD,cAAc,EAAE,CAAC,GAChB,aAAa,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CASjD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,cAAc,EAAE,cAAc,GAAG,SAAS,MAAM,EAAE,CAG7E;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,cAAc,EACpD,cAAc,EAAE,CAAC,GAChB,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAG3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,sBAAsB,CAEpC,CAAC,SAAS,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAC/B,IAAI,SAAS,MAAM,GAAG,MAAM,KACzB,IAAI,CAAG;AAEZ;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,cAAc,EAClD,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,cAAc,EAAE,CAAC,EACjB,GAAG,CAAC,EAAE,WAAW,CAAC,MAAM,GAAG,MAAM,CAAC,GACjC,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAOrB"}
|
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,32 @@ const HOUR_IN_MILLISECONDS = 60 * MINUTE_IN_MILLISECONDS;
|
|
|
6
6
|
|
|
7
7
|
const ReadonlySet = Set;
|
|
8
8
|
|
|
9
|
+
function getEnumEntries(transpiledEnum) {
|
|
10
|
+
const entries = Object.entries(transpiledEnum);
|
|
11
|
+
const numberEntries = entries.filter(
|
|
12
|
+
([_key, value]) => typeof value === "number"
|
|
13
|
+
);
|
|
14
|
+
const entriesToReturn = numberEntries.length > 0 ? numberEntries : entries;
|
|
15
|
+
return entriesToReturn;
|
|
16
|
+
}
|
|
17
|
+
function getEnumKeys(transpiledEnum) {
|
|
18
|
+
const enumEntries = getEnumEntries(transpiledEnum);
|
|
19
|
+
return enumEntries.map(([key, _value]) => key);
|
|
20
|
+
}
|
|
21
|
+
function getEnumValues(transpiledEnum) {
|
|
22
|
+
const enumEntries = getEnumEntries(transpiledEnum);
|
|
23
|
+
return enumEntries.map(([_key, value]) => value);
|
|
24
|
+
}
|
|
25
|
+
function interfaceSatisfiesEnum() {
|
|
26
|
+
}
|
|
27
|
+
function isEnumValue(value, transpiledEnum, set) {
|
|
28
|
+
if (set !== void 0) {
|
|
29
|
+
return set.has(value);
|
|
30
|
+
}
|
|
31
|
+
const enumValues = getEnumValues(transpiledEnum);
|
|
32
|
+
return enumValues.includes(value);
|
|
33
|
+
}
|
|
34
|
+
|
|
9
35
|
function isObject(variable) {
|
|
10
36
|
return typeof variable === "object" && variable !== null && !Array.isArray(variable);
|
|
11
37
|
}
|
|
@@ -25,6 +51,11 @@ function assertDefined(value, ...[msg]) {
|
|
|
25
51
|
throw new TypeError(msg);
|
|
26
52
|
}
|
|
27
53
|
}
|
|
54
|
+
function assertEnumValue(value, transpiledEnum, msg, set) {
|
|
55
|
+
if (!isEnumValue(value, transpiledEnum, set)) {
|
|
56
|
+
throw new TypeError(msg);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
28
59
|
function assertNotNull(value, ...[msg]) {
|
|
29
60
|
if (value === null) {
|
|
30
61
|
throw new TypeError(msg);
|
|
@@ -150,32 +181,6 @@ function sumArray(array) {
|
|
|
150
181
|
return array.reduce((accumulator, element) => accumulator + element, 0);
|
|
151
182
|
}
|
|
152
183
|
|
|
153
|
-
function getEnumEntries(transpiledEnum) {
|
|
154
|
-
const entries = Object.entries(transpiledEnum);
|
|
155
|
-
const numberEntries = entries.filter(
|
|
156
|
-
([_key, value]) => typeof value === "number"
|
|
157
|
-
);
|
|
158
|
-
const entriesToReturn = numberEntries.length > 0 ? numberEntries : entries;
|
|
159
|
-
return entriesToReturn;
|
|
160
|
-
}
|
|
161
|
-
function getEnumKeys(transpiledEnum) {
|
|
162
|
-
const enumEntries = getEnumEntries(transpiledEnum);
|
|
163
|
-
return enumEntries.map(([key, _value]) => key);
|
|
164
|
-
}
|
|
165
|
-
function getEnumValues(transpiledEnum) {
|
|
166
|
-
const enumEntries = getEnumEntries(transpiledEnum);
|
|
167
|
-
return enumEntries.map(([_key, value]) => value);
|
|
168
|
-
}
|
|
169
|
-
function interfaceSatisfiesEnum() {
|
|
170
|
-
}
|
|
171
|
-
function isEnumValue(value, transpiledEnum, set) {
|
|
172
|
-
if (set !== void 0) {
|
|
173
|
-
return set.has(value);
|
|
174
|
-
}
|
|
175
|
-
const enumValues = getEnumValues(transpiledEnum);
|
|
176
|
-
return enumValues.includes(value);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
184
|
function mapFilter(map, predicate) {
|
|
180
185
|
const array = [];
|
|
181
186
|
for (const value of map.values()) {
|
|
@@ -518,6 +523,7 @@ exports.arrayRemoveInPlace = arrayRemoveInPlace;
|
|
|
518
523
|
exports.assertArray = assertArray;
|
|
519
524
|
exports.assertBoolean = assertBoolean;
|
|
520
525
|
exports.assertDefined = assertDefined;
|
|
526
|
+
exports.assertEnumValue = assertEnumValue;
|
|
521
527
|
exports.assertNotNull = assertNotNull;
|
|
522
528
|
exports.assertNumber = assertNumber;
|
|
523
529
|
exports.assertObject = assertObject;
|
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,32 @@ const HOUR_IN_MILLISECONDS = 60 * MINUTE_IN_MILLISECONDS;
|
|
|
4
4
|
|
|
5
5
|
const ReadonlySet = Set;
|
|
6
6
|
|
|
7
|
+
function getEnumEntries(transpiledEnum) {
|
|
8
|
+
const entries = Object.entries(transpiledEnum);
|
|
9
|
+
const numberEntries = entries.filter(
|
|
10
|
+
([_key, value]) => typeof value === "number"
|
|
11
|
+
);
|
|
12
|
+
const entriesToReturn = numberEntries.length > 0 ? numberEntries : entries;
|
|
13
|
+
return entriesToReturn;
|
|
14
|
+
}
|
|
15
|
+
function getEnumKeys(transpiledEnum) {
|
|
16
|
+
const enumEntries = getEnumEntries(transpiledEnum);
|
|
17
|
+
return enumEntries.map(([key, _value]) => key);
|
|
18
|
+
}
|
|
19
|
+
function getEnumValues(transpiledEnum) {
|
|
20
|
+
const enumEntries = getEnumEntries(transpiledEnum);
|
|
21
|
+
return enumEntries.map(([_key, value]) => value);
|
|
22
|
+
}
|
|
23
|
+
function interfaceSatisfiesEnum() {
|
|
24
|
+
}
|
|
25
|
+
function isEnumValue(value, transpiledEnum, set) {
|
|
26
|
+
if (set !== void 0) {
|
|
27
|
+
return set.has(value);
|
|
28
|
+
}
|
|
29
|
+
const enumValues = getEnumValues(transpiledEnum);
|
|
30
|
+
return enumValues.includes(value);
|
|
31
|
+
}
|
|
32
|
+
|
|
7
33
|
function isObject(variable) {
|
|
8
34
|
return typeof variable === "object" && variable !== null && !Array.isArray(variable);
|
|
9
35
|
}
|
|
@@ -23,6 +49,11 @@ function assertDefined(value, ...[msg]) {
|
|
|
23
49
|
throw new TypeError(msg);
|
|
24
50
|
}
|
|
25
51
|
}
|
|
52
|
+
function assertEnumValue(value, transpiledEnum, msg, set) {
|
|
53
|
+
if (!isEnumValue(value, transpiledEnum, set)) {
|
|
54
|
+
throw new TypeError(msg);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
26
57
|
function assertNotNull(value, ...[msg]) {
|
|
27
58
|
if (value === null) {
|
|
28
59
|
throw new TypeError(msg);
|
|
@@ -148,32 +179,6 @@ function sumArray(array) {
|
|
|
148
179
|
return array.reduce((accumulator, element) => accumulator + element, 0);
|
|
149
180
|
}
|
|
150
181
|
|
|
151
|
-
function getEnumEntries(transpiledEnum) {
|
|
152
|
-
const entries = Object.entries(transpiledEnum);
|
|
153
|
-
const numberEntries = entries.filter(
|
|
154
|
-
([_key, value]) => typeof value === "number"
|
|
155
|
-
);
|
|
156
|
-
const entriesToReturn = numberEntries.length > 0 ? numberEntries : entries;
|
|
157
|
-
return entriesToReturn;
|
|
158
|
-
}
|
|
159
|
-
function getEnumKeys(transpiledEnum) {
|
|
160
|
-
const enumEntries = getEnumEntries(transpiledEnum);
|
|
161
|
-
return enumEntries.map(([key, _value]) => key);
|
|
162
|
-
}
|
|
163
|
-
function getEnumValues(transpiledEnum) {
|
|
164
|
-
const enumEntries = getEnumEntries(transpiledEnum);
|
|
165
|
-
return enumEntries.map(([_key, value]) => value);
|
|
166
|
-
}
|
|
167
|
-
function interfaceSatisfiesEnum() {
|
|
168
|
-
}
|
|
169
|
-
function isEnumValue(value, transpiledEnum, set) {
|
|
170
|
-
if (set !== void 0) {
|
|
171
|
-
return set.has(value);
|
|
172
|
-
}
|
|
173
|
-
const enumValues = getEnumValues(transpiledEnum);
|
|
174
|
-
return enumValues.includes(value);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
182
|
function mapFilter(map, predicate) {
|
|
178
183
|
const array = [];
|
|
179
184
|
for (const value of map.values()) {
|
|
@@ -503,4 +508,4 @@ function* tupleKeys(tuple) {
|
|
|
503
508
|
|
|
504
509
|
const ReadonlyMap = Map;
|
|
505
510
|
|
|
506
|
-
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveInPlace, assertArray, assertBoolean, assertDefined, assertNotNull, assertNumber, assertObject, assertString, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterMap, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, interfaceSatisfiesEnum, isArray, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isObject, isSemanticVersion, kebabCaseToCamelCase, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToReadonlySet, objectKeysToSet, objectToMap, objectToReadonlyMap, objectToReverseMap, objectToReverseReadonlyMap, objectValuesToReadonlySet, objectValuesToSet, parseFloatSafe, parseIntSafe, parseSemanticVersion, removeLinesBetweenMarkers, removeLinesMatching, removeNonPrintableCharacters, removeWhitespace, repeat, setAdd, setHas, sortCaseInsensitive, sumArray, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys };
|
|
511
|
+
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveInPlace, assertArray, assertBoolean, assertDefined, assertEnumValue, assertNotNull, assertNumber, assertObject, assertString, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterMap, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, interfaceSatisfiesEnum, isArray, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isObject, isSemanticVersion, kebabCaseToCamelCase, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToReadonlySet, objectKeysToSet, objectToMap, objectToReadonlyMap, objectToReverseMap, objectToReverseReadonlyMap, objectValuesToReadonlySet, objectValuesToSet, parseFloatSafe, parseIntSafe, parseSemanticVersion, removeLinesBetweenMarkers, removeLinesMatching, removeNonPrintableCharacters, removeWhitespace, repeat, setAdd, setHas, sortCaseInsensitive, sumArray, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "complete-common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Helper functions for TypeScript projects.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://complete-ts.github.io/",
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"test": "glob \"./src/**/*.test.ts\" --cmd=\"node --import tsx --test --test-reporter spec\""
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@types/node": "22.13.
|
|
39
|
-
"complete-node": "
|
|
38
|
+
"@types/node": "22.13.9",
|
|
39
|
+
"complete-node": "5.1.1",
|
|
40
40
|
"eslint-plugin-sort-exports": "0.9.1",
|
|
41
41
|
"glob": "11.0.1",
|
|
42
|
-
"typescript": "5.
|
|
43
|
-
"typescript-eslint": "8.
|
|
42
|
+
"typescript": "5.8.2",
|
|
43
|
+
"typescript-eslint": "8.26.0",
|
|
44
44
|
"unbuild": "3.5.0"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/functions/array.ts
CHANGED
|
@@ -101,7 +101,7 @@ export function arrayRemoveInPlace<T>(
|
|
|
101
101
|
|
|
102
102
|
/** Helper function to remove all of the elements in an array in-place. */
|
|
103
103
|
// eslint-disable-next-line complete/prefer-readonly-parameter-types
|
|
104
|
-
export function emptyArray
|
|
104
|
+
export function emptyArray(array: unknown[]): void {
|
|
105
105
|
array.splice(0, array.length);
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -171,8 +171,8 @@ export function getRandomArrayElement<T>(
|
|
|
171
171
|
* @param exceptions Optional. An array of indexes that will be skipped over when getting the random
|
|
172
172
|
* index. Default is an empty array.
|
|
173
173
|
*/
|
|
174
|
-
export function getRandomArrayIndex
|
|
175
|
-
array: readonly
|
|
174
|
+
export function getRandomArrayIndex(
|
|
175
|
+
array: readonly unknown[],
|
|
176
176
|
exceptions: readonly number[] = [],
|
|
177
177
|
): number {
|
|
178
178
|
if (array.length === 0) {
|
package/src/functions/assert.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import type { TranspiledEnum } from "./enums.js";
|
|
8
|
+
import { isEnumValue } from "./enums.js";
|
|
7
9
|
import { isObject } from "./types.js";
|
|
8
10
|
|
|
9
11
|
/** Helper function to throw an error if the provided value is not an array. */
|
|
@@ -44,6 +46,27 @@ export function assertDefined<T>(
|
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Helper function to throw an error if the provided value is not contained within an enum.
|
|
51
|
+
*
|
|
52
|
+
* @param value The value to check.
|
|
53
|
+
* @param transpiledEnum The enum to check against.
|
|
54
|
+
* @param msg The error message to throw if the check fails.
|
|
55
|
+
* @param set Optional. A set that contains all of the values of an enum. If provided, this function
|
|
56
|
+
* will check for existence using the set (instead of the enum itself). Using a set
|
|
57
|
+
* should be more performant for enums with around 52 or more elements.
|
|
58
|
+
*/
|
|
59
|
+
export function assertEnumValue<T extends TranspiledEnum>(
|
|
60
|
+
value: number | string,
|
|
61
|
+
transpiledEnum: T,
|
|
62
|
+
msg: string,
|
|
63
|
+
set?: ReadonlySet<string | number>,
|
|
64
|
+
): asserts value is T[keyof T] {
|
|
65
|
+
if (!isEnumValue(value, transpiledEnum, set)) {
|
|
66
|
+
throw new TypeError(msg);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
47
70
|
/**
|
|
48
71
|
* Helper function to throw an error if the provided value is equal to `null`.
|
|
49
72
|
*
|