ts-data-forge 5.1.0 → 5.1.1
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/README.md +46 -44
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +8 -8
- package/dist/array/impl/array-utils-search.d.mts +4 -4
- package/dist/array/impl/array-utils-set-op.d.mts +7 -7
- package/dist/array/impl/array-utils-set-op.mjs +7 -7
- package/dist/array/impl/array-utils-size.d.mts +2 -2
- package/dist/array/impl/array-utils-size.mjs +2 -2
- package/dist/array/impl/array-utils-slicing.d.mts +2 -2
- package/dist/array/impl/array-utils-slicing.mjs +2 -2
- package/dist/array/impl/array-utils-validation.d.mts +18 -18
- package/dist/array/impl/array-utils-validation.mjs +14 -14
- package/dist/collections/imap.d.mts +15 -15
- package/dist/collections/imap.mjs +3 -3
- package/dist/collections/iset-mapped.d.mts +19 -19
- package/dist/collections/iset-mapped.mjs +2 -2
- package/dist/collections/iset.d.mts +19 -19
- package/dist/collections/iset.mjs +2 -2
- package/dist/collections/queue.d.mts +25 -25
- package/dist/collections/queue.mjs +5 -5
- package/dist/collections/stack.d.mts +25 -25
- package/dist/collections/stack.mjs +5 -5
- package/dist/functional/match.d.mts +1 -1
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts +2 -2
- package/dist/functional/optional/impl/optional-is-none.d.mts +1 -1
- package/dist/functional/optional/impl/optional-is-none.mjs +1 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts +2 -2
- package/dist/functional/optional/impl/optional-is-optional.mjs +2 -2
- package/dist/functional/optional/impl/optional-is-some.d.mts +1 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +1 -1
- package/dist/functional/optional/impl/optional-none.d.mts +2 -2
- package/dist/functional/optional/impl/optional-none.mjs +2 -2
- package/dist/functional/optional/impl/optional-some.d.mts +2 -2
- package/dist/functional/optional/impl/optional-some.mjs +2 -2
- package/dist/functional/optional/impl/optional-to-nullable.d.mts +2 -2
- package/dist/functional/optional/impl/optional-to-nullable.mjs +2 -2
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts +4 -4
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +1 -1
- package/dist/functional/optional/impl/optional-unwrap.d.mts +2 -2
- package/dist/functional/optional/impl/optional-zip.d.mts +1 -1
- package/dist/functional/optional/impl/optional-zip.mjs +1 -1
- package/dist/functional/pipe.d.mts +2 -2
- package/dist/functional/result/impl/result-err.d.mts +1 -1
- package/dist/functional/result/impl/result-err.mjs +1 -1
- package/dist/functional/result/impl/result-expect-to-be.d.mts +2 -2
- package/dist/functional/result/impl/result-from-promise.d.mts +1 -1
- package/dist/functional/result/impl/result-from-promise.mjs +1 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts +1 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +1 -1
- package/dist/functional/result/impl/result-is-err.d.mts +2 -2
- package/dist/functional/result/impl/result-is-err.mjs +2 -2
- package/dist/functional/result/impl/result-is-ok.d.mts +2 -2
- package/dist/functional/result/impl/result-is-ok.mjs +2 -2
- package/dist/functional/result/impl/result-is-result.d.mts +3 -3
- package/dist/functional/result/impl/result-is-result.mjs +3 -3
- package/dist/functional/result/impl/result-ok.d.mts +1 -1
- package/dist/functional/result/impl/result-ok.mjs +1 -1
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts +4 -4
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +1 -1
- package/dist/functional/result/impl/result-unwrap-err.d.mts +2 -2
- package/dist/functional/result/impl/result-unwrap-err.mjs +2 -2
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +4 -4
- package/dist/functional/result/impl/result-unwrap-ok.d.mts +2 -2
- package/dist/functional/result/impl/result-unwrap-throw.d.mts +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +3 -3
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +3 -3
- package/dist/globals.d.mts +2 -1
- package/dist/guard/has-key.d.mts +6 -3
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +2 -2
- package/dist/guard/key-is-in.d.mts +2 -2
- package/dist/guard/key-is-in.mjs +2 -2
- package/dist/json/json.d.mts +21 -21
- package/dist/json/json.mjs +21 -21
- package/dist/number/branded-types/int.d.mts +19 -19
- package/dist/number/branded-types/int.mjs +19 -19
- package/dist/number/branded-types/positive-int.d.mts +20 -20
- package/dist/number/branded-types/positive-int.mjs +20 -20
- package/dist/number/branded-types/positive-safe-int.d.mts +26 -26
- package/dist/number/branded-types/positive-safe-int.mjs +26 -26
- package/dist/number/branded-types/safe-int.d.mts +27 -27
- package/dist/number/branded-types/safe-int.mjs +27 -27
- package/dist/number/branded-types/uint.d.mts +19 -19
- package/dist/number/branded-types/uint.mjs +19 -19
- package/dist/number/num.d.mts +20 -20
- package/dist/number/num.mjs +16 -16
- package/dist/number/refined-number-utils.d.mts +11 -11
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +11 -11
- package/dist/object/object.d.mts +3 -3
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +3 -3
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/tuple.d.mts +3 -3
- package/dist/others/tuple.mjs +3 -3
- package/dist/promise/promise.d.mts +4 -4
- package/dist/promise/promise.mjs +4 -4
- package/package.json +15 -13
- package/src/array/impl/array-utils-creation.test.mts +1 -1
- package/src/array/impl/array-utils-element-access.test.mts +16 -16
- package/src/array/impl/array-utils-modification.mts +38 -19
- package/src/array/impl/array-utils-reducing-value.mts +8 -8
- package/src/array/impl/array-utils-reducing-value.test.mts +23 -31
- package/src/array/impl/array-utils-search.mts +4 -4
- package/src/array/impl/array-utils-search.test.mts +10 -10
- package/src/array/impl/array-utils-set-op.mts +7 -7
- package/src/array/impl/array-utils-set-op.test.mts +13 -13
- package/src/array/impl/array-utils-size.mts +2 -2
- package/src/array/impl/array-utils-slicing.mts +2 -2
- package/src/array/impl/array-utils-transformation.test.mts +2 -2
- package/src/array/impl/array-utils-validation.mts +18 -18
- package/src/array/impl/array-utils-validation.test.mts +80 -78
- package/src/array/impl/array.test.mts +6 -6
- package/src/collections/imap-mapped.test.mts +16 -18
- package/src/collections/imap.mts +15 -15
- package/src/collections/imap.test.mts +31 -31
- package/src/collections/iset-mapped.mts +19 -19
- package/src/collections/iset-mapped.test.mts +52 -52
- package/src/collections/iset.mts +19 -19
- package/src/collections/iset.test.mts +130 -130
- package/src/collections/queue.mts +25 -25
- package/src/collections/queue.test.mts +33 -35
- package/src/collections/stack.mts +25 -25
- package/src/collections/stack.test.mts +15 -15
- package/src/functional/match.mts +1 -1
- package/src/functional/optional/impl/optional-expect-to-be.mts +2 -2
- package/src/functional/optional/impl/optional-is-none.mts +1 -1
- package/src/functional/optional/impl/optional-is-optional.mts +2 -2
- package/src/functional/optional/impl/optional-is-some.mts +1 -1
- package/src/functional/optional/impl/optional-none.mts +2 -2
- package/src/functional/optional/impl/optional-some.mts +2 -2
- package/src/functional/optional/impl/optional-to-nullable.mts +2 -2
- package/src/functional/optional/impl/optional-unwrap-or.mts +4 -4
- package/src/functional/optional/impl/optional-unwrap-throw.mts +1 -1
- package/src/functional/optional/impl/optional-unwrap.mts +2 -2
- package/src/functional/optional/impl/optional-zip.mts +1 -1
- package/src/functional/optional.test.mts +53 -54
- package/src/functional/pipe.mts +2 -2
- package/src/functional/pipe.test.mts +4 -4
- package/src/functional/result/impl/result-err.mts +1 -1
- package/src/functional/result/impl/result-expect-to-be.mts +2 -2
- package/src/functional/result/impl/result-from-promise.mts +1 -1
- package/src/functional/result/impl/result-from-throwable.mts +1 -1
- package/src/functional/result/impl/result-is-err.mts +2 -2
- package/src/functional/result/impl/result-is-ok.mts +2 -2
- package/src/functional/result/impl/result-is-result.mts +3 -3
- package/src/functional/result/impl/result-ok.mts +1 -1
- package/src/functional/result/impl/result-unwrap-err-or.mts +4 -4
- package/src/functional/result/impl/result-unwrap-err-throw.mts +1 -1
- package/src/functional/result/impl/result-unwrap-err.mts +2 -2
- package/src/functional/result/impl/result-unwrap-ok-or.mts +4 -4
- package/src/functional/result/impl/result-unwrap-ok.mts +2 -2
- package/src/functional/result/impl/result-unwrap-throw.mts +1 -1
- package/src/functional/result.test.mts +94 -152
- package/src/functional/ternary-result/impl/ternary-result-err.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +3 -3
- package/src/functional/ternary-result.test.mts +8 -8
- package/src/globals.d.mts +2 -1
- package/src/guard/has-key.mts +8 -5
- package/src/guard/has-key.test.mts +0 -5
- package/src/guard/is-error.test.mts +143 -0
- package/src/guard/is-non-empty-string.test.mts +24 -24
- package/src/guard/is-non-null-object.test.mts +26 -26
- package/src/guard/is-primitive.test.mts +28 -28
- package/src/guard/is-record.test.mts +7 -7
- package/src/guard/is-type.test.mts +151 -155
- package/src/guard/key-is-in.mts +2 -2
- package/src/guard/key-is-in.test.mts +2 -2
- package/src/json/json.mts +21 -21
- package/src/json/json.test.mts +135 -174
- package/src/number/branded-types/finite-number.test.mts +13 -11
- package/src/number/branded-types/int.mts +19 -19
- package/src/number/branded-types/int.test.mts +14 -14
- package/src/number/branded-types/int16.test.mts +16 -16
- package/src/number/branded-types/int32.test.mts +16 -16
- package/src/number/branded-types/non-negative-finite-number.test.mts +12 -12
- package/src/number/branded-types/non-negative-int16.test.mts +16 -16
- package/src/number/branded-types/non-negative-int32.test.mts +16 -16
- package/src/number/branded-types/non-zero-finite-number.test.mts +14 -14
- package/src/number/branded-types/non-zero-int.test.mts +19 -19
- package/src/number/branded-types/non-zero-int16.test.mts +16 -16
- package/src/number/branded-types/non-zero-int32.test.mts +16 -16
- package/src/number/branded-types/non-zero-safe-int.test.mts +23 -23
- package/src/number/branded-types/non-zero-uint16.test.mts +16 -16
- package/src/number/branded-types/non-zero-uint32.test.mts +16 -16
- package/src/number/branded-types/positive-finite-number.test.mts +14 -14
- package/src/number/branded-types/positive-int.mts +20 -20
- package/src/number/branded-types/positive-int.test.mts +17 -17
- package/src/number/branded-types/positive-int16.test.mts +15 -15
- package/src/number/branded-types/positive-int32.test.mts +15 -15
- package/src/number/branded-types/positive-safe-int.mts +26 -26
- package/src/number/branded-types/positive-safe-int.test.mts +19 -19
- package/src/number/branded-types/positive-uint16.test.mts +16 -16
- package/src/number/branded-types/positive-uint32.test.mts +16 -16
- package/src/number/branded-types/safe-int.mts +27 -27
- package/src/number/branded-types/safe-int.test.mts +18 -18
- package/src/number/branded-types/safe-uint.test.mts +17 -17
- package/src/number/branded-types/uint.mts +19 -19
- package/src/number/branded-types/uint.test.mts +15 -15
- package/src/number/branded-types/uint16.test.mts +15 -15
- package/src/number/branded-types/uint32.test.mts +15 -15
- package/src/number/enum/int8.test.mts +1 -1
- package/src/number/enum/uint8.test.mts +1 -1
- package/src/number/num.mts +20 -20
- package/src/number/num.test.mts +26 -26
- package/src/number/refined-number-utils.mts +13 -13
- package/src/object/object.mts +4 -3
- package/src/object/object.test.mts +6 -6
- package/src/others/cast-mutable.test.mts +1 -1
- package/src/others/cast-readonly.test.mts +4 -4
- package/src/others/if-then.test.mts +24 -24
- package/src/others/tuple.mts +3 -3
- package/src/promise/promise.mts +4 -4
- package/src/promise/promise.test.mts +7 -13
|
@@ -13,25 +13,25 @@ import {
|
|
|
13
13
|
describe('Arr validations', () => {
|
|
14
14
|
describe(isArray, () => {
|
|
15
15
|
test('should return true for arrays', () => {
|
|
16
|
-
|
|
16
|
+
assert.isTrue(isArray([1, 2, 3]));
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
assert.isTrue(isArray([]));
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
assert.isTrue(isArray(['a', 'b']));
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
test('should return false for non-arrays', () => {
|
|
24
|
-
|
|
24
|
+
assert.isFalse(isArray('hello'));
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
assert.isFalse(isArray(123));
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
assert.isFalse(isArray(null));
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
assert.isFalse(isArray(undefined));
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
assert.isFalse(isArray({}));
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
assert.isFalse(isArray(new Set()));
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
test('should refine union types correctly', () => {
|
|
@@ -139,23 +139,23 @@ describe('Arr validations', () => {
|
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
test('should return true for arrays (additional)', () => {
|
|
142
|
-
|
|
142
|
+
assert.isTrue(isArray([]));
|
|
143
143
|
|
|
144
|
-
|
|
144
|
+
assert.isTrue(isArray([1, 2, 3]));
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
assert.isTrue(isArray(['a', 'b']));
|
|
147
147
|
});
|
|
148
148
|
|
|
149
149
|
test('should return false for non-arrays (additional)', () => {
|
|
150
|
-
|
|
150
|
+
assert.isFalse(isArray('string'));
|
|
151
151
|
|
|
152
|
-
|
|
152
|
+
assert.isFalse(isArray(123));
|
|
153
153
|
|
|
154
|
-
|
|
154
|
+
assert.isFalse(isArray({}));
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
assert.isFalse(isArray(null));
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
assert.isFalse(isArray(undefined));
|
|
159
159
|
});
|
|
160
160
|
|
|
161
161
|
test('should work as type guard (additional)', () => {
|
|
@@ -171,7 +171,7 @@ describe('Arr validations', () => {
|
|
|
171
171
|
test('should handle array-like objects', () => {
|
|
172
172
|
const arrayLike = { 0: 'a', 1: 'b', length: 2 };
|
|
173
173
|
|
|
174
|
-
|
|
174
|
+
assert.isFalse(isArray(arrayLike));
|
|
175
175
|
});
|
|
176
176
|
|
|
177
177
|
describe('comprehensive type guard tests', () => {
|
|
@@ -377,11 +377,11 @@ describe('Arr validations', () => {
|
|
|
377
377
|
expectType<typeof result, boolean>('=');
|
|
378
378
|
|
|
379
379
|
test('case 1', () => {
|
|
380
|
-
|
|
380
|
+
assert.isFalse(result);
|
|
381
381
|
});
|
|
382
382
|
|
|
383
383
|
test('case 2', () => {
|
|
384
|
-
|
|
384
|
+
assert.isTrue(isEmpty([]));
|
|
385
385
|
});
|
|
386
386
|
});
|
|
387
387
|
|
|
@@ -393,11 +393,11 @@ describe('Arr validations', () => {
|
|
|
393
393
|
expectType<typeof result, boolean>('=');
|
|
394
394
|
|
|
395
395
|
test('case 1', () => {
|
|
396
|
-
|
|
396
|
+
assert.isTrue(result);
|
|
397
397
|
});
|
|
398
398
|
|
|
399
399
|
test('case 2', () => {
|
|
400
|
-
|
|
400
|
+
assert.isFalse(isNonEmpty([]));
|
|
401
401
|
});
|
|
402
402
|
});
|
|
403
403
|
|
|
@@ -405,7 +405,7 @@ describe('Arr validations', () => {
|
|
|
405
405
|
test('should return true if array has specified length', () => {
|
|
406
406
|
const arr = [1, 2, 3] as const;
|
|
407
407
|
|
|
408
|
-
|
|
408
|
+
assert.isTrue(isArrayOfLength(arr, 3));
|
|
409
409
|
|
|
410
410
|
if (isArrayOfLength(arr, 3)) {
|
|
411
411
|
expectType<typeof arr, readonly [1, 2, 3]>('=');
|
|
@@ -415,13 +415,13 @@ describe('Arr validations', () => {
|
|
|
415
415
|
test('should return false if array does not have specified length', () => {
|
|
416
416
|
const arr = [1, 2, 3] as const;
|
|
417
417
|
|
|
418
|
-
|
|
418
|
+
assert.isFalse(isArrayOfLength(arr, 2));
|
|
419
419
|
});
|
|
420
420
|
|
|
421
421
|
test('should return true for empty array and length 0', () => {
|
|
422
422
|
const arr = [] as const;
|
|
423
423
|
|
|
424
|
-
|
|
424
|
+
assert.isTrue(isArrayOfLength(arr, 0));
|
|
425
425
|
|
|
426
426
|
if (isArrayOfLength(arr, 0)) {
|
|
427
427
|
expectType<typeof arr, readonly []>('=');
|
|
@@ -431,47 +431,47 @@ describe('Arr validations', () => {
|
|
|
431
431
|
test('should return false for non-empty array and length 0', () => {
|
|
432
432
|
const arr = [1] as const;
|
|
433
433
|
|
|
434
|
-
|
|
434
|
+
assert.isFalse(isArrayOfLength(arr, 0));
|
|
435
435
|
});
|
|
436
436
|
|
|
437
437
|
test('should work with unknown array type', () => {
|
|
438
438
|
const arr: number[] = [1, 2];
|
|
439
439
|
|
|
440
|
-
|
|
440
|
+
assert.isTrue(isArrayOfLength(arr, 2));
|
|
441
441
|
|
|
442
442
|
if (isArrayOfLength(arr, 2)) {
|
|
443
443
|
expectType<typeof arr, number[] & ArrayOfLength<2, number>>('=');
|
|
444
444
|
}
|
|
445
445
|
|
|
446
|
-
|
|
446
|
+
assert.isFalse(isArrayOfLength(arr, 3));
|
|
447
447
|
});
|
|
448
448
|
|
|
449
449
|
test('should work with unknown readonly array type', () => {
|
|
450
450
|
const arr: readonly number[] = [1, 2];
|
|
451
451
|
|
|
452
|
-
|
|
452
|
+
assert.isTrue(isArrayOfLength(arr, 2));
|
|
453
453
|
|
|
454
454
|
if (isArrayOfLength(arr, 2)) {
|
|
455
455
|
expectType<typeof arr, ArrayOfLength<2, number>>('=');
|
|
456
456
|
}
|
|
457
457
|
|
|
458
|
-
|
|
458
|
+
assert.isFalse(isArrayOfLength(arr, 3));
|
|
459
459
|
});
|
|
460
460
|
|
|
461
461
|
test('should return true for arrays of exact length (additional)', () => {
|
|
462
|
-
|
|
462
|
+
assert.isTrue(isArrayOfLength([1, 2, 3], 3));
|
|
463
463
|
|
|
464
|
-
|
|
464
|
+
assert.isTrue(isArrayOfLength([], 0));
|
|
465
465
|
|
|
466
|
-
|
|
466
|
+
assert.isTrue(isArrayOfLength(['a'], 1));
|
|
467
467
|
});
|
|
468
468
|
|
|
469
469
|
test('should return false for arrays of different length (additional)', () => {
|
|
470
|
-
|
|
470
|
+
assert.isFalse(isArrayOfLength([1, 2, 3], 2));
|
|
471
471
|
|
|
472
|
-
|
|
472
|
+
assert.isFalse(isArrayOfLength([1, 2, 3], 4));
|
|
473
473
|
|
|
474
|
-
|
|
474
|
+
assert.isFalse(isArrayOfLength([], 1));
|
|
475
475
|
});
|
|
476
476
|
|
|
477
477
|
test('should work as type guard with exact length (additional)', () => {
|
|
@@ -489,13 +489,13 @@ describe('Arr validations', () => {
|
|
|
489
489
|
test('should return true if array length is greater than or equal to specified length', () => {
|
|
490
490
|
const arr = [1, 2, 3] as const;
|
|
491
491
|
|
|
492
|
-
|
|
492
|
+
assert.isTrue(isArrayAtLeastLength(arr, 3));
|
|
493
493
|
|
|
494
494
|
if (isArrayAtLeastLength(arr, 3)) {
|
|
495
495
|
expectType<typeof arr, readonly [1, 2, 3]>('=');
|
|
496
496
|
}
|
|
497
497
|
|
|
498
|
-
|
|
498
|
+
assert.isTrue(isArrayAtLeastLength(arr, 2));
|
|
499
499
|
|
|
500
500
|
if (isArrayAtLeastLength(arr, 2)) {
|
|
501
501
|
expectType<typeof arr, readonly [1, 2, 3]>('=');
|
|
@@ -505,13 +505,13 @@ describe('Arr validations', () => {
|
|
|
505
505
|
test('should return false if array length is less than specified length', () => {
|
|
506
506
|
const arr = [1, 2, 3] as const;
|
|
507
507
|
|
|
508
|
-
|
|
508
|
+
assert.isFalse(isArrayAtLeastLength(arr, 4));
|
|
509
509
|
});
|
|
510
510
|
|
|
511
511
|
test('should return true for empty array and length 0', () => {
|
|
512
512
|
const arr = [] as const;
|
|
513
513
|
|
|
514
|
-
|
|
514
|
+
assert.isTrue(isArrayAtLeastLength(arr, 0));
|
|
515
515
|
|
|
516
516
|
if (isArrayAtLeastLength(arr, 0)) {
|
|
517
517
|
expectType<typeof arr, readonly []>('=');
|
|
@@ -521,41 +521,43 @@ describe('Arr validations', () => {
|
|
|
521
521
|
test('should return false for empty array and positive length', () => {
|
|
522
522
|
const arr = [] as const;
|
|
523
523
|
|
|
524
|
-
|
|
524
|
+
assert.isFalse(isArrayAtLeastLength(arr, 1));
|
|
525
525
|
});
|
|
526
526
|
|
|
527
527
|
test('should work with unknown array type', () => {
|
|
528
528
|
const arr: number[] = [1, 2];
|
|
529
529
|
|
|
530
|
-
|
|
530
|
+
assert.isTrue(isArrayAtLeastLength(arr, 2));
|
|
531
531
|
|
|
532
|
-
|
|
533
|
-
expectType<typeof arr, number[] & ArrayAtLeastLen<2, number>>('=');
|
|
534
|
-
}
|
|
532
|
+
expectType<typeof arr, number[] & ArrayAtLeastLen<2, number>>('=');
|
|
535
533
|
|
|
536
|
-
|
|
534
|
+
assert.isFalse(isArrayAtLeastLength(arr, 3));
|
|
535
|
+
});
|
|
537
536
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
537
|
+
test('should work with unknown array type 2', () => {
|
|
538
|
+
const arr: number[] = [1, 2];
|
|
539
|
+
|
|
540
|
+
assert.isTrue(isArrayAtLeastLength(arr, 1));
|
|
541
|
+
|
|
542
|
+
expectType<typeof arr, number[] & ArrayAtLeastLen<1, number>>('=');
|
|
541
543
|
|
|
542
|
-
|
|
544
|
+
assert.isFalse(isArrayAtLeastLength(arr, 3));
|
|
543
545
|
});
|
|
544
546
|
|
|
545
547
|
test('should return true for arrays of at least specified length (additional)', () => {
|
|
546
|
-
|
|
548
|
+
assert.isTrue(isArrayAtLeastLength([1, 2, 3], 3));
|
|
547
549
|
|
|
548
|
-
|
|
550
|
+
assert.isTrue(isArrayAtLeastLength([1, 2, 3], 2));
|
|
549
551
|
|
|
550
|
-
|
|
552
|
+
assert.isTrue(isArrayAtLeastLength([1, 2, 3], 1));
|
|
551
553
|
|
|
552
|
-
|
|
554
|
+
assert.isTrue(isArrayAtLeastLength([1, 2, 3], 0));
|
|
553
555
|
});
|
|
554
556
|
|
|
555
557
|
test('should return false for arrays shorter than specified length (additional)', () => {
|
|
556
|
-
|
|
558
|
+
assert.isFalse(isArrayAtLeastLength([1, 2, 3], 4));
|
|
557
559
|
|
|
558
|
-
|
|
560
|
+
assert.isFalse(isArrayAtLeastLength([], 1));
|
|
559
561
|
});
|
|
560
562
|
|
|
561
563
|
test('should work as type guard for at least length (additional)', () => {
|
|
@@ -575,7 +577,7 @@ describe('Arr validations', () => {
|
|
|
575
577
|
|
|
576
578
|
const allEven = every(evens, (n) => n % 2 === 0);
|
|
577
579
|
|
|
578
|
-
|
|
580
|
+
assert.isTrue(allEven);
|
|
579
581
|
});
|
|
580
582
|
|
|
581
583
|
test('should return false when not all elements satisfy predicate', () => {
|
|
@@ -583,7 +585,7 @@ describe('Arr validations', () => {
|
|
|
583
585
|
|
|
584
586
|
const allEven = every(mixed, (n) => n % 2 === 0);
|
|
585
587
|
|
|
586
|
-
|
|
588
|
+
assert.isFalse(allEven);
|
|
587
589
|
});
|
|
588
590
|
|
|
589
591
|
test('should work as type guard', () => {
|
|
@@ -591,7 +593,7 @@ describe('Arr validations', () => {
|
|
|
591
593
|
|
|
592
594
|
if (every(mixed, (x): x is string => typeof x === 'string')) {
|
|
593
595
|
// TypeScript narrows mixed to readonly string[] here
|
|
594
|
-
|
|
596
|
+
assert.isTrue(mixed.every((s) => typeof s === 'string'));
|
|
595
597
|
}
|
|
596
598
|
});
|
|
597
599
|
|
|
@@ -600,9 +602,9 @@ describe('Arr validations', () => {
|
|
|
600
602
|
|
|
601
603
|
const allPositive = every(isPositive);
|
|
602
604
|
|
|
603
|
-
|
|
605
|
+
assert.isTrue(allPositive([1, 2, 3]));
|
|
604
606
|
|
|
605
|
-
|
|
607
|
+
assert.isFalse(allPositive([1, -2, 3]));
|
|
606
608
|
});
|
|
607
609
|
|
|
608
610
|
test('should work with curried type guards', () => {
|
|
@@ -623,7 +625,7 @@ describe('Arr validations', () => {
|
|
|
623
625
|
|
|
624
626
|
const result = every(empty, (n) => n > 0);
|
|
625
627
|
|
|
626
|
-
|
|
628
|
+
assert.isTrue(result);
|
|
627
629
|
});
|
|
628
630
|
|
|
629
631
|
test('should pass index to predicate', () => {
|
|
@@ -631,7 +633,7 @@ describe('Arr validations', () => {
|
|
|
631
633
|
|
|
632
634
|
const indexMatchesValue = every(numbers, (val, idx) => val === idx);
|
|
633
635
|
|
|
634
|
-
|
|
636
|
+
assert.isTrue(indexMatchesValue);
|
|
635
637
|
});
|
|
636
638
|
});
|
|
637
639
|
|
|
@@ -641,7 +643,7 @@ describe('Arr validations', () => {
|
|
|
641
643
|
|
|
642
644
|
const hasEven = some(numbers, (n) => n % 2 === 0);
|
|
643
645
|
|
|
644
|
-
|
|
646
|
+
assert.isTrue(hasEven);
|
|
645
647
|
});
|
|
646
648
|
|
|
647
649
|
test('should return false when no elements satisfy predicate', () => {
|
|
@@ -649,7 +651,7 @@ describe('Arr validations', () => {
|
|
|
649
651
|
|
|
650
652
|
const hasEven = some(odds, (n) => n % 2 === 0);
|
|
651
653
|
|
|
652
|
-
|
|
654
|
+
assert.isFalse(hasEven);
|
|
653
655
|
});
|
|
654
656
|
|
|
655
657
|
test('should work with curried version', () => {
|
|
@@ -657,9 +659,9 @@ describe('Arr validations', () => {
|
|
|
657
659
|
|
|
658
660
|
const hasNegative = some(isNegative);
|
|
659
661
|
|
|
660
|
-
|
|
662
|
+
assert.isTrue(hasNegative([1, 2, -3]));
|
|
661
663
|
|
|
662
|
-
|
|
664
|
+
assert.isFalse(hasNegative([1, 2, 3]));
|
|
663
665
|
});
|
|
664
666
|
|
|
665
667
|
test('should return false for empty array', () => {
|
|
@@ -667,7 +669,7 @@ describe('Arr validations', () => {
|
|
|
667
669
|
|
|
668
670
|
const result = some(empty, (n) => n > 0);
|
|
669
671
|
|
|
670
|
-
|
|
672
|
+
assert.isFalse(result);
|
|
671
673
|
});
|
|
672
674
|
|
|
673
675
|
test('should pass index to predicate', () => {
|
|
@@ -678,7 +680,7 @@ describe('Arr validations', () => {
|
|
|
678
680
|
(val, idx) => val === idx * 10,
|
|
679
681
|
);
|
|
680
682
|
|
|
681
|
-
|
|
683
|
+
assert.isTrue(hasValueMatchingIndex);
|
|
682
684
|
});
|
|
683
685
|
});
|
|
684
686
|
|
|
@@ -686,38 +688,38 @@ describe('Arr validations', () => {
|
|
|
686
688
|
test('should return true for valid indices', () => {
|
|
687
689
|
const array = ['a', 'b', 'c'];
|
|
688
690
|
|
|
689
|
-
|
|
691
|
+
assert.isTrue(indexIsInRange(array, 0));
|
|
690
692
|
|
|
691
|
-
|
|
693
|
+
assert.isTrue(indexIsInRange(array, 1));
|
|
692
694
|
|
|
693
|
-
|
|
695
|
+
assert.isTrue(indexIsInRange(array, 2));
|
|
694
696
|
});
|
|
695
697
|
|
|
696
698
|
test('should return false for invalid indices', () => {
|
|
697
699
|
const array = ['a', 'b', 'c'];
|
|
698
700
|
|
|
699
|
-
|
|
701
|
+
assert.isFalse(indexIsInRange(array, 3));
|
|
700
702
|
|
|
701
|
-
|
|
703
|
+
assert.isFalse(indexIsInRange(array, 10));
|
|
702
704
|
});
|
|
703
705
|
|
|
704
706
|
test('should work with empty array', () => {
|
|
705
707
|
const empty: readonly string[] = [];
|
|
706
708
|
|
|
707
|
-
|
|
709
|
+
assert.isFalse(indexIsInRange(empty, 0));
|
|
708
710
|
|
|
709
711
|
// @ts-expect-error negative indices should not be allowed
|
|
710
|
-
|
|
712
|
+
assert.isFalse(indexIsInRange(empty, -1));
|
|
711
713
|
});
|
|
712
714
|
|
|
713
715
|
test('should be type error with floating point indices', () => {
|
|
714
716
|
const array = [1, 2, 3];
|
|
715
717
|
|
|
716
718
|
// @ts-expect-error floating point indices should not be allowed
|
|
717
|
-
|
|
719
|
+
assert.isTrue(indexIsInRange(array, 1.5)); // JavaScript arrays accept floating point indices
|
|
718
720
|
|
|
719
721
|
// @ts-expect-error floating point indices should not be allowed
|
|
720
|
-
|
|
722
|
+
assert.isFalse(indexIsInRange(array, 3.1));
|
|
721
723
|
});
|
|
722
724
|
});
|
|
723
725
|
});
|
|
@@ -10,11 +10,11 @@ describe('Array.every', () => {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
test('case 1', () => {
|
|
13
|
-
|
|
13
|
+
assert.isFalse(xs.every((x): x is 1 => x === 1));
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
test('case 2', () => {
|
|
17
|
-
|
|
17
|
+
assert.isTrue(xs.every((x) => 1 <= x && x <= 3));
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
20
|
|
|
@@ -22,11 +22,11 @@ describe('Array.some', () => {
|
|
|
22
22
|
const xs = [1, 2, 3] as const;
|
|
23
23
|
|
|
24
24
|
test('case 1', () => {
|
|
25
|
-
|
|
25
|
+
assert.isTrue(xs.some((x): x is 1 => x === 1));
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
test('case 2', () => {
|
|
29
|
-
|
|
29
|
+
assert.isFalse(xs.some((x) => x <= 1 && 3 <= x));
|
|
30
30
|
});
|
|
31
31
|
});
|
|
32
32
|
|
|
@@ -54,7 +54,7 @@ describe('Array.includes', () => {
|
|
|
54
54
|
expectType<typeof result, boolean>('=');
|
|
55
55
|
|
|
56
56
|
test('case 1', () => {
|
|
57
|
-
|
|
57
|
+
assert.isTrue(result);
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -66,7 +66,7 @@ describe('Array.includes', () => {
|
|
|
66
66
|
expectType<typeof result, boolean>('=');
|
|
67
67
|
|
|
68
68
|
test('case 2', () => {
|
|
69
|
-
|
|
69
|
+
assert.isFalse(result);
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
});
|
|
@@ -150,9 +150,9 @@ describe('IMapMapped.equal', () => {
|
|
|
150
150
|
// Test structural equality, not reference equality
|
|
151
151
|
expect(map1.size).toBe(map2.size);
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
assert.isTrue(map1.has({ id: 1, type: 'user' }));
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
assert.isTrue(map2.has({ id: 1, type: 'user' }));
|
|
156
156
|
|
|
157
157
|
expect(Optional.unwrap(map1.get({ id: 1, type: 'user' }))).toBe(
|
|
158
158
|
Optional.unwrap(map2.get({ id: 1, type: 'user' })),
|
|
@@ -178,7 +178,7 @@ describe('IMapMapped.equal', () => {
|
|
|
178
178
|
stringToTestKey,
|
|
179
179
|
);
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
assert.isFalse(IMapMapped.equal(map1, map2));
|
|
182
182
|
});
|
|
183
183
|
|
|
184
184
|
test('should return false for maps with different keys', () => {
|
|
@@ -200,7 +200,7 @@ describe('IMapMapped.equal', () => {
|
|
|
200
200
|
stringToTestKey,
|
|
201
201
|
);
|
|
202
202
|
|
|
203
|
-
|
|
203
|
+
assert.isFalse(IMapMapped.equal(map1, map2));
|
|
204
204
|
});
|
|
205
205
|
|
|
206
206
|
test('should return true for empty maps', () => {
|
|
@@ -216,7 +216,7 @@ describe('IMapMapped.equal', () => {
|
|
|
216
216
|
stringToTestKey,
|
|
217
217
|
);
|
|
218
218
|
|
|
219
|
-
|
|
219
|
+
assert.isTrue(IMapMapped.equal(map1, map2));
|
|
220
220
|
});
|
|
221
221
|
});
|
|
222
222
|
|
|
@@ -248,7 +248,7 @@ describe('IMapMapped.has', () => {
|
|
|
248
248
|
fromKey,
|
|
249
249
|
);
|
|
250
250
|
|
|
251
|
-
|
|
251
|
+
assert.isTrue(s0.has({ v: 3 }));
|
|
252
252
|
});
|
|
253
253
|
|
|
254
254
|
test('case 2', () => {
|
|
@@ -262,7 +262,7 @@ describe('IMapMapped.has', () => {
|
|
|
262
262
|
fromKey,
|
|
263
263
|
);
|
|
264
264
|
|
|
265
|
-
|
|
265
|
+
assert.isFalse(s0.has({ v: 4 }));
|
|
266
266
|
});
|
|
267
267
|
|
|
268
268
|
test('case 3', () => {
|
|
@@ -272,7 +272,7 @@ describe('IMapMapped.has', () => {
|
|
|
272
272
|
fromKey,
|
|
273
273
|
);
|
|
274
274
|
|
|
275
|
-
|
|
275
|
+
assert.isFalse(s0.has({ v: 3 }));
|
|
276
276
|
});
|
|
277
277
|
});
|
|
278
278
|
|
|
@@ -438,7 +438,7 @@ describe('IMapMapped.update', () => {
|
|
|
438
438
|
|
|
439
439
|
expect(updated).toBe(map);
|
|
440
440
|
|
|
441
|
-
|
|
441
|
+
assert.isTrue(Optional.isNone(updated.get({ id: 2, type: 'user' })));
|
|
442
442
|
});
|
|
443
443
|
});
|
|
444
444
|
|
|
@@ -560,7 +560,7 @@ describe('IMapMapped.every', () => {
|
|
|
560
560
|
stringToTestKey,
|
|
561
561
|
);
|
|
562
562
|
|
|
563
|
-
|
|
563
|
+
assert.isTrue(map.every((value) => typeof value === 'string'));
|
|
564
564
|
});
|
|
565
565
|
|
|
566
566
|
test('should return false when some values do not satisfy predicate', () => {
|
|
@@ -573,7 +573,7 @@ describe('IMapMapped.every', () => {
|
|
|
573
573
|
stringToTestKey,
|
|
574
574
|
);
|
|
575
575
|
|
|
576
|
-
|
|
576
|
+
assert.isFalse(map.every((value) => value.length > 5));
|
|
577
577
|
});
|
|
578
578
|
|
|
579
579
|
test('should return true for empty map', () => {
|
|
@@ -583,7 +583,7 @@ describe('IMapMapped.every', () => {
|
|
|
583
583
|
stringToTestKey,
|
|
584
584
|
);
|
|
585
585
|
|
|
586
|
-
|
|
586
|
+
assert.isTrue(map.every((value) => value.length > 0));
|
|
587
587
|
});
|
|
588
588
|
});
|
|
589
589
|
|
|
@@ -599,7 +599,7 @@ describe('IMapMapped.some', () => {
|
|
|
599
599
|
);
|
|
600
600
|
|
|
601
601
|
// eslint-disable-next-line unicorn/prefer-includes
|
|
602
|
-
|
|
602
|
+
assert.isTrue(map.some((value) => value === 'Alice'));
|
|
603
603
|
});
|
|
604
604
|
|
|
605
605
|
test('should return false when no values satisfy predicate', () => {
|
|
@@ -613,7 +613,7 @@ describe('IMapMapped.some', () => {
|
|
|
613
613
|
);
|
|
614
614
|
|
|
615
615
|
// eslint-disable-next-line unicorn/prefer-includes
|
|
616
|
-
|
|
616
|
+
assert.isFalse(map.some((value) => value === 'Charlie'));
|
|
617
617
|
});
|
|
618
618
|
|
|
619
619
|
test('should return false for empty map', () => {
|
|
@@ -623,7 +623,7 @@ describe('IMapMapped.some', () => {
|
|
|
623
623
|
stringToTestKey,
|
|
624
624
|
);
|
|
625
625
|
|
|
626
|
-
|
|
626
|
+
assert.isFalse(map.some((value) => value.length > 0));
|
|
627
627
|
});
|
|
628
628
|
});
|
|
629
629
|
|
|
@@ -724,9 +724,7 @@ describe('IMapMapped.mapKeys', () => {
|
|
|
724
724
|
|
|
725
725
|
const transformed = map.mapKeys((key) => ({ ...key, id: key.id * 10 }));
|
|
726
726
|
|
|
727
|
-
|
|
728
|
-
true,
|
|
729
|
-
);
|
|
727
|
+
assert.isTrue(Optional.isNone(transformed.get({ id: 1, type: 'user' })));
|
|
730
728
|
|
|
731
729
|
expect(Optional.unwrap(transformed.get({ id: 10, type: 'user' }))).toBe(
|
|
732
730
|
'Alice',
|