ts-data-forge 6.7.0 → 6.9.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.
Files changed (60) hide show
  1. package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
  2. package/dist/array/impl/array-utils-set-op.mjs +1 -3
  3. package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
  4. package/dist/array/impl/array-utils-transformation.d.mts +25 -0
  5. package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
  6. package/dist/array/impl/array-utils-transformation.mjs +36 -1
  7. package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
  8. package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
  9. package/dist/array/impl/array-utils-validation.mjs +2 -6
  10. package/dist/array/impl/array-utils-validation.mjs.map +1 -1
  11. package/dist/array/impl/index.mjs +1 -1
  12. package/dist/object/object.d.mts +56 -0
  13. package/dist/object/object.d.mts.map +1 -1
  14. package/dist/object/object.mjs +107 -1
  15. package/dist/object/object.mjs.map +1 -1
  16. package/dist/others/fast-deep-equal.d.mts.map +1 -1
  17. package/dist/others/fast-deep-equal.mjs +0 -1
  18. package/dist/others/fast-deep-equal.mjs.map +1 -1
  19. package/package.json +14 -14
  20. package/src/array/impl/array-utils-overload-type-error.test.mts +2 -4
  21. package/src/array/impl/array-utils-set-op.mts +0 -1
  22. package/src/array/impl/array-utils-transformation.mts +40 -0
  23. package/src/array/impl/array-utils-transformation.test.mts +54 -0
  24. package/src/array/impl/array-utils-validation.mts +2 -6
  25. package/src/functional/optional.test.mts +5 -7
  26. package/src/functional/result.test.mts +8 -10
  27. package/src/functional/ternary-result.test.mts +4 -4
  28. package/src/json/json.test.mts +5 -5
  29. package/src/number/branded-types/finite-number.test.mts +11 -15
  30. package/src/number/branded-types/int.test.mts +13 -13
  31. package/src/number/branded-types/int16.test.mts +15 -15
  32. package/src/number/branded-types/int32.test.mts +15 -15
  33. package/src/number/branded-types/non-negative-finite-number.test.mts +15 -19
  34. package/src/number/branded-types/non-negative-int16.test.mts +15 -15
  35. package/src/number/branded-types/non-negative-int32.test.mts +15 -15
  36. package/src/number/branded-types/non-zero-finite-number.test.mts +18 -18
  37. package/src/number/branded-types/non-zero-int.test.mts +14 -18
  38. package/src/number/branded-types/non-zero-int16.test.mts +15 -19
  39. package/src/number/branded-types/non-zero-int32.test.mts +15 -19
  40. package/src/number/branded-types/non-zero-safe-int.test.mts +18 -22
  41. package/src/number/branded-types/non-zero-uint16.test.mts +15 -15
  42. package/src/number/branded-types/non-zero-uint32.test.mts +15 -15
  43. package/src/number/branded-types/positive-finite-number.test.mts +18 -18
  44. package/src/number/branded-types/positive-int.test.mts +16 -22
  45. package/src/number/branded-types/positive-int16.test.mts +14 -14
  46. package/src/number/branded-types/positive-int32.test.mts +14 -14
  47. package/src/number/branded-types/positive-safe-int.test.mts +18 -20
  48. package/src/number/branded-types/positive-uint16.test.mts +15 -15
  49. package/src/number/branded-types/positive-uint32.test.mts +15 -15
  50. package/src/number/branded-types/safe-int.test.mts +17 -21
  51. package/src/number/branded-types/safe-uint.test.mts +16 -22
  52. package/src/number/branded-types/uint.test.mts +14 -14
  53. package/src/number/branded-types/uint16.test.mts +14 -14
  54. package/src/number/branded-types/uint32.test.mts +14 -14
  55. package/src/number/enum/int8.test.mts +1 -1
  56. package/src/number/enum/uint8.test.mts +1 -1
  57. package/src/object/object.mts +174 -1
  58. package/src/object/object.test.mts +172 -0
  59. package/src/others/fast-deep-equal.mts +0 -1
  60. package/src/others/unknown-to-string.test.mts +1 -1
@@ -4,6 +4,7 @@ import { asPositiveUint32, asUint32, Uint32 } from '../../number/index.mjs';
4
4
  import { castMutable, tp } from '../../others/index.mjs';
5
5
  import { newArray, seq } from './array-utils-creation.mjs';
6
6
  import { size } from './array-utils-size.mjs';
7
+ import { isNonEmpty } from './array-utils-validation.mjs';
7
8
 
8
9
  /**
9
10
  * Creates a new array by transforming each element with a mapping function.
@@ -809,3 +810,42 @@ export const zip = <
809
810
  * @see {@link partition}
810
811
  */
811
812
  export const chunk = partition;
