complete-common 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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<T>(array: T[]): void;
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<T>(array: readonly T[], exceptions?: readonly number[]): number;
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<T>(array: T[]): void;
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<T>(array: readonly T[], exceptions?: readonly number[]): number;
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<T>(array: T[]): void;
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<T>(array: readonly T[], exceptions?: readonly number[]): number;
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,gB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AAgB,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,9 @@
3
3
  *
4
4
  * @module
5
5
  */
6
+ import type { TranspiledEnum } from "./enums.js";
7
+ /** Helper function to throw an error if the provided value is not an array. */
8
+ export declare function assertArray(value: unknown, msg: string): asserts value is unknown[];
6
9
  /** Helper function to throw an error if the provided value is not a boolean. */
7
10
  export declare function assertBoolean(value: unknown, msg: string): asserts value is boolean;
8
11
  /**
@@ -13,6 +16,17 @@ export declare function assertBoolean(value: unknown, msg: string): asserts valu
13
16
  export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends [T] ? [string] : [
14
17
  "The assertion is useless because the provided value does not contain undefined."
15
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];
16
30
  /**
17
31
  * Helper function to throw an error if the provided value is equal to `null`.
18
32
  *
@@ -3,6 +3,9 @@
3
3
  *
4
4
  * @module
5
5
  */
6
+ import type { TranspiledEnum } from "./enums.js";
7
+ /** Helper function to throw an error if the provided value is not an array. */
8
+ export declare function assertArray(value: unknown, msg: string): asserts value is unknown[];
6
9
  /** Helper function to throw an error if the provided value is not a boolean. */
7
10
  export declare function assertBoolean(value: unknown, msg: string): asserts value is boolean;
8
11
  /**
@@ -13,6 +16,17 @@ export declare function assertBoolean(value: unknown, msg: string): asserts valu
13
16
  export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends [T] ? [string] : [
14
17
  "The assertion is useless because the provided value does not contain undefined."
15
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];
16
30
  /**
17
31
  * Helper function to throw an error if the provided value is equal to `null`.
18
32
  *
@@ -3,6 +3,9 @@
3
3
  *
4
4
  * @module
5
5
  */
6
+ import type { TranspiledEnum } from "./enums.js";
7
+ /** Helper function to throw an error if the provided value is not an array. */
8
+ export declare function assertArray(value: unknown, msg: string): asserts value is unknown[];
6
9
  /** Helper function to throw an error if the provided value is not a boolean. */
7
10
  export declare function assertBoolean(value: unknown, msg: string): asserts value is boolean;
