ts-data-forge 7.0.0 → 7.1.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/array/impl/array-utils-creation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-creation.mjs +1 -1
- package/dist/array/impl/array-utils-creation.mjs.map +1 -1
- package/dist/array/impl/array-utils-iterators.mjs +1 -1
- package/dist/array/impl/array-utils-iterators.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +0 -1
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.d.mts +0 -2
- package/dist/array/impl/array-utils-search.d.mts.map +1 -1
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-set-op.mjs +0 -1
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +2 -4
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts +41 -1
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +44 -10
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/array/impl/index.mjs +1 -1
- package/dist/collections/imap-mapped.d.mts +622 -3
- package/dist/collections/imap-mapped.d.mts.map +1 -1
- package/dist/collections/imap-mapped.mjs +111 -18
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts +3 -3
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +6 -5
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +4 -4
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs +8 -4
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.d.mts +2 -2
- package/dist/collections/iset.d.mts.map +1 -1
- package/dist/collections/iset.mjs +5 -2
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.mjs +20 -20
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.mjs +17 -17
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-flat-map.d.mts +2 -2
- package/dist/functional/pipe.d.mts.map +1 -1
- package/dist/functional/pipe.mjs.map +1 -1
- package/dist/functional/result/impl/result-flat-map.d.mts +2 -2
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts +5 -3
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -1
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +1 -3
- package/dist/guard/has-key.mjs.map +1 -1
- package/dist/guard/is-non-null-object.d.mts.map +1 -1
- package/dist/guard/is-non-null-object.mjs +1 -3
- package/dist/guard/is-non-null-object.mjs.map +1 -1
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +1 -3
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/json/json.mjs +5 -7
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +2 -2
- package/dist/number/branded-types/positive-safe-int.mjs +1 -1
- package/dist/number/branded-types/safe-int.mjs +2 -2
- package/dist/number/branded-types/safe-uint.mjs +1 -1
- package/dist/number/num-arithmetic-types.d.mts.map +1 -1
- package/dist/number/num.mjs +3 -3
- package/dist/object/object.mjs +1 -1
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/fast-deep-equal.d.mts.map +1 -1
- package/dist/others/fast-deep-equal.mjs +0 -1
- package/dist/others/fast-deep-equal.mjs.map +1 -1
- package/dist/others/unknown-to-string.mjs +2 -2
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/package.json +5 -5
- package/src/array/impl/array-utils-creation.mts +1 -1
- package/src/array/impl/array-utils-iterators.mts +1 -1
- package/src/array/impl/array-utils-reducing-value.mts +1 -2
- package/src/array/impl/array-utils-search.mts +0 -2
- package/src/array/impl/array-utils-set-op.mts +0 -1
- package/src/array/impl/array-utils-transformation.mts +8 -6
- package/src/array/impl/array-utils-validation.mts +57 -5
- package/src/array/impl/array-utils-validation.test.mts +160 -1
- package/src/collections/imap-mapped.mts +696 -34
- package/src/collections/imap-mapped.test.mts +61 -13
- package/src/collections/imap.mts +20 -9
- package/src/collections/imap.test.mts +9 -8
- package/src/collections/iset-mapped.mts +18 -10
- package/src/collections/iset-mapped.test.mts +6 -1
- package/src/collections/iset.mts +11 -4
- package/src/collections/iset.test.mts +6 -8
- package/src/collections/queue.mts +32 -32
- package/src/collections/stack.mts +26 -26
- package/src/functional/optional/impl/optional-flat-map.mts +2 -2
- package/src/functional/optional.test.mts +6 -4
- package/src/functional/pipe.mts +0 -1
- package/src/functional/pipe.test.mts +2 -1
- package/src/functional/result/impl/result-flat-map.mts +2 -2
- package/src/functional/result.test.mts +3 -2
- package/src/functional/ternary-result/impl/ternary-result-flat-map.mts +5 -3
- package/src/functional/ternary-result.test.mts +8 -3
- package/src/guard/has-key.mts +1 -3
- package/src/guard/is-non-null-object.mts +0 -1
- package/src/guard/key-is-in.mts +1 -3
- package/src/json/json.mts +5 -8
- package/src/json/json.test.mts +2 -2
- package/src/number/branded-types/non-zero-safe-int.mts +2 -2
- package/src/number/branded-types/positive-safe-int.mts +1 -1
- package/src/number/branded-types/safe-int.mts +2 -2
- package/src/number/branded-types/safe-uint.mts +1 -1
- package/src/number/num-arithmetic-types.mts +0 -4
- package/src/number/num.mts +3 -3
- package/src/number/num.test.mts +2 -2
- package/src/object/object.mts +2 -2
- package/src/others/fast-deep-equal.mts +0 -2
- package/src/others/map-nullable.test.mts +4 -3
- package/src/others/unknown-to-string.mts +2 -2
|
@@ -265,7 +265,7 @@ export function count<E>(
|
|
|
265
265
|
* ```ts
|
|
266
266
|
* const words = ['Ada', 'Grace', 'Alan', 'Barbara'] as const;
|
|
267
267
|
*
|
|
268
|
-
* const counts = Arr.countBy(words, (word) => word
|
|
268
|
+
* const counts = Arr.countBy(words, (word) => word.at(0));
|
|
269
269
|
*
|
|
270
270
|
* assert.deepStrictEqual(counts.get('A'), Optional.some(2));
|
|
271
271
|
*
|
|
@@ -503,7 +503,6 @@ export function sum(array: readonly Int[]): Int;
|
|
|
503
503
|
export function sum(array: readonly number[]): number;
|
|
504
504
|
|
|
505
505
|
export function sum(array: readonly number[]): number {
|
|
506
|
-
// eslint-disable-next-line ts-data-forge/prefer-arr-sum
|
|
507
506
|
return array.reduce((prev, curr) => prev + curr, 0);
|
|
508
507
|
}
|
|
509
508
|
|
|
@@ -196,7 +196,6 @@ export function findLast<E>(
|
|
|
196
196
|
*
|
|
197
197
|
* const indexOfB = Arr.findIndex(letters, (letter) => letter === 'b');
|
|
198
198
|
*
|
|
199
|
-
* // eslint-disable-next-line unicorn/prefer-array-index-of
|
|
200
199
|
* const indexOfMissing = Arr.findIndex<string>((letter) => letter === 'z')(
|
|
201
200
|
* letters,
|
|
202
201
|
* );
|
|
@@ -263,7 +262,6 @@ export function findIndex<E>(
|
|
|
263
262
|
*
|
|
264
263
|
* const lastIndexOfB = Arr.findLastIndex(letters, (letter) => letter === 'b');
|
|
265
264
|
*
|
|
266
|
-
* // eslint-disable-next-line unicorn/prefer-array-index-of
|
|
267
265
|
* const notFound = Arr.findLastIndex<string>((letter) => letter === 'z')(
|
|
268
266
|
* letters,
|
|
269
267
|
* );
|
|
@@ -105,7 +105,6 @@ export const setIntersection = <
|
|
|
105
105
|
array1: readonly E1[],
|
|
106
106
|
array2: readonly E2[],
|
|
107
107
|
): readonly (E1 & E2)[] =>
|
|
108
|
-
// transformer-ignore-next-line
|
|
109
108
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
110
109
|
(array1 as readonly (E1 & E2)[]).filter((e) => array2.includes(e));
|
|
111
110
|
|
|
@@ -540,13 +540,15 @@ export function flat<E, D extends SafeUintWithSmallInt = 1>(
|
|
|
540
540
|
const depth = arrayOrDepth as SafeUintWithSmallInt | undefined;
|
|
541
541
|
|
|
542
542
|
return (array) => flat(array, depth);
|
|
543
|
-
}
|
|
544
|
-
return (array) => flat(array, 1);
|
|
545
|
-
} else {
|
|
546
|
-
expectType<typeof arrayOrDepth, readonly E[]>('=');
|
|
543
|
+
}
|
|
547
544
|
|
|
548
|
-
|
|
545
|
+
if (arrayOrDepth === undefined) {
|
|
546
|
+
return (array) => flat(array, 1);
|
|
549
547
|
}
|
|
548
|
+
|
|
549
|
+
expectType<typeof arrayOrDepth, readonly E[]>('=');
|
|
550
|
+
|
|
551
|
+
return arrayOrDepth.flat();
|
|
550
552
|
}
|
|
551
553
|
|
|
552
554
|
case 0:
|
|
@@ -709,7 +711,7 @@ export const concat = <
|
|
|
709
711
|
*
|
|
710
712
|
* const groupedByLength = Arr.groupBy(animals, (animal) => animal.length);
|
|
711
713
|
*
|
|
712
|
-
* const groupedByFirstLetter = Arr.groupBy((animal: string) => animal
|
|
714
|
+
* const groupedByFirstLetter = Arr.groupBy((animal: string) => animal.at(0))(
|
|
713
715
|
* animals,
|
|
714
716
|
* );
|
|
715
717
|
*
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type ArrayAtLeastLen,
|
|
3
|
+
type ArrayAtMostLen,
|
|
4
|
+
type ArrayBoundedLen,
|
|
3
5
|
type ArrayOfLength,
|
|
4
6
|
type BoolOr,
|
|
5
7
|
type NonEmptyArray,
|
|
@@ -28,7 +30,6 @@ import { type ArrayIndex, type SizeType } from '../../types.mjs';
|
|
|
28
30
|
* ```
|
|
29
31
|
*/
|
|
30
32
|
export const isArray = <E,>(value: E): value is FilterArray<E> =>
|
|
31
|
-
// eslint-disable-next-line ts-data-forge/prefer-arr-is-array
|
|
32
33
|
Array.isArray(value);
|
|
33
34
|
|
|
34
35
|
type FilterArray<T> = T extends T
|
|
@@ -64,7 +65,6 @@ type Cast<A, B> = A extends B ? A : never;
|
|
|
64
65
|
* ```
|
|
65
66
|
*/
|
|
66
67
|
export const isEmpty = <E,>(array: readonly E[]): array is readonly [] =>
|
|
67
|
-
// eslint-disable-next-line ts-data-forge/prefer-arr-is-array-of-length
|
|
68
68
|
array.length === 0;
|
|
69
69
|
|
|
70
70
|
/**
|
|
@@ -88,9 +88,7 @@ export const isEmpty = <E,>(array: readonly E[]): array is readonly [] =>
|
|
|
88
88
|
*/
|
|
89
89
|
export const isNonEmpty = <E,>(
|
|
90
90
|
array: readonly E[],
|
|
91
|
-
): array is NonEmptyArray<E> =>
|
|
92
|
-
// eslint-disable-next-line ts-data-forge/prefer-arr-is-non-empty
|
|
93
|
-
array.length > 0;
|
|
91
|
+
): array is NonEmptyArray<E> => array.length > 0;
|
|
94
92
|
|
|
95
93
|
/**
|
|
96
94
|
* Checks if an array has a specific length.
|
|
@@ -140,6 +138,60 @@ export const isArrayAtLeastLength = <E, N extends SizeType.ArgArr>(
|
|
|
140
138
|
len: N,
|
|
141
139
|
): array is ArrayAtLeastLen<N, E> => array.length >= len;
|
|
142
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Checks if an array has at most a specific length.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
*
|
|
146
|
+
* ```ts
|
|
147
|
+
* const pair: readonly number[] = [1, 2] as const;
|
|
148
|
+
*
|
|
149
|
+
* const triple: readonly number[] = [1, 2, 3] as const;
|
|
150
|
+
*
|
|
151
|
+
* assert.isTrue(Arr.isArrayAtMostLength(pair, 2));
|
|
152
|
+
*
|
|
153
|
+
* assert.isFalse(Arr.isArrayAtMostLength(triple, 2));
|
|
154
|
+
*
|
|
155
|
+
* if (Arr.isArrayAtMostLength(pair, 2)) {
|
|
156
|
+
* assert.isTrue(pair.length <= 2);
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export const isArrayAtMostLength = <E, N extends SizeType.ArgArr>(
|
|
161
|
+
array: readonly E[],
|
|
162
|
+
len: N,
|
|
163
|
+
): array is ArrayAtMostLen<N, E> => array.length <= len;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Checks if an array's length is within a specific inclusive range.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
*
|
|
170
|
+
* ```ts
|
|
171
|
+
* const pair: readonly number[] = [1, 2] as const;
|
|
172
|
+
*
|
|
173
|
+
* const quad: readonly number[] = [1, 2, 3, 4] as const;
|
|
174
|
+
*
|
|
175
|
+
* assert.isTrue(Arr.isArrayBoundedLength(pair, 1, 3));
|
|
176
|
+
*
|
|
177
|
+
* assert.isFalse(Arr.isArrayBoundedLength(quad, 1, 3));
|
|
178
|
+
*
|
|
179
|
+
* if (Arr.isArrayBoundedLength(pair, 1, 3)) {
|
|
180
|
+
* assert.isTrue(pair.length >= 1 && pair.length <= 3);
|
|
181
|
+
* }
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
export const isArrayBoundedLength = <
|
|
185
|
+
E,
|
|
186
|
+
Min extends SizeType.ArgArr,
|
|
187
|
+
Max extends SizeType.ArgArr,
|
|
188
|
+
>(
|
|
189
|
+
array: readonly E[],
|
|
190
|
+
min: Min,
|
|
191
|
+
max: Max,
|
|
192
|
+
): array is ArrayBoundedLen<Min, Max, E> =>
|
|
193
|
+
array.length >= min && array.length <= max;
|
|
194
|
+
|
|
143
195
|
/**
|
|
144
196
|
* Tests whether all elements in an array pass a test implemented by a predicate.
|
|
145
197
|
*
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type ArrayAtLeastLen,
|
|
3
|
+
type ArrayAtMostLen,
|
|
4
|
+
type ArrayBoundedLen,
|
|
5
|
+
type ArrayOfLength,
|
|
6
|
+
} from 'ts-type-forge';
|
|
2
7
|
import { expectType } from '../../expect-type.mjs';
|
|
3
8
|
import {
|
|
4
9
|
every,
|
|
5
10
|
indexIsInRange,
|
|
6
11
|
isArray,
|
|
7
12
|
isArrayAtLeastLength,
|
|
13
|
+
isArrayAtMostLength,
|
|
14
|
+
isArrayBoundedLength,
|
|
8
15
|
isArrayOfLength,
|
|
9
16
|
isEmpty,
|
|
10
17
|
isNonEmpty,
|
|
@@ -584,6 +591,158 @@ describe('Arr validations', () => {
|
|
|
584
591
|
});
|
|
585
592
|
});
|
|
586
593
|
|
|
594
|
+
describe(isArrayAtMostLength, () => {
|
|
595
|
+
test('should return true if array length is less than or equal to specified length', () => {
|
|
596
|
+
const arr = [1, 2, 3] as const;
|
|
597
|
+
|
|
598
|
+
assert.isTrue(isArrayAtMostLength(arr, 3));
|
|
599
|
+
|
|
600
|
+
if (isArrayAtMostLength(arr, 3)) {
|
|
601
|
+
expectType<typeof arr, readonly [1, 2, 3]>('=');
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
assert.isTrue(isArrayAtMostLength(arr, 4));
|
|
605
|
+
|
|
606
|
+
if (isArrayAtMostLength(arr, 4)) {
|
|
607
|
+
expectType<typeof arr, readonly [1, 2, 3]>('=');
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
test('should return false if array length is greater than specified length', () => {
|
|
612
|
+
const arr = [1, 2, 3] as const;
|
|
613
|
+
|
|
614
|
+
assert.isFalse(isArrayAtMostLength(arr, 2));
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
test('should return true for empty array and length 0', () => {
|
|
618
|
+
const arr = [] as const;
|
|
619
|
+
|
|
620
|
+
assert.isTrue(isArrayAtMostLength(arr, 0));
|
|
621
|
+
|
|
622
|
+
if (isArrayAtMostLength(arr, 0)) {
|
|
623
|
+
expectType<typeof arr, readonly []>('=');
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
test('should return false for non-empty array and length 0', () => {
|
|
628
|
+
const arr = [1] as const;
|
|
629
|
+
|
|
630
|
+
assert.isFalse(isArrayAtMostLength(arr, 0));
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
test('should work with unknown array type', () => {
|
|
634
|
+
const mut_arr: number[] = [1, 2];
|
|
635
|
+
|
|
636
|
+
assert.isTrue(isArrayAtMostLength(mut_arr, 2));
|
|
637
|
+
|
|
638
|
+
// transformer-ignore-next-line
|
|
639
|
+
expectType<typeof mut_arr, number[] & ArrayAtMostLen<2, number>>('=');
|
|
640
|
+
|
|
641
|
+
assert.isFalse(isArrayAtMostLength(mut_arr, 1));
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
test('should return true for arrays of at most specified length (additional)', () => {
|
|
645
|
+
assert.isTrue(isArrayAtMostLength([1, 2, 3], 3));
|
|
646
|
+
|
|
647
|
+
assert.isTrue(isArrayAtMostLength([1, 2, 3], 4));
|
|
648
|
+
|
|
649
|
+
assert.isTrue(isArrayAtMostLength([], 0));
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
test('should return false for arrays longer than specified length (additional)', () => {
|
|
653
|
+
assert.isFalse(isArrayAtMostLength([1, 2, 3], 2));
|
|
654
|
+
|
|
655
|
+
assert.isFalse(isArrayAtMostLength([1, 2, 3], 0));
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
test('should work as type guard for at most length (additional)', () => {
|
|
659
|
+
const array: readonly number[] = [1, 2] as const;
|
|
660
|
+
|
|
661
|
+
if (isArrayAtMostLength(array, 3)) {
|
|
662
|
+
expectType<typeof array, ArrayAtMostLen<3, number>>('=');
|
|
663
|
+
|
|
664
|
+
expect(array.length).toBeLessThanOrEqual(3);
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
describe(isArrayBoundedLength, () => {
|
|
670
|
+
test('should return true if array length is within the specified range', () => {
|
|
671
|
+
const arr = [1, 2, 3] as const;
|
|
672
|
+
|
|
673
|
+
assert.isTrue(isArrayBoundedLength(arr, 1, 3));
|
|
674
|
+
|
|
675
|
+
if (isArrayBoundedLength(arr, 1, 3)) {
|
|
676
|
+
expectType<typeof arr, readonly [1, 2, 3]>('=');
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
assert.isTrue(isArrayBoundedLength(arr, 3, 5));
|
|
680
|
+
|
|
681
|
+
if (isArrayBoundedLength(arr, 3, 5)) {
|
|
682
|
+
expectType<typeof arr, readonly [1, 2, 3]>('=');
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
test('should return false if array length is below the specified range', () => {
|
|
687
|
+
const arr = [1, 2, 3] as const;
|
|
688
|
+
|
|
689
|
+
assert.isFalse(isArrayBoundedLength(arr, 4, 5));
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
test('should return false if array length is above the specified range', () => {
|
|
693
|
+
const arr = [1, 2, 3] as const;
|
|
694
|
+
|
|
695
|
+
assert.isFalse(isArrayBoundedLength(arr, 0, 2));
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
test('should return true for empty array and range including 0', () => {
|
|
699
|
+
const arr = [] as const;
|
|
700
|
+
|
|
701
|
+
assert.isTrue(isArrayBoundedLength(arr, 0, 2));
|
|
702
|
+
|
|
703
|
+
if (isArrayBoundedLength(arr, 0, 2)) {
|
|
704
|
+
expectType<typeof arr, readonly []>('=');
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
test('should work with unknown array type', () => {
|
|
709
|
+
const mut_arr: number[] = [1, 2];
|
|
710
|
+
|
|
711
|
+
assert.isTrue(isArrayBoundedLength(mut_arr, 1, 3));
|
|
712
|
+
|
|
713
|
+
// transformer-ignore-next-line
|
|
714
|
+
expectType<typeof mut_arr, number[] & ArrayBoundedLen<1, 3, number>>('=');
|
|
715
|
+
|
|
716
|
+
assert.isFalse(isArrayBoundedLength(mut_arr, 3, 5));
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
test('should return true for arrays within specified range (additional)', () => {
|
|
720
|
+
assert.isTrue(isArrayBoundedLength([1, 2, 3], 1, 3));
|
|
721
|
+
|
|
722
|
+
assert.isTrue(isArrayBoundedLength([1, 2, 3], 3, 3));
|
|
723
|
+
|
|
724
|
+
assert.isTrue(isArrayBoundedLength([], 0, 0));
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
test('should return false for arrays outside specified range (additional)', () => {
|
|
728
|
+
assert.isFalse(isArrayBoundedLength([1, 2, 3], 4, 5));
|
|
729
|
+
|
|
730
|
+
assert.isFalse(isArrayBoundedLength([1, 2, 3], 0, 2));
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
test('should work as type guard for bounded length (additional)', () => {
|
|
734
|
+
const array: readonly number[] = [1, 2] as const;
|
|
735
|
+
|
|
736
|
+
if (isArrayBoundedLength(array, 1, 3)) {
|
|
737
|
+
expectType<typeof array, ArrayBoundedLen<1, 3, number>>('=');
|
|
738
|
+
|
|
739
|
+
expect(array.length).toBeGreaterThanOrEqual(1);
|
|
740
|
+
|
|
741
|
+
expect(array.length).toBeLessThanOrEqual(3);
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
});
|
|
745
|
+
|
|
587
746
|
describe(every, () => {
|
|
588
747
|
test('should return true when all elements satisfy predicate', () => {
|
|
589
748
|
const evens = [2, 4, 6, 8] as const;
|