ts-data-forge 6.4.0 → 6.6.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 (181) hide show
  1. package/README.md +5 -3
  2. package/dist/array/impl/array-utils-element-access.d.mts +5 -5
  3. package/dist/array/impl/array-utils-element-access.mjs +4 -4
  4. package/dist/array/impl/array-utils-iterators.d.mts +1 -1
  5. package/dist/array/impl/array-utils-iterators.mjs +1 -1
  6. package/dist/array/impl/array-utils-modification.d.mts +4 -4
  7. package/dist/array/impl/array-utils-reducing-value.d.mts +5 -5
  8. package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
  9. package/dist/array/impl/array-utils-reducing-value.mjs +1 -0
  10. package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
  11. package/dist/array/impl/array-utils-search.d.mts +8 -8
  12. package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
  13. package/dist/array/impl/array-utils-set-op.mjs +3 -1
  14. package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
  15. package/dist/array/impl/array-utils-size.d.mts +1 -1
  16. package/dist/array/impl/array-utils-size.mjs +1 -1
  17. package/dist/array/impl/array-utils-slice-clamped.d.mts +1 -1
  18. package/dist/array/impl/array-utils-slicing.d.mts +3 -3
  19. package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
  20. package/dist/array/impl/array-utils-validation.d.mts +7 -7
  21. package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
  22. package/dist/array/impl/array-utils-validation.mjs +22 -12
  23. package/dist/array/impl/array-utils-validation.mjs.map +1 -1
  24. package/dist/collections/imap-mapped.d.mts +5 -12
  25. package/dist/collections/imap-mapped.d.mts.map +1 -1
  26. package/dist/collections/imap-mapped.mjs.map +1 -1
  27. package/dist/collections/imap.d.mts +24 -28
  28. package/dist/collections/imap.d.mts.map +1 -1
  29. package/dist/collections/imap.mjs +1 -1
  30. package/dist/collections/imap.mjs.map +1 -1
  31. package/dist/collections/iset-mapped.d.mts +8 -14
  32. package/dist/collections/iset-mapped.d.mts.map +1 -1
  33. package/dist/collections/iset-mapped.mjs.map +1 -1
  34. package/dist/collections/iset.d.mts +9 -23
  35. package/dist/collections/iset.d.mts.map +1 -1
  36. package/dist/collections/iset.mjs +1 -0
  37. package/dist/collections/iset.mjs.map +1 -1
  38. package/dist/entry-point.mjs +1 -0
  39. package/dist/entry-point.mjs.map +1 -1
  40. package/dist/functional/optional/impl/optional-is-optional.d.mts +1 -1
  41. package/dist/functional/optional/impl/optional-is-optional.d.mts.map +1 -1
  42. package/dist/functional/optional/impl/optional-is-optional.mjs +6 -5
  43. package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
  44. package/dist/functional/optional/impl/optional-some.d.mts.map +1 -1
  45. package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
  46. package/dist/functional/optional/impl/optional-zip.d.mts +1 -1
  47. package/dist/functional/optional/impl/optional-zip.mjs +1 -1
  48. package/dist/functional/result/impl/result-err.d.mts.map +1 -1
  49. package/dist/functional/result/impl/result-err.mjs.map +1 -1
  50. package/dist/functional/result/impl/result-is-result.d.mts +1 -1
  51. package/dist/functional/result/impl/result-is-result.mjs +1 -1
  52. package/dist/functional/result/impl/result-ok.d.mts.map +1 -1
  53. package/dist/functional/result/impl/result-ok.mjs.map +1 -1
  54. package/dist/functional/result/impl/result-unwrap-err-throw.mjs +1 -0
  55. package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
  56. package/dist/functional/result/impl/result-unwrap-throw.mjs +1 -0
  57. package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
  58. package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +1 -1
  59. package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -1
  60. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +1 -1
  61. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +1 -1
  62. package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +1 -1
  63. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -1
  64. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +1 -0
  65. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -1
  66. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +1 -0
  67. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -1
  68. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +1 -0
  69. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -1
  70. package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +1 -1
  71. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -1
  72. package/dist/guard/has-key.d.mts +3 -1
  73. package/dist/guard/has-key.d.mts.map +1 -1
  74. package/dist/guard/has-key.mjs +6 -2
  75. package/dist/guard/has-key.mjs.map +1 -1
  76. package/dist/guard/is-non-null-object.d.mts.map +1 -1
  77. package/dist/guard/is-non-null-object.mjs +3 -1
  78. package/dist/guard/is-non-null-object.mjs.map +1 -1
  79. package/dist/guard/is-record.d.mts +2 -2
  80. package/dist/guard/is-record.mjs +2 -2
  81. package/dist/guard/is-type.d.mts +15 -15
  82. package/dist/guard/is-type.mjs +15 -15
  83. package/dist/guard/key-is-in.d.mts.map +1 -1
  84. package/dist/guard/key-is-in.mjs +3 -1
  85. package/dist/guard/key-is-in.mjs.map +1 -1
  86. package/dist/index.mjs +1 -0
  87. package/dist/index.mjs.map +1 -1
  88. package/dist/json/json.d.mts +3 -3
  89. package/dist/json/json.mjs +4 -3
  90. package/dist/json/json.mjs.map +1 -1
  91. package/dist/number/branded-types/non-zero-safe-int.mjs +2 -2
  92. package/dist/number/branded-types/positive-safe-int.mjs +1 -1
  93. package/dist/number/branded-types/safe-int.mjs +2 -2
  94. package/dist/number/branded-types/safe-uint.mjs +1 -1
  95. package/dist/number/num.mjs +1 -1
  96. package/dist/object/object.d.mts +36 -8
  97. package/dist/object/object.d.mts.map +1 -1
  98. package/dist/object/object.mjs +28 -6
  99. package/dist/object/object.mjs.map +1 -1
  100. package/dist/others/fast-deep-equal.d.mts +8 -0
  101. package/dist/others/fast-deep-equal.d.mts.map +1 -0
  102. package/dist/others/fast-deep-equal.mjs +72 -0
  103. package/dist/others/fast-deep-equal.mjs.map +1 -0
  104. package/dist/others/index.d.mts +1 -0
  105. package/dist/others/index.d.mts.map +1 -1
  106. package/dist/others/index.mjs +1 -0
  107. package/dist/others/index.mjs.map +1 -1
  108. package/package.json +34 -29
  109. package/src/array/impl/array-utils-creation.test.mts +13 -10
  110. package/src/array/impl/array-utils-element-access.mts +5 -5
  111. package/src/array/impl/array-utils-element-access.test.mts +5 -5
  112. package/src/array/impl/array-utils-iterators.mts +1 -1
  113. package/src/array/impl/array-utils-iterators.test.mts +6 -6
  114. package/src/array/impl/array-utils-modification.mts +4 -4
  115. package/src/array/impl/array-utils-modification.test.mts +12 -12
  116. package/src/array/impl/array-utils-overload-type-error.test.mts +1 -1
  117. package/src/array/impl/array-utils-reducing-value.mts +6 -5
  118. package/src/array/impl/array-utils-reducing-value.test.mts +9 -9
  119. package/src/array/impl/array-utils-search.mts +8 -8
  120. package/src/array/impl/array-utils-search.test.mts +35 -35
  121. package/src/array/impl/array-utils-set-op.mts +1 -0
  122. package/src/array/impl/array-utils-set-op.test.mts +2 -2
  123. package/src/array/impl/array-utils-size.mts +1 -1
  124. package/src/array/impl/array-utils-size.test.mts +1 -1
  125. package/src/array/impl/array-utils-slice-clamped.mts +1 -1
  126. package/src/array/impl/array-utils-slice-clamped.test.mts +5 -5
  127. package/src/array/impl/array-utils-slicing.mts +3 -3
  128. package/src/array/impl/array-utils-slicing.test.mts +5 -5
  129. package/src/array/impl/array-utils-transformation.mts +1 -1
  130. package/src/array/impl/array-utils-transformation.test.mts +53 -53
  131. package/src/array/impl/array-utils-validation.mts +18 -10
  132. package/src/array/impl/array-utils-validation.test.mts +34 -29
  133. package/src/array/impl/array.test.mts +1 -1
  134. package/src/collections/imap-mapped.mts +4 -10
  135. package/src/collections/imap-mapped.test.mts +9 -9
  136. package/src/collections/imap.mts +24 -27
  137. package/src/collections/imap.test.mts +6 -6
  138. package/src/collections/iset-mapped.mts +12 -16
  139. package/src/collections/iset-mapped.test.mts +6 -6
  140. package/src/collections/iset.mts +14 -25
  141. package/src/collections/queue.test.mts +2 -1
  142. package/src/collections/stack.test.mts +3 -3
  143. package/src/functional/optional/impl/optional-is-optional.mts +6 -6
  144. package/src/functional/optional/impl/optional-some.mts +5 -4
  145. package/src/functional/optional/impl/optional-zip.mts +1 -1
  146. package/src/functional/result/impl/result-err.mts +5 -4
  147. package/src/functional/result/impl/result-is-result.mts +1 -1
  148. package/src/functional/result/impl/result-ok.mts +5 -4
  149. package/src/functional/result.test.mts +2 -2
  150. package/src/functional/ternary-result/impl/ternary-result-err.mts +5 -4
  151. package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +1 -1
  152. package/src/functional/ternary-result/impl/ternary-result-ok.mts +5 -4
  153. package/src/functional/ternary-result/impl/ternary-result-warn.mts +6 -5
  154. package/src/guard/has-key.mts +6 -2
  155. package/src/guard/is-error.test.mts +1 -1
  156. package/src/guard/is-non-empty-string.test.mts +1 -1
  157. package/src/guard/is-non-null-object.mts +1 -0
  158. package/src/guard/is-non-null-object.test.mts +4 -3
  159. package/src/guard/is-primitive.test.mts +1 -1
  160. package/src/guard/is-record.mts +2 -2
  161. package/src/guard/is-record.test.mts +2 -2
  162. package/src/guard/is-type.mts +15 -15
  163. package/src/guard/is-type.test.mts +2 -2
  164. package/src/guard/key-is-in.mts +3 -1
  165. package/src/json/json.mts +4 -3
  166. package/src/json/json.test.mts +20 -19
  167. package/src/number/branded-types/non-zero-safe-int.mts +2 -2
  168. package/src/number/branded-types/positive-safe-int.mts +1 -1
  169. package/src/number/branded-types/safe-int.mts +2 -2
  170. package/src/number/branded-types/safe-uint.mts +1 -1
  171. package/src/number/num.mts +1 -1
  172. package/src/object/object.mts +54 -8
  173. package/src/object/object.test.mts +70 -7
  174. package/src/others/cast-mutable.test.mts +3 -3
  175. package/src/others/cast-readonly.test.mts +10 -5
  176. package/src/others/fast-deep-equal.mts +98 -0
  177. package/src/others/fast-deep-equal.test.mts +771 -0
  178. package/src/others/index.mts +1 -0
  179. package/src/others/map-nullable.test.mts +8 -8
  180. package/src/others/memoize-function.test.mts +20 -8
  181. package/src/others/unknown-to-string.test.mts +8 -8