8
11
  /**
@@ -13,6 +16,17 @@ export declare function assertBoolean(value: unknown, msg: string): asserts valu
13
16
  export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends [T] ? [string] : [
14
17
  "The assertion is useless because the provided value does not contain undefined."
15
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];
16
30
  /**
17
31
  * Helper function to throw an error if the provided value is equal to `null`.
18
32
  *
@@ -1 +1 @@
1
- {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/functions/assert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,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;;;;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,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,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,KAAK,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;AAEtD;;;;;;;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;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AEpC,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,10 +6,41 @@ 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
  }
12
38
 
39
+ function assertArray(value, msg) {
40
+ if (!Array.isArray(value)) {
41
+ throw new TypeError(msg);
42
+ }
43
+ }
13
44
  function assertBoolean(value, msg) {
14
45
  if (typeof value !== "boolean") {
15
46
  throw new TypeError(msg);
@@ -20,6 +51,11 @@ function assertDefined(value, ...[msg]) {
20
51
  throw new TypeError(msg);
21
52
  }
22
53
  }
54
+ function assertEnumValue(value, transpiledEnum, msg, set) {
55
+ if (!isEnumValue(value, transpiledEnum, set)) {
56
+ throw new TypeError(msg);
57
+ }
58
+ }
23
59
  function assertNotNull(value, ...[msg]) {
24
60
  if (value === null) {
25
61
  throw new TypeError(msg);
@@ -145,32 +181,6 @@ function sumArray(array) {
145
181
  return array.reduce((accumulator, element) => accumulator + element, 0);
146
182
  }
147
183
 
148
- function getEnumEntries(transpiledEnum) {
149
- const entries = Object.entries(transpiledEnum);
150
- const numberEntries = entries.filter(
151
- ([_key, value]) => typeof value === "number"
152
- );
153
- const entriesToReturn = numberEntries.length > 0 ? numberEntries : entries;
154
- return entriesToReturn;
155
- }
156
- function getEnumKeys(transpiledEnum) {
157
- const enumEntries = getEnumEntries(transpiledEnum);
158
- return enumEntries.map(([key, _value]) => key);
159
- }
160
- function getEnumValues(transpiledEnum) {
161
- const enumEntries = getEnumEntries(transpiledEnum);
162
- return enumEntries.map(([_key, value]) => value);
163
- }
164
- function interfaceSatisfiesEnum() {
165
- }
166
- function isEnumValue(value, transpiledEnum, set) {
167
- if (set !== void 0) {
168
- return set.has(value);
169
- }
170
- const enumValues = getEnumValues(transpiledEnum);
171
- return enumValues.includes(value);
172
- }
173
-
174
184
  function mapFilter(map, predicate) {
175
185
  const array = [];
176
186
  for (const value of map.values()) {
@@ -510,8 +520,10 @@ exports.arrayCopyTwoDimensional = arrayCopyTwoDimensional;
510
520
  exports.arrayEquals = arrayEquals;
511
521
  exports.arrayRemove = arrayRemove;
512
522
  exports.arrayRemoveInPlace = arrayRemoveInPlace;
523
+ exports.assertArray = assertArray;
513
524
  exports.assertBoolean = assertBoolean;
514
525
  exports.assertDefined = assertDefined;
526
+ exports.assertEnumValue = assertEnumValue;
515
527
  exports.assertNotNull = assertNotNull;
516
528
  exports.assertNumber = assertNumber;
517
529
  exports.assertObject = assertObject;
package/dist/index.mjs CHANGED
@@ -4,10 +4,41 @@ 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
  }
10
36
 
37
+ function assertArray(value, msg) {
38
+ if (!Array.isArray(value)) {
39
+ throw new TypeError(msg);
40
+ }
41
+ }
11
42
  function assertBoolean(value, msg) {
12
43
  if (typeof value !== "boolean") {
13
44
  throw new TypeError(msg);
@@ -18,6 +49,11 @@ function assertDefined(value, ...[msg]) {
18
49
  throw new TypeError(msg);
19
50
  }
20
51
  }
52
+ function assertEnumValue(value, transpiledEnum, msg, set) {
53
+ if (!isEnumValue(value, transpiledEnum, set)) {
54
+ throw new TypeError(msg);
55
+ }
56
+ }
21
57
  function assertNotNull(value, ...[msg]) {
22
58
  if (value === null) {
23
59
  throw new TypeError(msg);
@@ -143,32 +179,6 @@ function sumArray(array) {
143
179
  return array.reduce((accumulator, element) => accumulator + element, 0);
144
180
  }
145
181
 
146
- function getEnumEntries(transpiledEnum) {
147
- const entries = Object.entries(transpiledEnum);
148
- const numberEntries = entries.filter(
149
- ([_key, value]) => typeof value === "number"
150
- );
151
- const entriesToReturn = numberEntries.length > 0 ? numberEntries : entries;
152
- return entriesToReturn;
153
- }
154
- function getEnumKeys(transpiledEnum) {
155
- const enumEntries = getEnumEntries(transpiledEnum);
156
- return enumEntries.map(([key, _value]) => key);
157
- }
158
- function getEnumValues(transpiledEnum) {
159
- const enumEntries = getEnumEntries(transpiledEnum);
160
- return enumEntries.map(([_key, value]) => value);
161
- }
162
- function interfaceSatisfiesEnum() {
163
- }
164
- function isEnumValue(value, transpiledEnum, set) {
165
- if (set !== void 0) {
166
- return set.has(value);
167
- }
168
- const enumValues = getEnumValues(transpiledEnum);
169
- return enumValues.includes(value);
170
- }
171
-
172
182
  function mapFilter(map, predicate) {
173
183
  const array = [];
174
184
  for (const value of map.values()) {
@@ -498,4 +508,4 @@ function* tupleKeys(tuple) {
498
508
 
499
509
  const ReadonlyMap = Map;
500
510
 
501
- export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveInPlace, 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.2.0",
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.5",
39
- "complete-node": "3.1.6",
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.7.3",
43
- "typescript-eslint": "8.25.0",
42
+ "typescript": "5.8.2",
43
+ "typescript-eslint": "8.26.0",
44
44
  "unbuild": "3.5.0"
45
45
  }
46
46
  }
@@ -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<T>(array: T[]): void {
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<T>(
175
- array: readonly T[],
174
+ export function getRandomArrayIndex(
175
+ array: readonly unknown[],
176
176
  exceptions: readonly number[] = [],
177
177
  ): number {
178
178
  if (array.length === 0) {
@@ -4,8 +4,20 @@
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
 
11
+ /** Helper function to throw an error if the provided value is not an array. */
12
+ export function assertArray(
13
+ value: unknown,
14
+ msg: string,
15
+ ): asserts value is unknown[] {
16
+ if (!Array.isArray(value)) {
17
+ throw new TypeError(msg);
18
+ }
19
+ }
20
+
9
21
  /** Helper function to throw an error if the provided value is not a boolean. */
10
22
  export function assertBoolean(
11
23
  value: unknown,
@@ -34,6 +46,27 @@ export function assertDefined<T>(
34
46
  }
35
47
  }
36
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
+
37
70
  /**
38
71
  * Helper function to throw an error if the provided value is equal to `null`.
39
72
  *
@@ -4,7 +4,7 @@
4
4
  * @module
5
5
  */
6
6
 
7
- type TranspiledEnum = Record<string, string | number>;
7
+ export type TranspiledEnum = Record<string, string | number>;
8
8
 
9
9
  /**
10
10
  * Helper function to get the entries of an enum.