813
+
814
+ /**
815
+ * Computes the cartesian product of arrays.
816
+ * cartesianProduct([[1,2], [3,4]]) => [[1,3], [1,4], [2,3], [2,4]]
817
+ *
818
+ * @example
819
+ *
820
+ *
821
+ * ```ts
822
+ * const sizes = ['S', 'M'] as const;
823
+ *
824
+ * const colors = ['red', 'blue'] as const;
825
+ *
826
+ * const combinations = Arr.cartesianProduct([sizes, colors]);
827
+ *
828
+ * const expectedCombinations = [
829
+ * ['S', 'red'],
830
+ * ['S', 'blue'],
831
+ * ['M', 'red'],
832
+ * ['M', 'blue'],
833
+ * ] as const;
834
+ *
835
+ * assert.deepStrictEqual(combinations, expectedCombinations);
836
+ * ```
837
+ */
838
+ export const cartesianProduct = <T,>(
839
+ arrays: readonly (readonly T[])[],
840
+ ): readonly (readonly T[])[] => {
841
+ if (!isNonEmpty(arrays)) return [[]];
842
+
843
+ const [first, ...rest] = arrays;
844
+
845
+ // If first array is empty, the result is empty
846
+ if (!isNonEmpty(first)) return [];
847
+
848
+ const restProduct = cartesianProduct(rest);
849
+
850
+ return first.flatMap((item) => restProduct.map((prod) => [item, ...prod]));
851
+ };
@@ -3,6 +3,7 @@ import { expectType } from '../../expect-type.mjs';
3
3
  import { Optional } from '../../functional/index.mjs';
4
4
  import { SafeUint } from '../../number/index.mjs';
5
5
  import {
6
+ cartesianProduct,
6
7
  concat,
7
8
  filter,
8
9
  filterNot,
@@ -1093,4 +1094,57 @@ describe('Arr transformations', () => {
1093
1094
  assert.deepStrictEqual(result, []);
1094
1095
  });
1095
1096
  });
1097
+
1098
+ describe(cartesianProduct, () => {
1099
+ test('Empty array', () => {
1100
+ assert.deepStrictEqual(cartesianProduct([]), [[]]);
1101
+ });
1102
+
1103
+ test('Single array', () => {
1104
+ assert.deepStrictEqual(cartesianProduct([[1, 2, 3]]), [[1], [2], [3]]);
1105
+ });
1106
+
1107
+ test('Two arrays', () => {
1108
+ assert.deepStrictEqual(
1109
+ cartesianProduct([
1110
+ [1, 2],
1111
+ [3, 4],
1112
+ ]),
1113
+ [
1114
+ [1, 3],
1115
+ [1, 4],
1116
+ [2, 3],
1117
+ [2, 4],
1118
+ ],
1119
+ );
1120
+ });
1121
+
1122
+ test('Three arrays', () => {
1123
+ assert.deepStrictEqual(
1124
+ cartesianProduct<string | number | boolean>([
1125
+ ['a', 'b'],
1126
+ [1, 2],
1127
+ [true, false],
1128
+ ]),
1129
+ [
1130
+ ['a', 1, true],
1131
+ ['a', 1, false],
1132
+ ['a', 2, true],
1133
+ ['a', 2, false],
1134
+ ['b', 1, true],
1135
+ ['b', 1, false],
1136
+ ['b', 2, true],
1137
+ ['b', 2, false],
1138
+ ],
1139
+ );
1140
+ });
1141
+
1142
+ test('Array with empty array', () => {
1143
+ assert.deepStrictEqual(cartesianProduct([[1, 2], [], [3, 4]]), []);
1144
+ });
1145
+
1146
+ test('Single element arrays', () => {
1147
+ assert.deepStrictEqual(cartesianProduct([[1], [2], [3]]), [[1, 2, 3]]);
1148
+ });
1149
+ });
1096
1150
  });
@@ -106,9 +106,7 @@ export const isNonEmpty = <E,>(
106
106
  export const isArrayOfLength = <E, N extends SizeType.ArgArr>(
107
107
  array: readonly E[],
108
108
  len: N,
109
- ): array is ArrayOfLength<N, E> =>
110
- // eslint-disable-next-line ts-data-forge/prefer-arr-is-array-of-length
111
- array.length === len;
109
+ ): array is ArrayOfLength<N, E> => array.length === len;
112
110
 