@@ -65,7 +65,7 @@ describe('Arr transformations', () => {
65
65
 
66
66
  describe(scan, () => {
67
67
  test('should compute running sum', () => {
68
- const numbers = [1, 2, 3, 4];
68
+ const numbers = [1, 2, 3, 4] as const;
69
69
 
70
70
  const runningSum = scan(numbers, (acc, curr) => acc + curr, 0);
71
71
 
@@ -75,7 +75,7 @@ describe('Arr transformations', () => {
75
75
  });
76
76
 
77
77
  test('should include initial value as first element', () => {
78
- const numbers = [10, 20, 30];
78
+ const numbers = [10, 20, 30] as const;
79
79
 
80
80
  const result = scan(numbers, (acc, curr) => acc + curr, 100);
81
81
 
@@ -97,7 +97,7 @@ describe('Arr transformations', () => {
97
97
  });
98
98
 
99
99
  test('should provide index to reducer', () => {
100
- const numbers = [10, 20, 30];
100
+ const numbers = [10, 20, 30] as const;
101
101
 
102
102
  const mut_indices: number[] = [];
103
103
 
@@ -115,7 +115,7 @@ describe('Arr transformations', () => {
115
115
  });
116
116
 
117
117
  test('should work with empty array', () => {
118
- const empty: readonly number[] = [];
118
+ const empty: readonly number[] = [] as const;
119
119
 
120
120
  const result = scan(empty, (acc, curr) => acc + curr, 42);
121
121
 
@@ -123,7 +123,7 @@ describe('Arr transformations', () => {
123
123
  });
124
124
 
125
125
  test('should work with different accumulator and element types', () => {
126
- const strings = ['a', 'b', 'c'];
126
+ const strings = ['a', 'b', 'c'] as const;
127
127
 
128
128
  const result = scan(strings, (acc, curr) => acc + curr.length, 0);
129
129
 
@@ -133,7 +133,7 @@ describe('Arr transformations', () => {
133
133
  });
134
134
 
135
135
  test('should compute running product', () => {
136
- const numbers = [2, 3, 4];
136
+ const numbers = [2, 3, 4] as const;
137
137
 
138
138
  const runningProduct = scan(numbers, (acc, curr) => acc * curr, 1);
139
139
 
@@ -149,7 +149,7 @@ describe('Arr transformations', () => {
149
149
  });
150
150
 
151
151
  test('should preserve all intermediate values', () => {
152
- const numbers = [1, 2, 3];
152
+ const numbers = [1, 2, 3] as const;
153
153
 
154
154
  const result = scan(numbers, (acc, curr) => acc - curr, 10);
155
155
 
@@ -285,7 +285,7 @@ describe('Arr transformations', () => {
285
285
  { name: 'Alice', age: 30 },
286
286
  { name: 'Bob', age: 20 },
287
287
  { name: 'Charlie', age: 25 },
288
- ];
288
+ ] as readonly Readonly<{ name: string; age: number }>[];
289
289
 
290
290
  const result = toSortedBy(people, (person) => person.age);
291
291
 
@@ -299,7 +299,7 @@ describe('Arr transformations', () => {
299
299
  });
300
300
 
301
301
  test('should work with string sorting', () => {
302
- const words = ['banana', 'apple', 'cherry'];
302
+ const words = ['banana', 'apple', 'cherry'] as const;
303
303
 
304
304
  const result = toSortedBy(
305
305
  words,
@@ -311,7 +311,7 @@ describe('Arr transformations', () => {
311
311
  });
312
312
 
313
313
  test('should work with custom key extraction', () => {
314
- const items = ['hello', 'hi', 'welcome', 'bye'];
314
+ const items = ['hello', 'hi', 'welcome', 'bye'] as const;
315
315
 
316
316
  const result = toSortedBy(items, (item) => item.length);
317
317
 
@@ -319,7 +319,7 @@ describe('Arr transformations', () => {
319
319
  });
320
320
 
321
321
  test('should work with empty array', () => {
322
- const empty: readonly Readonly<{ value: number }>[] = [];
322
+ const empty: readonly Readonly<{ value: number }>[] = [] as const;
323
323
 
324
324
  const result = toSortedBy(empty, (item) => item.value);
325
325
 
@@ -327,7 +327,7 @@ describe('Arr transformations', () => {
327
327
  });
328
328
 
329
329
  test('toSortedBy should work with empty array', () => {
330
- const empty: readonly Readonly<{ value: number }>[] = [];
330
+ const empty: readonly Readonly<{ value: number }>[] = [] as const;
331
331
 
332
332
  const result = toSortedBy(empty, (item) => item.value);
333
333
 
@@ -337,7 +337,7 @@ describe('Arr transformations', () => {
337
337
 
338
338
  describe(filter, () => {
339
339
  test('should filter array with predicate', () => {
340
- const numbers = [1, 2, 3, 4, 5];
340
+ const numbers = [1, 2, 3, 4, 5] as const;
341
341
 
342
342
  const evens = filter(numbers, (n) => n % 2 === 0);
343
343
 
@@ -351,7 +351,7 @@ describe('Arr transformations', () => {
351
351
  null,
352
352
  'world',
353
353
  123,
354
- ];
354
+ ] as const;
355
355
 
356
356
  const strings = filter(mixed, (x): x is string => typeof x === 'string');
357
357
 
@@ -393,7 +393,7 @@ describe('Arr transformations', () => {
393
393
  });
394
394
 
395
395
  test('should work with empty array', () => {
396
- const empty: readonly number[] = [];
396
+ const empty: readonly number[] = [] as const;
397
397
 
398
398
  const result = filter(empty, (n) => n > 0);
399
399
 
@@ -401,7 +401,7 @@ describe('Arr transformations', () => {
401
401
  });
402
402
 
403
403
  test('should pass index to predicate', () => {
404
- const numbers = [10, 20, 30, 40];
404
+ const numbers = [10, 20, 30, 40] as const;
405
405
 
406
406
  const evenIndexes = filter(numbers, (_, i) => i % 2 === 0);
407
407
 
@@ -423,7 +423,7 @@ describe('Arr transformations', () => {
423
423
 
424
424
  describe(uniq, () => {
425
425
  test('should remove duplicate primitives', () => {
426
- const array = [1, 2, 2, 3, 1, 4, 3];
426
+ const array = [1, 2, 2, 3, 1, 4, 3] as const;
427
427
 
428
428
  const result = uniq(array);
429
429
 
@@ -431,7 +431,7 @@ describe('Arr transformations', () => {
431
431
  });
432
432
 
433
433
  test('should work with strings', () => {
434
- const array = ['a', 'b', 'a', 'c', 'b'];
434
+ const array = ['a', 'b', 'a', 'c', 'b'] as const;
435
435
 
436
436
  const result = uniq(array);
437
437
 
@@ -439,7 +439,7 @@ describe('Arr transformations', () => {
439
439
  });
440
440
 
441
441
  test('should work with empty array', () => {
442
- const array: readonly number[] = [];
442
+ const array: readonly number[] = [] as const;
443
443
 
444
444
  const result = uniq(array);
445
445
 
@@ -447,7 +447,7 @@ describe('Arr transformations', () => {
447
447
  });
448
448
 
449
449
  test('should preserve order of first occurrence', () => {
450
- const array = [3, 1, 2, 1, 3, 2];
450
+ const array = [3, 1, 2, 1, 3, 2] as const;
451
451
 
452
452
  const result = uniq(array);
453
453
 
@@ -462,7 +462,7 @@ describe('Arr transformations', () => {
462
462
  { id: 2, name: 'Bob' },
463
463
  { id: 1, name: 'Alice Duplicate' },
464
464
  { id: 3, name: 'Charlie' },
465
- ];
465
+ ] as const;
466
466
 
467
467
  const result = uniqBy(array, (item) => item.id);
468
468
 
@@ -476,7 +476,7 @@ describe('Arr transformations', () => {
476
476
  });
477
477
 
478
478
  test('should work with string key function', () => {
479
- const words = ['hello', 'world', 'hi', 'welcome'];
479
+ const words = ['hello', 'world', 'hi', 'welcome'] as const;
480
480
 
481
481
  const result = uniqBy(words, (word) => word.length);
482
482
 
@@ -490,7 +490,7 @@ describe('Arr transformations', () => {
490
490
  });
491
491
 
492
492
  test('should work with empty array', () => {
493
- const empty: readonly Readonly<{ id: number }>[] = [];
493
+ const empty: readonly Readonly<{ id: number }>[] = [] as const;
494
494
 
495
495
  const result = uniqBy(empty, (item) => item.id);
496
496
 
@@ -504,7 +504,7 @@ describe('Arr transformations', () => {
504
504
  [1, 2],
505
505
  [3, 4],
506
506
  [5, 6],
507
- ];
507
+ ] as const;
508
508
 
509
509
  const flattened = flat(nested);
510
510
 
@@ -512,7 +512,7 @@ describe('Arr transformations', () => {
512
512
  });
513
513
 
514
514
  test('should flatten with specified depth', () => {
515
- const deepNested = [1, [2, [3, 4]], 5];
515
+ const deepNested = [1, [2, [3, 4]], 5] as const;
516
516
 
517
517
  const flat1 = flat(deepNested, 1);
518
518
 
@@ -535,7 +535,7 @@ describe('Arr transformations', () => {
535
535
  });
536
536
 
537
537
  test('should work with empty arrays', () => {
538
- const withEmpties = [[1], [], [2, 3]];
538
+ const withEmpties = [[1], [], [2, 3]] as const;
539
539
 
540
540
  const flattened = flat(withEmpties);
541
541
 
@@ -546,7 +546,7 @@ describe('Arr transformations', () => {
546
546
  const nested = [
547
547
  [1, 2],
548
548
  [3, 4],
549
- ];
549
+ ] as const;
550
550
 
551
551
  const unflattened = flat(nested, 0);
552
552
 
@@ -557,7 +557,7 @@ describe('Arr transformations', () => {
557
557
  });
558
558
 
559
559
  test('should work with infinite depth', () => {
560
- const veryDeep = [1, [2, [3, [4, [5]]]]];
560
+ const veryDeep = [1, [2, [3, [4, [5]]]]] as const;
561
561
 
562
562
  const allFlat = flat(veryDeep, SafeUint.MAX_VALUE);
563
563
 
@@ -567,7 +567,7 @@ describe('Arr transformations', () => {
567
567
 
568
568
  describe(flatMap, () => {
569
569
  test('should map and flatten results', () => {
570
- const words = ['hello', 'world'];
570
+ const words = ['hello', 'world'] as const;
571
571
 
572
572
  const chars = flatMap(words, (word) => word.split(''));
573
573
 
@@ -594,7 +594,7 @@ describe('Arr transformations', () => {
594
594
  });
595
595
 
596
596
  test('should work with numbers', () => {
597
- const numbers = [1, 2, 3];
597
+ const numbers = [1, 2, 3] as const;
598
598
 
599
599
  const doubled = flatMap(numbers, (n) => [n, n * 2]);
600
600
 
@@ -602,7 +602,7 @@ describe('Arr transformations', () => {
602
602
  });
603
603
 
604
604
  test('should pass index to mapping function', () => {
605
- const numbers = [10, 20];
605
+ const numbers = [10, 20] as const;
606
606
 
607
607
  const result = flatMap(numbers, (n, i) => [n, i]);
608
608
 
@@ -610,7 +610,7 @@ describe('Arr transformations', () => {
610
610
  });
611
611
 
612
612
  test('should work with empty arrays', () => {
613
- const empty: readonly string[] = [];
613
+ const empty: readonly string[] = [] as const;
614
614
 
615
615
  const result = flatMap(empty, (s) => s.split(''));
616
616
 
@@ -618,7 +618,7 @@ describe('Arr transformations', () => {
618
618
  });
619
619
 
620
620
  test('should handle mapping to empty arrays', () => {
621
- const numbers = [1, 2, 3];
621
+ const numbers = [1, 2, 3] as const;
622
622
 
623
623
  const result = flatMap(numbers, (n) => (n % 2 === 0 ? [n] : []));
624
624
 
@@ -729,7 +729,7 @@ describe('Arr transformations', () => {
729
729
  }
730
730
 
731
731
  test('should partition array into chunks', () => {
732
- const numbers = [1, 2, 3, 4, 5, 6];
732
+ const numbers = [1, 2, 3, 4, 5, 6] as const;
733
733
 
734
734
  const result = partition(numbers, 2);
735
735
 
@@ -741,7 +741,7 @@ describe('Arr transformations', () => {
741
741
  });
742
742
 
743
743
  test('should handle arrays not evenly divisible by chunk size', () => {
744
- const numbers = [1, 2, 3, 4, 5];
744
+ const numbers = [1, 2, 3, 4, 5] as const;
745
745
 
746
746
  const result = partition(numbers, 2);
747
747
 
@@ -749,7 +749,7 @@ describe('Arr transformations', () => {
749
749
  });
750
750
 
751
751
  test('should work with chunk size < 2 (returns empty)', () => {
752
- const numbers = [1, 2, 3];
752
+ const numbers = [1, 2, 3] as const;
753
753
 
754
754
  const result = partition(numbers, 1);
755
755
 
@@ -758,7 +758,7 @@ describe('Arr transformations', () => {
758
758
  });
759
759
 
760
760
  test('should work with chunk size larger than array', () => {
761
- const numbers = [1, 2];
761
+ const numbers = [1, 2] as const;
762
762
 
763
763
  const result = partition(numbers, 5);
764
764
 
@@ -766,7 +766,7 @@ describe('Arr transformations', () => {
766
766
  });
767
767
 
768
768
  test('partition should work with empty array', () => {
769
- const empty: readonly number[] = [];
769
+ const empty: readonly number[] = [] as const;
770
770
 
771
771
  const result = partition(empty, 2);
772
772
 
@@ -884,7 +884,7 @@ describe('Arr transformations', () => {
884
884
  { type: 'fruit', name: 'apple' },
885
885
  { type: 'vegetable', name: 'carrot' },
886
886
  { type: 'fruit', name: 'banana' },
887
- ];
887
+ ] as const;
888
888
 
889
889
  const grouped = groupBy(array, (item) => item.type);
890
890
 
@@ -914,7 +914,7 @@ describe('Arr transformations', () => {
914
914
  });
915
915
 
916
916
  test('should work with numeric keys', () => {
917
- const numbers = [1, 2, 3, 4, 5, 6];
917
+ const numbers = [1, 2, 3, 4, 5, 6] as const;
918
918
 
919
919
  const grouped = groupBy(numbers, (n) => n % 2);
920
920
 
@@ -934,7 +934,7 @@ describe('Arr transformations', () => {
934
934
  });
935
935
 
936
936
  test('should work with empty array', () => {
937
- const empty: readonly number[] = [];
937
+ const empty: readonly number[] = [] as const;
938
938
 
939
939
  const grouped = groupBy(empty, (n) => n % 2);
940
940
 
@@ -942,7 +942,7 @@ describe('Arr transformations', () => {
942
942
  });
943
943
 
944
944
  test('should handle all elements in same group', () => {
945
- const array = [1, 2, 3, 4];
945
+ const array = [1, 2, 3, 4] as const;
946
946
 
947
947
  const grouped = groupBy(array, () => 'all');
948
948
 
@@ -979,9 +979,9 @@ describe('Arr transformations', () => {
979
979
  }
980
980
 
981
981
  {
982
- const xs: readonly number[] = [1, 2, 3];
982
+ const xs: readonly number[] = [1, 2, 3] as const;
983
983
 
984
- const ys: readonly number[] = [4];
984
+ const ys: readonly number[] = [4] as const;
985
985
 
986
986
  const zipped = zip(xs, ys);
987
987
 
@@ -995,7 +995,7 @@ describe('Arr transformations', () => {
995
995
  {
996
996
  const xs = [1] as const;
997
997
 
998
- const ys: readonly number[] = [4, 5, 6];
998
+ const ys: readonly number[] = [4, 5, 6] as const;
999
999
 
1000
1000
  const zipped = zip(xs, ys);
1001
1001
 
@@ -1047,9 +1047,9 @@ describe('Arr transformations', () => {
1047
1047
  // });
1048
1048
 
1049
1049
  test('should zip two arrays', () => {
1050
- const arr1 = [1, 2, 3];
1050
+ const arr1 = [1, 2, 3] as const;
1051
1051
 
1052
- const arr2 = ['a', 'b', 'c'];
1052
+ const arr2 = ['a', 'b', 'c'] as const;
1053
1053
 
1054
1054
  const result = zip(arr1, arr2);
1055
1055
 
@@ -1061,9 +1061,9 @@ describe('Arr transformations', () => {
1061
1061
  });
1062
1062
 
1063
1063
  test('should handle arrays of different lengths', () => {
1064
- const arr1 = [1, 2, 3, 4];
1064
+ const arr1 = [1, 2, 3, 4] as const;
1065
1065
 
1066
- const arr2 = ['a', 'b'];
1066
+ const arr2 = ['a', 'b'] as const;
1067
1067
 
1068
1068
  const result = zip(arr1, arr2);
1069
1069
 
@@ -1074,9 +1074,9 @@ describe('Arr transformations', () => {
1074
1074
  });
1075
1075
 
1076
1076
  test('should work with empty arrays', () => {
1077
- const arr1: readonly number[] = [];
1077
+ const arr1: readonly number[] = [] as const;
1078
1078
 
1079
- const arr2: readonly string[] = [];
1079
+ const arr2: readonly string[] = [] as const;
1080
1080
 
1081
1081
  const result = zip(arr1, arr2);
1082
1082
 
@@ -1084,9 +1084,9 @@ describe('Arr transformations', () => {
1084
1084
  });
1085
1085
 
1086
1086
  test('should handle one empty array', () => {
1087
- const arr1 = [1, 2, 3];
1087
+ const arr1 = [1, 2, 3] as readonly number[];
1088
1088
 
1089
- const arr2: readonly string[] = [];
1089
+ const arr2: readonly string[] = [] as const;
1090
1090
 
1091
1091
  const result = zip(arr1, arr2);
1092
1092
 
@@ -6,7 +6,7 @@ import { asUint32, Num } from '../../number/index.mjs';
6
6
  * @example
7
7
  *
8
8
  * ```ts
9
- * const maybeArray: unknown = [1, 2, 3];
9
+ * const maybeArray: unknown = [1, 2, 3] as const;
10
10
  *
11
11
  * const maybeValue: unknown = 'Ada';
12
12
  *
@@ -20,6 +20,7 @@ import { asUint32, Num } from '../../number/index.mjs';
20
20
  * ```
21
21
  */
22
22
  export const isArray = <E,>(value: E): value is FilterArray<E> =>
23
+ // eslint-disable-next-line ts-data-forge/prefer-arr-is-array
23
24
  Array.isArray(value);
24
25
 
25
26
  type FilterArray<T> = T extends T
@@ -55,6 +56,7 @@ type Cast<A, B> = A extends B ? A : never;
55
56
  * ```
56
57
  */
57
58
  export const isEmpty = <E,>(array: readonly E[]): array is readonly [] =>
59
+ // eslint-disable-next-line ts-data-forge/prefer-arr-is-array-of-length
58
60
  array.length === 0;
59
61
 
60
62
  /**
@@ -63,9 +65,9 @@ export const isEmpty = <E,>(array: readonly E[]): array is readonly [] =>
63
65
  * @example
64
66
  *
65
67
  * ```ts
66
- * const users: readonly Readonly<{ id: number }>[] = [{ id: 1 }];
68
+ * const users: readonly Readonly<{ id: number }>[] = [{ id: 1 }] as const;
67
69
  *
68
- * const emptyUsers: readonly Readonly<{ id: number }>[] = [];
70
+ * const emptyUsers: readonly Readonly<{ id: number }>[] = [] as const;
69
71
  *
70
72
  * assert.isTrue(Arr.isNonEmpty(users));
71
73
  *
@@ -78,7 +80,9 @@ export const isEmpty = <E,>(array: readonly E[]): array is readonly [] =>
78
80
  */
79
81
  export const isNonEmpty = <E,>(
80
82
  array: readonly E[],
81
- ): array is NonEmptyArray<E> => array.length > 0;
83
+ ): array is NonEmptyArray<E> =>
84
+ // eslint-disable-next-line ts-data-forge/prefer-arr-is-non-empty
85
+ array.length > 0;
82
86
 
83
87
  /**
84
88
  * Checks if an array has a specific length.
@@ -86,9 +90,9 @@ export const isNonEmpty = <E,>(
86
90
  * @example
87
91
  *
88
92
  * ```ts
89
- * const pair: readonly number[] = [1, 2];
93
+ * const pair: readonly number[] = [1, 2] as const;
90
94
  *
91
- * const triple: readonly number[] = [1, 2, 3];
95
+ * const triple: readonly number[] = [1, 2, 3] as const;
92
96
  *
93
97
  * assert.isTrue(Arr.isArrayOfLength(pair, 2));
94
98
  *
@@ -102,7 +106,9 @@ export const isNonEmpty = <E,>(
102
106
  export const isArrayOfLength = <E, N extends SizeType.ArgArr>(
103
107
  array: readonly E[],
104
108
  len: N,
105
- ): array is ArrayOfLength<N, E> => array.length === len;
109
+ ): array is ArrayOfLength<N, E> =>
110
+ // eslint-disable-next-line ts-data-forge/prefer-arr-is-array-of-length
111
+ array.length === len;
106
112
 
107
113
  /**
108
114
  * Checks if an array has at least a specific length.
@@ -110,9 +116,9 @@ export const isArrayOfLength = <E, N extends SizeType.ArgArr>(
110
116
  * @example
111
117
  *
112
118
  * ```ts
113
- * const queue: readonly string[] = ['task-1', 'task-2'];
119
+ * const queue: readonly string[] = ['task-1', 'task-2'] as const;
114
120
  *
115
- * const emptyQueue: readonly string[] = [];
121
+ * const emptyQueue: readonly string[] = [] as const;
116
122
  *
117
123
  * assert.isTrue(Arr.isArrayAtLeastLength(queue, 1));
118
124
  *
@@ -126,7 +132,9 @@ export const isArrayOfLength = <E, N extends SizeType.ArgArr>(
126
132
  export const isArrayAtLeastLength = <E, N extends SizeType.ArgArr>(
127
133
  array: readonly E[],
128
134
  len: N,
129
- ): array is ArrayAtLeastLen<N, E> => array.length >= len;
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;
130
138
 
131
139
  /**
132
140
  * Tests whether all elements in an array pass a test implemented by a predicate.