113
111
  /**
114
112
  * Checks if an array has at least a specific length.
@@ -132,9 +130,7 @@ export const isArrayOfLength = <E, N extends SizeType.ArgArr>(
132
130
  export const isArrayAtLeastLength = <E, N extends SizeType.ArgArr>(
133
131
  array: readonly E[],
134
132
  len: N,
135
- ): array is ArrayAtLeastLen<N, E> =>
136
- // eslint-disable-next-line ts-data-forge/prefer-arr-is-array-at-least-length
137
- array.length >= len;
133
+ ): array is ArrayAtLeastLen<N, E> => array.length >= len;
138
134
 
139
135
  /**
140
136
  * Tests whether all elements in an array pass a test implemented by a predicate.
@@ -218,7 +218,7 @@ describe('Optional test', () => {
218
218
  });
219
219
 
220
220
  test('should throw for None', () => {
221
- expect(() => Optional.unwrapThrow(Optional.none)).toThrowError(
221
+ expect(() => Optional.unwrapThrow(Optional.none)).toThrow(
222
222
  '`unwrapThrow()` has failed because it is `None`',
223
223
  );
224
224
  });
@@ -300,9 +300,7 @@ describe('Optional test', () => {
300
300
  test('should throw with custom message for None', () => {
301
301
  const expectNumber = Optional.expectToBe<number>('Expected a number');
302
302
 
303
- expect(() => expectNumber(Optional.none)).toThrowError(
304
- 'Expected a number',
305
- );
303
+ expect(() => expectNumber(Optional.none)).toThrow('Expected a number');
306
304
  });
307
305
 
308
306
  test('should be curried', () => {
@@ -314,7 +312,7 @@ describe('Optional test', () => {
314
312
 
315
313
  expect(expectValidId(id1)).toBe('user-123');
316
314
 
317
- expect(() => expectValidId(id2)).toThrowError('ID is required');
315
+ expect(() => expectValidId(id2)).toThrow('ID is required');
318
316
  });
319
317
 
320
318
  test('should support curried form', () => {
@@ -328,7 +326,7 @@ describe('Optional test', () => {
328
326
 
329
327
  const noneValue = Optional.none;
330
328
 
331
- expect(() => getValue(noneValue)).toThrowError('Value must exist');
329
+ expect(() => getValue(noneValue)).toThrow('Value must exist');
332
330
  });
333
331
 
334
332
  test('should work with pipe when curried', () => {
@@ -340,7 +338,7 @@ describe('Optional test', () => {
340
338
 
341
339
  assert.deepStrictEqual(someResult, { name: 'Alice', age: 30 });
342
340
 
343
- expect(() => pipe(Optional.none).map(expectUser).value).toThrowError(
341
+ expect(() => pipe(Optional.none).map(expectUser).value).toThrow(
344
342
  'User not found',
345
343
  );
346
344
  });
@@ -248,7 +248,7 @@ describe('Result test', () => {
248
248
  test('throws on Err result', () => {
249
249
  const result = Result.err('error message');
250
250
 
251
- expect(() => Result.unwrapThrow(result)).toThrowError('error message');
251
+ expect(() => Result.unwrapThrow(result)).toThrow('error message');
252
252
  });
253
253
  });
254
254
 
@@ -589,7 +589,7 @@ describe('Result test', () => {
589
589
  test('should throw for Ok', () => {
590
590
  const result = Result.ok(42);
591
591
 
592
- expect(() => Result.unwrapErrThrow(result)).toThrowError(
592
+ expect(() => Result.unwrapErrThrow(result)).toThrow(
593
593
  'Expected Err but got Ok: 42',
594
594
  );
595
595
  });
@@ -599,7 +599,7 @@ describe('Result test', () => {
599
599
 
600
600
  expect(() =>
601
601
  Result.unwrapErrThrow(result, (obj) => `Object(id=${obj.id})`),
602
- ).toThrowError('Expected Err but got Ok: Object(id=1)');
602
+ ).toThrow('Expected Err but got Ok: Object(id=1)');
603
603
  });
604
604
  });
605
605
 
@@ -665,9 +665,9 @@ describe('Result test', () => {
665
665
  test('should throw custom error for Err result', () => {
666
666
  const result = Result.err('failed');
667
667
 
668
- expect(() =>
669
- Result.expectToBe(result, 'Operation must succeed'),
670
- ).toThrowError('Operation must succeed');
668
+ expect(() => Result.expectToBe(result, 'Operation must succeed')).toThrow(
669
+ 'Operation must succeed',
670
+ );
671
671
  });
672
672
 
673
673
  test('should support curried form', () => {
@@ -681,9 +681,7 @@ describe('Result test', () => {
681
681
 
682
682
  const errResult: Result<string, string> = Result.err('failed');
683
683
 
684
- expect(() => mustBeOk(errResult)).toThrowError(
685
- 'Expected successful result',
686
- );
684
+ expect(() => mustBeOk(errResult)).toThrow('Expected successful result');
687
685
  });
688
686
 
689
687
  test('should work with pipe when curried', () => {
@@ -695,7 +693,7 @@ describe('Result test', () => {
695
693
 
696
694
  expect(
697
695
  () => pipe(Result.err('validation error')).map(mustBeOk).value,
698
- ).toThrowError('Validation failed');
696
+ ).toThrow('Validation failed');
699
697
  });
700
698
  });
701
699
 
@@ -171,15 +171,15 @@ describe('TernaryResult test', () => {
171
171
  test('throwing unwrap variants provide descriptive errors', () => {
172
172
  expect(() =>
173
173
  TernaryResult.unwrapThrow(TernaryResult.warn('notice', 'warned')),
174
- ).toThrowError(/Warn/u);
174
+ ).toThrow(/Warn/u);
175
175
 
176
176
  expect(() =>
177
177
  TernaryResult.unwrapWarnThrow(TernaryResult.err('no warn')),
178
- ).toThrowError(/Err/u);
178
+ ).toThrow(/Err/u);
179
179
 
180
180
  expect(() =>
181
181
  TernaryResult.unwrapErrThrow(TernaryResult.ok('no err')),
182
- ).toThrowError(/Ok/u);
182
+ ).toThrow(/Ok/u);
183
183
  });
184
184
 
185
185
  test('expectToBe unwraps Ok values', () => {
@@ -187,7 +187,7 @@ describe('TernaryResult test', () => {
187
187
 
188
188
  expect(() =>
189
189
  TernaryResult.expectToBe(TernaryResult.err('x'), 'missing'),
190
- ).toThrowError(/missing/u);
190
+ ).toThrow(/missing/u);
191
191
  });
192
192
 
193
193
  test('zip prefers Err over Warn or Ok.', () => {
@@ -118,11 +118,11 @@ describe('parse', () => {
118
118
  });
119
119
 
120
120
  test('should not throw errors', () => {
121
- expect(() => Json.parse('{{{')).not.toThrowError();
121
+ expect(() => Json.parse('{{{')).not.toThrow();
122
122
 
123
- expect(() => Json.parse('null null')).not.toThrowError();
123
+ expect(() => Json.parse('null null')).not.toThrow();
124
124
 
125
- expect(() => Json.parse(String(undefined))).not.toThrowError();
125
+ expect(() => Json.parse(String(undefined))).not.toThrow();
126
126
  });
127
127
 
128
128
  test('should use reviver function to transform values', () => {
@@ -323,9 +323,9 @@ describe('stringify', () => {
323
323
 
324
324
  mut_circularArray.push(mut_circularArray);
325
325
 
326
- expect(() => Json.stringify(mut_circularArray)).not.toThrowError();
326
+ expect(() => Json.stringify(mut_circularArray)).not.toThrow();
327
327
 
328
- expect(() => Json.stringify({ fn: () => {} })).not.toThrowError();
328
+ expect(() => Json.stringify({ fn: () => {} })).not.toThrow();
329
329
  });
330
330
 
331
331
  test('should use replacer function to filter values', () => {
@@ -6,31 +6,27 @@ import { asNonZeroFiniteNumber } from './non-zero-finite-number.mjs';
6
6
  describe('FiniteNumber test', () => {
7
7
  describe(asFiniteNumber, () => {
8
8
  test('accepts valid finite numbers', () => {
9
- expect(() => asFiniteNumber(0)).not.toThrowError();
9
+ expect(() => asFiniteNumber(0)).not.toThrow();
10
10
 
11
- expect(() => asFiniteNumber(1)).not.toThrowError();
11
+ expect(() => asFiniteNumber(1)).not.toThrow();
12
12
 
13
- expect(() => asFiniteNumber(-1)).not.toThrowError();
13
+ expect(() => asFiniteNumber(-1)).not.toThrow();
14
14
 
15
- expect(() => asFiniteNumber(3.14)).not.toThrowError();
15
+ expect(() => asFiniteNumber(3.14)).not.toThrow();
16
16
 
17
- expect(() => asFiniteNumber(-2.5)).not.toThrowError();
17
+ expect(() => asFiniteNumber(-2.5)).not.toThrow();
18
18
 
19
- expect(() => asFiniteNumber(Number.MAX_VALUE)).not.toThrowError();
19
+ expect(() => asFiniteNumber(Number.MAX_VALUE)).not.toThrow();
20
20
 
21
- expect(() => asFiniteNumber(-Number.MAX_VALUE)).not.toThrowError();
21
+ expect(() => asFiniteNumber(-Number.MAX_VALUE)).not.toThrow();
22
22
  });
23
23
 
24
24
  test('rejects non-finite numbers', () => {
25
- expect(() => asFiniteNumber(Number.NaN)).toThrowError(TypeError);
25
+ expect(() => asFiniteNumber(Number.NaN)).toThrow(TypeError);
26
26
 
27
- expect(() => asFiniteNumber(Number.POSITIVE_INFINITY)).toThrowError(
28
- TypeError,
29
- );
27
+ expect(() => asFiniteNumber(Number.POSITIVE_INFINITY)).toThrow(TypeError);
30
28
 
31
- expect(() => asFiniteNumber(Number.NEGATIVE_INFINITY)).toThrowError(
32
- TypeError,
33
- );
29
+ expect(() => asFiniteNumber(Number.NEGATIVE_INFINITY)).toThrow(TypeError);
34
30
  });
35
31
 
36
32
  test('returns the same value for valid inputs', () => {
@@ -48,7 +44,7 @@ describe('FiniteNumber test', () => {
48
44
  ] as const)(
49
45
  `asFiniteNumber($name) should throw a TypeError`,
50
46
  ({ value }) => {
51
- expect(() => asFiniteNumber(value)).toThrowError(
47
+ expect(() => asFiniteNumber(value)).toThrow(
52
48
  new TypeError(`Expected a finite number, got: ${value}`),
53
49
  );
54
50
  },
@@ -6,31 +6,31 @@ import { asNonZeroInt } from './non-zero-int.mjs';
6
6
  describe('Int test', () => {
7
7
  describe(asInt, () => {
8
8
  test('accepts valid integers', () => {
9
- expect(() => asInt(0)).not.toThrowError();
9
+ expect(() => asInt(0)).not.toThrow();
10
10
 
11
- expect(() => asInt(1)).not.toThrowError();
11
+ expect(() => asInt(1)).not.toThrow();
12
12
 
13
- expect(() => asInt(-1)).not.toThrowError();
13
+ expect(() => asInt(-1)).not.toThrow();
14
14
 
15
- expect(() => asInt(42)).not.toThrowError();
15
+ expect(() => asInt(42)).not.toThrow();
16
16
 
17
- expect(() => asInt(-42)).not.toThrowError();
17
+ expect(() => asInt(-42)).not.toThrow();
18
18
 
19
- expect(() => asInt(Number.MAX_SAFE_INTEGER)).not.toThrowError();
19
+ expect(() => asInt(Number.MAX_SAFE_INTEGER)).not.toThrow();
20
20
 
21
- expect(() => asInt(Number.MIN_SAFE_INTEGER)).not.toThrowError();
21
+ expect(() => asInt(Number.MIN_SAFE_INTEGER)).not.toThrow();
22
22
  });
23
23
 
24
24
  test('rejects non-integers', () => {
25
- expect(() => asInt(Number.NaN)).toThrowError(TypeError);
25
+ expect(() => asInt(Number.NaN)).toThrow(TypeError);
26
26
 
27
- expect(() => asInt(Number.POSITIVE_INFINITY)).toThrowError(TypeError);
27
+ expect(() => asInt(Number.POSITIVE_INFINITY)).toThrow(TypeError);
28
28
 
29
- expect(() => asInt(Number.NEGATIVE_INFINITY)).toThrowError(TypeError);
29
+ expect(() => asInt(Number.NEGATIVE_INFINITY)).toThrow(TypeError);
30
30
 
31
- expect(() => asInt(1.2)).toThrowError(TypeError);
31
+ expect(() => asInt(1.2)).toThrow(TypeError);
32
32
 
33
- expect(() => asInt(-3.4)).toThrowError(TypeError);
33
+ expect(() => asInt(-3.4)).toThrow(TypeError);
34
34
  });
35
35
 
36
36
  test('returns the same value for valid inputs', () => {
@@ -48,7 +48,7 @@ describe('Int test', () => {
48
48
  { name: '1.2', value: 1.2 },
49
49
  { name: '-3.4', value: -3.4 },
50
50
  ] as const)(`asInt($name) should throw a TypeError`, ({ value }) => {
51
- expect(() => asInt(value)).toThrowError(
51
+ expect(() => asInt(value)).toThrow(
52
52
  new TypeError(`Expected an integer, got: ${value}`),
53
53
  );
54
54
  });
@@ -6,37 +6,37 @@ import { asNonZeroInt16 } from './non-zero-int16.mjs';
6
6
  describe('Int16 test', () => {
7
7
  describe(asInt16, () => {
8
8
  test('accepts valid int16 values', () => {
9
- expect(() => asInt16(0)).not.toThrowError();
9
+ expect(() => asInt16(0)).not.toThrow();
10
10
 
11
- expect(() => asInt16(1)).not.toThrowError();
11
+ expect(() => asInt16(1)).not.toThrow();
12
12
 
13
- expect(() => asInt16(-1)).not.toThrowError();
13
+ expect(() => asInt16(-1)).not.toThrow();
14
14
 
15
- expect(() => asInt16(32_767)).not.toThrowError(); // 2^15 - 1
15
+ expect(() => asInt16(32_767)).not.toThrow(); // 2^15 - 1
16
16
 
17
- expect(() => asInt16(-32_768)).not.toThrowError(); // -2^15
17
+ expect(() => asInt16(-32_768)).not.toThrow(); // -2^15
18
18
  });
19
19
 
20
20
  test('rejects values outside int16 range', () => {
21
- expect(() => asInt16(32_768)).toThrowError(TypeError); // 2^15
21
+ expect(() => asInt16(32_768)).toThrow(TypeError); // 2^15
22
22
 
23
- expect(() => asInt16(-32_769)).toThrowError(TypeError); // -2^15 - 1
23
+ expect(() => asInt16(-32_769)).toThrow(TypeError); // -2^15 - 1
24
24
 
25
- expect(() => asInt16(65_536)).toThrowError(TypeError);
25
+ expect(() => asInt16(65_536)).toThrow(TypeError);
26
26
 
27
- expect(() => asInt16(-65_536)).toThrowError(TypeError);
27
+ expect(() => asInt16(-65_536)).toThrow(TypeError);
28
28
  });
29
29
 
30
30
  test('rejects non-integers', () => {
31
- expect(() => asInt16(Number.NaN)).toThrowError(TypeError);
31
+ expect(() => asInt16(Number.NaN)).toThrow(TypeError);
32
32
 
33
- expect(() => asInt16(Number.POSITIVE_INFINITY)).toThrowError(TypeError);
33
+ expect(() => asInt16(Number.POSITIVE_INFINITY)).toThrow(TypeError);
34
34
 
35
- expect(() => asInt16(Number.NEGATIVE_INFINITY)).toThrowError(TypeError);
35
+ expect(() => asInt16(Number.NEGATIVE_INFINITY)).toThrow(TypeError);
36
36
 
37
- expect(() => asInt16(1.2)).toThrowError(TypeError);
37
+ expect(() => asInt16(1.2)).toThrow(TypeError);
38
38
 
39
- expect(() => asInt16(-3.4)).toThrowError(TypeError);
39
+ expect(() => asInt16(-3.4)).toThrow(TypeError);
40
40
  });
41
41
 
42
42
  test('returns the same value for valid inputs', () => {
@@ -58,7 +58,7 @@ describe('Int16 test', () => {
58
58
  { name: '1.2', value: 1.2 },
59
59
  { name: '-3.4', value: -3.4 },
60
60
  ] as const)(`asInt16($name) should throw a TypeError`, ({ value }) => {
61
- expect(() => asInt16(value)).toThrowError(
61
+ expect(() => asInt16(value)).toThrow(
62
62
  new TypeError(`Expected an integer in [-2^15, 2^15), got: ${value}`),
63
63
  );
64
64
  });
@@ -6,37 +6,37 @@ import { asNonZeroInt32 } from './non-zero-int32.mjs';
6
6
  describe('Int32 test', () => {
7
7
  describe(asInt32, () => {
8
8
  test('accepts valid int32 values', () => {
9
- expect(() => asInt32(0)).not.toThrowError();
9
+ expect(() => asInt32(0)).not.toThrow();
10
10
 
11
- expect(() => asInt32(1)).not.toThrowError();
11
+ expect(() => asInt32(1)).not.toThrow();
12
12
 
13
- expect(() => asInt32(-1)).not.toThrowError();
13
+ expect(() => asInt32(-1)).not.toThrow();
14
14
 
15
- expect(() => asInt32(2_147_483_647)).not.toThrowError(); // 2^31 - 1
15
+ expect(() => asInt32(2_147_483_647)).not.toThrow(); // 2^31 - 1
16
16
 
17
- expect(() => asInt32(-2_147_483_648)).not.toThrowError(); // -2^31
17
+ expect(() => asInt32(-2_147_483_648)).not.toThrow(); // -2^31
18
18
  });
19
19
 
20
20
  test('rejects values outside int32 range', () => {
21
- expect(() => asInt32(2_147_483_648)).toThrowError(TypeError); // 2^31
21
+ expect(() => asInt32(2_147_483_648)).toThrow(TypeError); // 2^31
22
22
 
23
- expect(() => asInt32(-2_147_483_649)).toThrowError(TypeError); // -2^31 - 1
23
+ expect(() => asInt32(-2_147_483_649)).toThrow(TypeError); // -2^31 - 1
24
24
 
25
- expect(() => asInt32(4_294_967_296)).toThrowError(TypeError);
25
+ expect(() => asInt32(4_294_967_296)).toThrow(TypeError);
26
26
 
27
- expect(() => asInt32(-4_294_967_296)).toThrowError(TypeError);
27
+ expect(() => asInt32(-4_294_967_296)).toThrow(TypeError);
28
28
  });
29
29
 
30
30
  test('rejects non-integers', () => {
31
- expect(() => asInt32(Number.NaN)).toThrowError(TypeError);
31
+ expect(() => asInt32(Number.NaN)).toThrow(TypeError);
32
32
 
33
- expect(() => asInt32(Number.POSITIVE_INFINITY)).toThrowError(TypeError);
33
+ expect(() => asInt32(Number.POSITIVE_INFINITY)).toThrow(TypeError);
34
34
 
35
- expect(() => asInt32(Number.NEGATIVE_INFINITY)).toThrowError(TypeError);
35
+ expect(() => asInt32(Number.NEGATIVE_INFINITY)).toThrow(TypeError);
36
36
 
37
- expect(() => asInt32(1.2)).toThrowError(TypeError);
37
+ expect(() => asInt32(1.2)).toThrow(TypeError);
38
38
 
39
- expect(() => asInt32(-3.4)).toThrowError(TypeError);
39
+ expect(() => asInt32(-3.4)).toThrow(TypeError);
40
40
  });
41
41
 
42
42
  test('returns the same value for valid inputs', () => {
@@ -58,7 +58,7 @@ describe('Int32 test', () => {
58
58
  { name: '1.2', value: 1.2 },
59
59
  { name: '-3.4', value: -3.4 },
60
60
  ] as const)(`asInt32($name) should throw a TypeError`, ({ value }) => {
61
- expect(() => asInt32(value)).toThrowError(
61
+ expect(() => asInt32(value)).toThrow(
62
62
  new TypeError(`Expected an integer in [-2^31, 2^31), got: ${value}`),
63
63
  );
64
64
  });
@@ -9,41 +9,37 @@ import {
9
9
  describe('NonNegativeFiniteNumber test', () => {
10
10
  describe(asNonNegativeFiniteNumber, () => {
11
11
  test('accepts valid non-negative finite numbers', () => {
12
- expect(() => asNonNegativeFiniteNumber(0)).not.toThrowError();
12
+ expect(() => asNonNegativeFiniteNumber(0)).not.toThrow();
13
13
 
14
- expect(() => asNonNegativeFiniteNumber(1)).not.toThrowError();
14
+ expect(() => asNonNegativeFiniteNumber(1)).not.toThrow();
15
15
 
16
- expect(() => asNonNegativeFiniteNumber(3.14)).not.toThrowError();
16
+ expect(() => asNonNegativeFiniteNumber(3.14)).not.toThrow();
17
17
 
18
- expect(() => asNonNegativeFiniteNumber(0.5)).not.toThrowError();
18
+ expect(() => asNonNegativeFiniteNumber(0.5)).not.toThrow();
19
19
 
20
- expect(() =>
21
- asNonNegativeFiniteNumber(Number.MAX_VALUE),
22
- ).not.toThrowError();
20
+ expect(() => asNonNegativeFiniteNumber(Number.MAX_VALUE)).not.toThrow();
23
21
  });
24
22
 
25
23
  test('rejects negative numbers', () => {
26
- expect(() => asNonNegativeFiniteNumber(-1)).toThrowError(TypeError);
24
+ expect(() => asNonNegativeFiniteNumber(-1)).toThrow(TypeError);
27
25
 
28
- expect(() => asNonNegativeFiniteNumber(-0.1)).toThrowError(TypeError);
26
+ expect(() => asNonNegativeFiniteNumber(-0.1)).toThrow(TypeError);
29
27
 
30
- expect(() => asNonNegativeFiniteNumber(-Number.MAX_VALUE)).toThrowError(
28
+ expect(() => asNonNegativeFiniteNumber(-Number.MAX_VALUE)).toThrow(
31
29
  TypeError,
32
30
  );
33
31
  });
34
32
 
35
33
  test('rejects non-finite numbers', () => {
36
- expect(() => asNonNegativeFiniteNumber(Number.NaN)).toThrowError(
34
+ expect(() => asNonNegativeFiniteNumber(Number.NaN)).toThrow(TypeError);
35
+
36
+ expect(() => asNonNegativeFiniteNumber(Number.POSITIVE_INFINITY)).toThrow(
37
37
  TypeError,
38
38
  );
39
39
 
40
- expect(() =>
41
- asNonNegativeFiniteNumber(Number.POSITIVE_INFINITY),
42
- ).toThrowError(TypeError);
43
-
44
- expect(() =>
45
- asNonNegativeFiniteNumber(Number.NEGATIVE_INFINITY),
46
- ).toThrowError(TypeError);
40
+ expect(() => asNonNegativeFiniteNumber(Number.NEGATIVE_INFINITY)).toThrow(
41
+ TypeError,
42
+ );
47
43
  });
48
44
 
49
45
  test('returns the same value for valid inputs', () => {
@@ -62,7 +58,7 @@ describe('NonNegativeFiniteNumber test', () => {
62
58
  ] as const)(
63
59
  `asNonNegativeFiniteNumber($name) should throw a TypeError`,
64
60
  ({ value }) => {
65
- expect(() => asNonNegativeFiniteNumber(value)).toThrowError(
61
+ expect(() => asNonNegativeFiniteNumber(value)).toThrow(
66
62
  new TypeError(`Expected a non-negative finite number, got: ${value}`),
67
63
  );
68
64
  },
@@ -10,43 +10,43 @@ import { asPositiveInt16 } from './positive-int16.mjs';
10
10
  describe('NonNegativeInt16 test', () => {
11
11
  describe(asNonNegativeInt16, () => {
12
12
  test('accepts valid non-negative int16 values', () => {
13
- expect(() => asNonNegativeInt16(0)).not.toThrowError();
13
+ expect(() => asNonNegativeInt16(0)).not.toThrow();
14
14
 
15
- expect(() => asNonNegativeInt16(1)).not.toThrowError();
15
+ expect(() => asNonNegativeInt16(1)).not.toThrow();
16
16
 
17
- expect(() => asNonNegativeInt16(1000)).not.toThrowError();
17
+ expect(() => asNonNegativeInt16(1000)).not.toThrow();
18
18
 
19
- expect(() => asNonNegativeInt16(32_767)).not.toThrowError(); // 2^15 - 1
19
+ expect(() => asNonNegativeInt16(32_767)).not.toThrow(); // 2^15 - 1
20
20
  });
21
21
 
22
22
  test('rejects negative integers', () => {
23
- expect(() => asNonNegativeInt16(-1)).toThrowError(TypeError);
23
+ expect(() => asNonNegativeInt16(-1)).toThrow(TypeError);
24
24
 
25
- expect(() => asNonNegativeInt16(-42)).toThrowError(TypeError);
25
+ expect(() => asNonNegativeInt16(-42)).toThrow(TypeError);
26
26
 
27
- expect(() => asNonNegativeInt16(-32_768)).toThrowError(TypeError);
27
+ expect(() => asNonNegativeInt16(-32_768)).toThrow(TypeError);
28
28
  });
29
29
 
30
30
  test('rejects values outside int16 range', () => {
31
- expect(() => asNonNegativeInt16(32_768)).toThrowError(TypeError); // 2^15
31
+ expect(() => asNonNegativeInt16(32_768)).toThrow(TypeError); // 2^15
32
32
 
33
- expect(() => asNonNegativeInt16(65_536)).toThrowError(TypeError);
33
+ expect(() => asNonNegativeInt16(65_536)).toThrow(TypeError);
34
34
  });
35
35
 
36
36
  test('rejects non-integers', () => {
37
- expect(() => asNonNegativeInt16(Number.NaN)).toThrowError(TypeError);
37
+ expect(() => asNonNegativeInt16(Number.NaN)).toThrow(TypeError);
38
38
 
39
- expect(() => asNonNegativeInt16(Number.POSITIVE_INFINITY)).toThrowError(
39
+ expect(() => asNonNegativeInt16(Number.POSITIVE_INFINITY)).toThrow(
40
40
  TypeError,
41
41
  );
42
42
 
43
- expect(() => asNonNegativeInt16(Number.NEGATIVE_INFINITY)).toThrowError(
43
+ expect(() => asNonNegativeInt16(Number.NEGATIVE_INFINITY)).toThrow(
44
44
  TypeError,
45
45
  );
46
46
 
47
- expect(() => asNonNegativeInt16(1.2)).toThrowError(TypeError);
47
+ expect(() => asNonNegativeInt16(1.2)).toThrow(TypeError);
48
48
 
49
- expect(() => asNonNegativeInt16(-3.4)).toThrowError(TypeError);
49
+ expect(() => asNonNegativeInt16(-3.4)).toThrow(TypeError);
50
50
  });
51
51
 
52
52
  test('returns the same value for valid inputs', () => {
@@ -68,7 +68,7 @@ describe('NonNegativeInt16 test', () => {
68
68
  ] as const)(
69
69
  `asNonNegativeInt16($name) should throw a TypeError`,
70
70
  ({ value }) => {
71
- expect(() => asNonNegativeInt16(value)).toThrowError(
71
+ expect(() => asNonNegativeInt16(value)).toThrow(
72
72
  new TypeError(
73
73
  `Expected a non-negative integer in [0, 2^15), got: ${value}`,
74
74
  ),