ts-data-forge 14.7.0 → 14.8.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/README.md +21 -34
- package/dist/array/impl/array-utils-creation.d.mts +3 -3
- package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-creation.mjs.map +1 -1
- package/dist/array/impl/array-utils-element-access.d.mts +2 -2
- package/dist/array/impl/array-utils-element-access.d.mts.map +1 -1
- package/dist/array/impl/array-utils-element-access.mjs +1 -1
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/array/impl/array-utils-iterators.d.mts +1 -1
- package/dist/array/impl/array-utils-iterators.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts +37 -7
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +4 -0
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-guard.d.mts +9 -9
- package/dist/array/impl/array-utils-length-bounded-array-guard.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-guard.mjs +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-guard.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts +28 -8
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs +4 -0
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-guard.d.mts +3 -3
- package/dist/array/impl/array-utils-length-bounded-tuple-guard.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs.map +1 -1
- package/dist/array/impl/array-utils-modification.d.mts +2 -2
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +2 -2
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +3 -4
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.d.mts +1 -1
- package/dist/array/impl/array-utils-search.d.mts.map +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts +2 -2
- package/dist/array/impl/array-utils-size.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.d.mts +1 -1
- package/dist/array/impl/array-utils-slice-clamped.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts +2 -2
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts +2 -2
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +6 -3
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts +2 -2
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/collections/imap-mapped.d.mts +2 -2
- package/dist/collections/imap-mapped.d.mts.map +1 -1
- package/dist/collections/imap-mapped.mjs +10 -7
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts +2 -2
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +10 -7
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +2 -2
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs +6 -3
- 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 -5
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.d.mts +1 -1
- package/dist/collections/queue.d.mts.map +1 -1
- package/dist/collections/stack.d.mts +1 -1
- package/dist/collections/stack.d.mts.map +1 -1
- package/dist/guard/is-non-empty-string.d.mts +1 -1
- package/dist/guard/is-non-empty-string.d.mts.map +1 -1
- package/dist/guard/is-primitive.d.mts +1 -1
- package/dist/guard/is-primitive.d.mts.map +1 -1
- package/dist/guard/is-type.d.mts +1 -1
- package/dist/guard/is-type.d.mts.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/iterator/range.d.mts +5 -4
- package/dist/iterator/range.d.mts.map +1 -1
- package/dist/iterator/range.mjs.map +1 -1
- package/dist/json/json.d.mts +29 -32
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +1 -4
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/finite-number.d.mts +1 -1
- package/dist/number/branded-types/finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/int.d.mts +2 -2
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int16.d.mts +1 -1
- package/dist/number/branded-types/int16.d.mts.map +1 -1
- package/dist/number/branded-types/int32.d.mts +1 -1
- package/dist/number/branded-types/int32.d.mts.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +1 -1
- package/dist/number/branded-types/negative-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int.d.mts +1 -1
- package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +2 -2
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +1 -1
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +1 -1
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +2 -2
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +2 -2
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +1 -1
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.d.mts +2 -2
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +1 -1
- package/dist/number/branded-types/uint16.d.mts.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +1 -1
- package/dist/number/branded-types/uint32.d.mts.map +1 -1
- package/dist/number/enum/int8.d.mts +1 -1
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/uint8.d.mts +1 -1
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/num-arithmetic-types.d.mts +1 -1
- package/dist/number/num-arithmetic-types.d.mts.map +1 -1
- package/dist/number/num.d.mts +3 -3
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/refined-number-utils.d.mts +2 -2
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +6 -4
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts +5 -8
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +16 -13
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/cast-mutable.d.mts +1 -1
- package/dist/others/cast-mutable.d.mts.map +1 -1
- package/dist/others/cast-readonly.d.mts +1 -1
- package/dist/others/cast-readonly.d.mts.map +1 -1
- package/dist/others/debounce-function.d.mts.map +1 -1
- package/dist/others/debounce-function.mjs +1 -5
- package/dist/others/debounce-function.mjs.map +1 -1
- package/dist/others/memoize-function.d.mts +1 -1
- package/dist/others/memoize-function.d.mts.map +1 -1
- package/dist/string/str.d.mts +26 -18
- package/dist/string/str.d.mts.map +1 -1
- package/dist/string/str.mjs +9 -1
- package/dist/string/str.mjs.map +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/types.d.mts.map +1 -1
- package/package.json +33 -32
- package/src/array/impl/array-utils-creation.mts +24 -22
- package/src/array/impl/array-utils-creation.test.mts +25 -22
- package/src/array/impl/array-utils-element-access.mts +7 -7
- package/src/array/impl/array-utils-element-access.test.mts +2 -2
- package/src/array/impl/array-utils-iterators.mts +1 -1
- package/src/array/impl/array-utils-iterators.test.mts +1 -1
- package/src/array/impl/array-utils-length-bounded-array-cast.mts +43 -13
- package/src/array/impl/array-utils-length-bounded-array-cast.test.mts +6 -6
- package/src/array/impl/array-utils-length-bounded-array-guard.mts +15 -15
- package/src/array/impl/array-utils-length-bounded-array-guard.test.mts +66 -54
- package/src/array/impl/array-utils-length-bounded-tuple-cast.mts +32 -12
- package/src/array/impl/array-utils-length-bounded-tuple-cast.test.mts +10 -10
- package/src/array/impl/array-utils-length-bounded-tuple-guard.mts +8 -8
- package/src/array/impl/array-utils-length-bounded-tuple-guard.test.mts +38 -28
- package/src/array/impl/array-utils-length-constraint-preservation.test.mts +14 -14
- package/src/array/impl/array-utils-modification.mts +12 -12
- package/src/array/impl/array-utils-modification.test.mts +7 -7
- package/src/array/impl/array-utils-overload-type-error.test.mts +1 -1
- package/src/array/impl/array-utils-reducing-value.mts +9 -11
- package/src/array/impl/array-utils-reducing-value.test.mts +2 -2
- package/src/array/impl/array-utils-search.mts +4 -4
- package/src/array/impl/array-utils-search.test.mts +25 -17
- package/src/array/impl/array-utils-set-op.mts +1 -1
- package/src/array/impl/array-utils-shape-invariants.test.mts +8 -8
- package/src/array/impl/array-utils-size.mts +5 -5
- package/src/array/impl/array-utils-slice-clamped.mts +2 -2
- package/src/array/impl/array-utils-slicing.mts +8 -8
- package/src/array/impl/array-utils-slicing.test.mts +1 -1
- package/src/array/impl/array-utils-transformation.mts +26 -24
- package/src/array/impl/array-utils-transformation.test.mts +12 -10
- package/src/array/impl/array-utils-validation.mts +7 -7
- package/src/array/impl/array-utils-validation.test.mts +39 -39
- package/src/array/impl/array.test.mts +1 -1
- package/src/collections/imap-mapped.mts +15 -9
- package/src/collections/imap-mapped.test.mts +1 -1
- package/src/collections/imap.mts +15 -9
- package/src/collections/imap.test.mts +7 -5
- package/src/collections/iset-mapped.mts +14 -8
- package/src/collections/iset.mts +12 -10
- package/src/collections/iset.test.mts +14 -12
- package/src/collections/queue.mts +1 -1
- package/src/collections/stack.mts +1 -1
- package/src/collections/stack.test.mts +8 -6
- package/src/guard/is-error.test.mts +6 -4
- package/src/guard/is-non-empty-string.mts +1 -1
- package/src/guard/is-non-empty-string.test.mts +15 -11
- package/src/guard/is-primitive.mts +1 -1
- package/src/guard/is-type.mts +1 -1
- package/src/guard/is-type.test.mts +87 -59
- package/src/index.mts +2 -0
- package/src/iterator/range.mts +5 -9
- package/src/iterator/range.test.mts +29 -0
- package/src/json/json.mts +32 -35
- package/src/json/json.test.mts +106 -89
- package/src/number/branded-types/finite-number.mts +4 -4
- package/src/number/branded-types/int.mts +2 -2
- package/src/number/branded-types/int16.mts +1 -1
- package/src/number/branded-types/int32.mts +1 -1
- package/src/number/branded-types/negative-finite-number.mts +1 -1
- package/src/number/branded-types/negative-finite-number.test.mts +4 -4
- package/src/number/branded-types/negative-int.mts +3 -3
- package/src/number/branded-types/negative-int.test.mts +1 -1
- package/src/number/branded-types/negative-safe-int.mts +3 -3
- package/src/number/branded-types/negative-safe-int.test.mts +1 -1
- package/src/number/branded-types/non-negative-finite-number.mts +3 -3
- package/src/number/branded-types/non-negative-int16.mts +1 -1
- package/src/number/branded-types/non-negative-int32.mts +1 -1
- package/src/number/branded-types/non-positive-finite-number.mts +1 -1
- package/src/number/branded-types/non-positive-int.mts +1 -1
- package/src/number/branded-types/non-positive-safe-int.mts +1 -1
- package/src/number/branded-types/non-zero-finite-number.mts +5 -5
- package/src/number/branded-types/non-zero-int.mts +1 -1
- package/src/number/branded-types/non-zero-int16.mts +1 -1
- package/src/number/branded-types/non-zero-int32.mts +1 -1
- package/src/number/branded-types/non-zero-safe-int.mts +4 -4
- package/src/number/branded-types/non-zero-uint16.mts +1 -1
- package/src/number/branded-types/non-zero-uint32.mts +1 -1
- package/src/number/branded-types/positive-finite-number.mts +4 -4
- package/src/number/branded-types/positive-int.mts +2 -2
- package/src/number/branded-types/positive-int16.mts +1 -1
- package/src/number/branded-types/positive-int32.mts +1 -1
- package/src/number/branded-types/positive-safe-int.mts +4 -4
- package/src/number/branded-types/positive-uint16.mts +1 -1
- package/src/number/branded-types/positive-uint32.mts +1 -1
- package/src/number/branded-types/safe-int.mts +2 -5
- package/src/number/branded-types/safe-uint.mts +1 -1
- package/src/number/branded-types/uint.mts +2 -2
- package/src/number/branded-types/uint16.mts +1 -1
- package/src/number/branded-types/uint32.mts +1 -1
- package/src/number/enum/int8.mts +5 -5
- package/src/number/enum/uint8.mts +4 -4
- package/src/number/num-arithmetic-types.mts +27 -27
- package/src/number/num-arithmetic-types.test.mts +21 -21
- package/src/number/num-arithmetic.test.mts +6 -6
- package/src/number/num.mts +24 -24
- package/src/number/num.test.mts +1 -1
- package/src/number/refined-number-utils.mts +25 -21
- package/src/object/object.mts +46 -34
- package/src/object/object.test.mts +5 -5
- package/src/others/cast-mutable.mts +1 -1
- package/src/others/cast-readonly.mts +1 -1
- package/src/others/debounce-function.mts +1 -5
- package/src/others/fast-deep-equal.test.mts +1 -1
- package/src/others/map-nullable.test.mts +1 -1
- package/src/others/memoize-function.mts +1 -1
- package/src/string/str.mts +33 -25
- package/src/string/str.test.mts +48 -38
- package/src/types.mts +14 -14
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type {
|
|
2
|
+
BoundedLengthArray,
|
|
3
|
+
FixedLengthArray,
|
|
4
|
+
MaxLengthArray,
|
|
5
|
+
MinLengthArray,
|
|
6
6
|
} from 'ts-type-forge';
|
|
7
7
|
import { expectType } from '../../expect-type.mjs';
|
|
8
8
|
import {
|
|
@@ -32,39 +32,43 @@ describe(isMinLengthArray, () => {
|
|
|
32
32
|
test('should act as a type guard', () => {
|
|
33
33
|
const value: readonly number[] = [0, 1, 2, 3] as const;
|
|
34
34
|
|
|
35
|
-
if (isMinLengthArray(3, value)) {
|
|
36
|
-
|
|
35
|
+
if (!isMinLengthArray(3, value)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
expectType<typeof value, MinLengthArray<3, number>>('<=');
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
expectType<typeof value, MinLengthArray<1, number>>('<='); // 3 >= 1
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
// (even under `noUncheckedIndexedAccess`)
|
|
44
|
-
const _first = value[0];
|
|
43
|
+
expectType<typeof value, MinLengthArray<5, number>>('!<=');
|
|
45
44
|
|
|
46
|
-
|
|
45
|
+
// indexed access below the minimum length does not include `undefined`
|
|
46
|
+
// (even under `noUncheckedIndexedAccess`)
|
|
47
|
+
const _first = value[0];
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
expectType<typeof _first, number>('=');
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
const _third = value[2];
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
expectType<typeof _third, number>('=');
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
const _fourth = value[3];
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
expectType<typeof _fourth, number | undefined>('=');
|
|
58
|
+
|
|
59
|
+
expect(value.length).toBeGreaterThanOrEqual(3);
|
|
58
60
|
});
|
|
59
61
|
|
|
60
62
|
test('should preserve the original array type', () => {
|
|
61
63
|
const tuple = [1, 2, 3] as const;
|
|
62
64
|
|
|
63
|
-
if (isMinLengthArray(2, tuple)) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
expectType<typeof tuple, MinLengthArray<2, 1 | 2 | 3>>('<=');
|
|
65
|
+
if (!isMinLengthArray(2, tuple)) {
|
|
66
|
+
return;
|
|
67
67
|
}
|
|
68
|
+
|
|
69
|
+
expectType<typeof tuple, readonly [1, 2, 3]>('<=');
|
|
70
|
+
|
|
71
|
+
expectType<typeof tuple, MinLengthArray<2, 1 | 2 | 3>>('<=');
|
|
68
72
|
});
|
|
69
73
|
});
|
|
70
74
|
|
|
@@ -86,15 +90,17 @@ describe(isMaxLengthArray, () => {
|
|
|
86
90
|
test('should act as a type guard', () => {
|
|
87
91
|
const value: readonly number[] = [0, 1, 2] as const;
|
|
88
92
|
|
|
89
|
-
if (isMaxLengthArray(8, value)) {
|
|
90
|
-
|
|
93
|
+
if (!isMaxLengthArray(8, value)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
91
96
|
|
|
92
|
-
|
|
97
|
+
expectType<typeof value, MaxLengthArray<8, number>>('<=');
|
|
93
98
|
|
|
94
|
-
|
|
99
|
+
expectType<typeof value, MaxLengthArray<16, number>>('<='); // 8 <= 16
|
|
95
100
|
|
|
96
|
-
|
|
97
|
-
|
|
101
|
+
expectType<typeof value, MaxLengthArray<2, number>>('!<=');
|
|
102
|
+
|
|
103
|
+
expect(value.length).toBeLessThanOrEqual(8);
|
|
98
104
|
});
|
|
99
105
|
});
|
|
100
106
|
|
|
@@ -116,17 +122,19 @@ describe(isBoundedLengthArray, () => {
|
|
|
116
122
|
test('should act as a type guard', () => {
|
|
117
123
|
const value: readonly number[] = [1, 2, 3] as const;
|
|
118
124
|
|
|
119
|
-
if (isBoundedLengthArray(1, 5, value)) {
|
|
120
|
-
|
|
125
|
+
if (!isBoundedLengthArray(1, 5, value)) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
121
128
|
|
|
122
|
-
|
|
129
|
+
expectType<typeof value, BoundedLengthArray<1, 5, number>>('<=');
|
|
123
130
|
|
|
124
|
-
|
|
131
|
+
expectType<typeof value, BoundedLengthArray<0, 100, number>>('<=');
|
|
125
132
|
|
|
126
|
-
|
|
133
|
+
expectType<typeof value, MinLengthArray<1, number>>('<=');
|
|
127
134
|
|
|
128
|
-
|
|
129
|
-
|
|
135
|
+
expectType<typeof value, MaxLengthArray<5, number>>('<=');
|
|
136
|
+
|
|
137
|
+
expectType<typeof value, BoundedLengthArray<2, 5, number>>('!<=');
|
|
130
138
|
});
|
|
131
139
|
});
|
|
132
140
|
|
|
@@ -146,27 +154,29 @@ describe(isFixedLengthArray, () => {
|
|
|
146
154
|
test('should act as a type guard', () => {
|
|
147
155
|
const value: readonly number[] = [255, 128, 0] as const;
|
|
148
156
|
|
|
149
|
-
if (isFixedLengthArray(3, value)) {
|
|
150
|
-
|
|
157
|
+
if (!isFixedLengthArray(3, value)) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
151
160
|
|
|
152
|
-
|
|
161
|
+
expectType<typeof value, FixedLengthArray<3, number>>('<=');
|
|
153
162
|
|
|
154
|
-
|
|
163
|
+
expectType<typeof value, MaxLengthArray<5, number>>('<='); // 3 <= 5
|
|
155
164
|
|
|
156
|
-
|
|
165
|
+
expectType<typeof value, MinLengthArray<1, number>>('<='); // 3 >= 1
|
|
157
166
|
|
|
158
|
-
|
|
159
|
-
// not include `undefined` (even under `noUncheckedIndexedAccess`)
|
|
160
|
-
const _len = value.length;
|
|
167
|
+
expectType<typeof value, FixedLengthArray<4, number>>('!<=');
|
|
161
168
|
|
|
162
|
-
|
|
169
|
+
// `length` is narrowed to the literal and in-range indexed access does
|
|
170
|
+
// not include `undefined` (even under `noUncheckedIndexedAccess`)
|
|
171
|
+
const _len = value.length;
|
|
163
172
|
|
|
164
|
-
|
|
173
|
+
expectType<typeof _len, 3>('=');
|
|
165
174
|
|
|
166
|
-
|
|
175
|
+
const _second = value[1];
|
|
167
176
|
|
|
168
|
-
|
|
169
|
-
|
|
177
|
+
expectType<typeof _second, number>('=');
|
|
178
|
+
|
|
179
|
+
expect(value).toHaveLength(3);
|
|
170
180
|
});
|
|
171
181
|
});
|
|
172
182
|
|
|
@@ -182,13 +192,15 @@ describe('curried length guards', () => {
|
|
|
182
192
|
|
|
183
193
|
assert.isTrue(hasThree(value));
|
|
184
194
|
|
|
185
|
-
if (hasThree(value)) {
|
|
186
|
-
|
|
195
|
+
if (!hasThree(value)) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
187
198
|
|
|
188
|
-
|
|
199
|
+
expectType<typeof value, MinLengthArray<3, number>>('<=');
|
|
189
200
|
|
|
190
|
-
|
|
191
|
-
|
|
201
|
+
const _first = value[0];
|
|
202
|
+
|
|
203
|
+
expectType<typeof _first, number>('=');
|
|
192
204
|
});
|
|
193
205
|
|
|
194
206
|
test('isMaxLengthArray narrows when applied later', () => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type {
|
|
2
|
+
BoundedLengthTuple,
|
|
3
|
+
FixedLengthTuple,
|
|
4
|
+
MaxLengthTuple,
|
|
5
|
+
MinLengthTuple,
|
|
6
6
|
} from 'ts-type-forge';
|
|
7
|
-
import {
|
|
7
|
+
import type { SizeType } from '../../types.mjs';
|
|
8
8
|
import {
|
|
9
9
|
isBoundedLengthTuple,
|
|
10
10
|
isEmptyTuple,
|
|
@@ -36,7 +36,11 @@ import {
|
|
|
36
36
|
* // curried version
|
|
37
37
|
* const asRgb = Arr.asFixedLengthTuple(3);
|
|
38
38
|
*
|
|
39
|
-
*
|
|
39
|
+
* assert.strictEqual(red, 255);
|
|
40
|
+
*
|
|
41
|
+
* assert.deepStrictEqual(asRgb([0, 255, 0]), [0, 255, 0]);
|
|
42
|
+
*
|
|
43
|
+
* assert.throws(() => Arr.asFixedLengthTuple(3, [255, 128]), TypeError);
|
|
40
44
|
* ```
|
|
41
45
|
*
|
|
42
46
|
* @template Length - The exact number of elements.
|
|
@@ -104,7 +108,11 @@ const asFixedLengthTupleImpl = (
|
|
|
104
108
|
* // curried version
|
|
105
109
|
* const asHistory = Arr.asMinLengthTuple(3);
|
|
106
110
|
*
|
|
107
|
-
*
|
|
111
|
+
* assert.strictEqual(first, 0);
|
|
112
|
+
*
|
|
113
|
+
* assert.deepStrictEqual(asHistory([4, 5, 6]), [4, 5, 6]);
|
|
114
|
+
*
|
|
115
|
+
* assert.throws(() => Arr.asMinLengthTuple(3, [0, 1]), TypeError);
|
|
108
116
|
* ```
|
|
109
117
|
*
|
|
110
118
|
* @template MinLength - The minimum number of elements (inclusive).
|
|
@@ -170,7 +178,11 @@ const asMinLengthTupleImpl = (
|
|
|
170
178
|
* // curried version
|
|
171
179
|
* const asTags = Arr.asMaxLengthTuple(8);
|
|
172
180
|
*
|
|
173
|
-
*
|
|
181
|
+
* assert.deepStrictEqual(tags, ['a', 'b', 'c']);
|
|
182
|
+
*
|
|
183
|
+
* assert.deepStrictEqual(asTags(['d', 'e']), ['d', 'e']);
|
|
184
|
+
*
|
|
185
|
+
* assert.throws(() => Arr.asMaxLengthTuple(2, ['a', 'b', 'c']), TypeError);
|
|
174
186
|
* ```
|
|
175
187
|
*
|
|
176
188
|
* @template MaxLength - The maximum number of elements (inclusive).
|
|
@@ -236,7 +248,11 @@ const asMaxLengthTupleImpl = (
|
|
|
236
248
|
* // curried version
|
|
237
249
|
* const asSelection = Arr.asBoundedLengthTuple(1, 5);
|
|
238
250
|
*
|
|
239
|
-
*
|
|
251
|
+
* assert.deepStrictEqual(selection, [1, 2, 3]);
|
|
252
|
+
*
|
|
253
|
+
* assert.deepStrictEqual(asSelection([4, 5]), [4, 5]);
|
|
254
|
+
*
|
|
255
|
+
* assert.throws(() => Arr.asBoundedLengthTuple(1, 2, [1, 2, 3]), TypeError);
|
|
240
256
|
* ```
|
|
241
257
|
*
|
|
242
258
|
* @template Min - The minimum number of elements (inclusive).
|
|
@@ -311,7 +327,9 @@ const asBoundedLengthTupleImpl = (
|
|
|
311
327
|
* ```ts
|
|
312
328
|
* const nothing = Arr.asEmptyTuple([]);
|
|
313
329
|
*
|
|
314
|
-
*
|
|
330
|
+
* assert.deepStrictEqual(nothing, []);
|
|
331
|
+
*
|
|
332
|
+
* assert.throws(() => Arr.asEmptyTuple([1]), TypeError);
|
|
315
333
|
* ```
|
|
316
334
|
*
|
|
317
335
|
* @template Xs - The input array type (tuple types are preserved).
|
|
@@ -345,7 +363,9 @@ export const asEmptyTuple = <Xs extends readonly unknown[]>(
|
|
|
345
363
|
*
|
|
346
364
|
* const first: number = values[0]; // OK — no `undefined`
|
|
347
365
|
*
|
|
348
|
-
*
|
|
366
|
+
* assert.strictEqual(first, 1);
|
|
367
|
+
*
|
|
368
|
+
* assert.throws(() => Arr.asNonEmptyTuple([]), TypeError);
|
|
349
369
|
* ```
|
|
350
370
|
*
|
|
351
371
|
* @template Xs - The input array type (tuple types are preserved).
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type {
|
|
2
|
+
BoundedLengthTuple,
|
|
3
|
+
FixedLengthTuple,
|
|
4
|
+
MaxLengthTuple,
|
|
5
|
+
MinLengthTuple,
|
|
6
6
|
} from 'ts-type-forge';
|
|
7
7
|
import { expectType } from '../../expect-type.mjs';
|
|
8
8
|
import {
|
|
@@ -24,7 +24,7 @@ describe(asFixedLengthTuple, () => {
|
|
|
24
24
|
|
|
25
25
|
const red: number = casted[0];
|
|
26
26
|
|
|
27
|
-
assert.
|
|
27
|
+
assert.strictEqual(red, 255);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
test('is the same value it was handed', () => {
|
|
@@ -69,7 +69,7 @@ describe(asMinLengthTuple, () => {
|
|
|
69
69
|
|
|
70
70
|
const first: number = casted[0];
|
|
71
71
|
|
|
72
|
-
assert.
|
|
72
|
+
assert.strictEqual(first, 0);
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
test('throws when the array is too short', () => {
|
|
@@ -168,7 +168,7 @@ describe(asNonEmptyTuple, () => {
|
|
|
168
168
|
|
|
169
169
|
const first: number = casted[0];
|
|
170
170
|
|
|
171
|
-
assert.
|
|
171
|
+
assert.strictEqual(first, 1);
|
|
172
172
|
});
|
|
173
173
|
|
|
174
174
|
test('throws when the array is empty', () => {
|
|
@@ -190,7 +190,7 @@ describe('tuple casts preserve the input type, like their branded counterparts',
|
|
|
190
190
|
|
|
191
191
|
const length: 5 = casted.length;
|
|
192
192
|
|
|
193
|
-
assert.
|
|
193
|
+
assert.strictEqual(length, 5);
|
|
194
194
|
|
|
195
195
|
assert.deepStrictEqual<readonly number[]>(casted, [1, 2, 3, 4, 5]);
|
|
196
196
|
});
|
|
@@ -202,6 +202,6 @@ describe('tuple casts preserve the input type, like their branded counterparts',
|
|
|
202
202
|
|
|
203
203
|
const first: 1 = casted[0];
|
|
204
204
|
|
|
205
|
-
assert.
|
|
205
|
+
assert.strictEqual(first, 1);
|
|
206
206
|
});
|
|
207
207
|
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type {
|
|
2
|
+
BoundedLengthTuple,
|
|
3
|
+
FixedLengthTuple,
|
|
4
|
+
MaxLengthTuple,
|
|
5
|
+
MinLengthTuple,
|
|
6
6
|
} from 'ts-type-forge';
|
|
7
|
-
import {
|
|
7
|
+
import type { SizeType } from '../../types.mjs';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Type guard that checks if an array is empty, narrowing it to the structural
|
|
@@ -218,7 +218,7 @@ const hasMaxLength = (
|
|
|
218
218
|
* assert.isFalse(Arr.isBoundedLengthTuple(1, 3, quad));
|
|
219
219
|
*
|
|
220
220
|
* if (Arr.isBoundedLengthTuple(1, 3, pair)) {
|
|
221
|
-
* assert.isTrue(pair.length
|
|
221
|
+
* assert.isTrue(1 <= pair.length && pair.length <= 3);
|
|
222
222
|
* }
|
|
223
223
|
* ```
|
|
224
224
|
*/
|
|
@@ -263,4 +263,4 @@ const isWithinBounds = (
|
|
|
263
263
|
min: SizeType.ArgArr,
|
|
264
264
|
max: SizeType.ArgArr,
|
|
265
265
|
array: readonly unknown[],
|
|
266
|
-
): boolean => array.length
|
|
266
|
+
): boolean => min <= array.length && array.length <= max;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type {
|
|
2
|
+
BoundedLengthTuple,
|
|
3
|
+
FixedLengthTuple,
|
|
4
|
+
MaxLengthTuple,
|
|
5
|
+
MinLengthTuple,
|
|
6
6
|
} from 'ts-type-forge';
|
|
7
7
|
import { expectType } from '../../expect-type.mjs';
|
|
8
8
|
import {
|
|
@@ -92,11 +92,13 @@ describe('Arr structural tuple length guards', () => {
|
|
|
92
92
|
test('should work as type guard with exact length (additional)', () => {
|
|
93
93
|
const array: readonly number[] = [1, 2, 3] as const;
|
|
94
94
|
|
|
95
|
-
if (isFixedLengthTuple(3, array)) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
expect(array).toHaveLength(3);
|
|
95
|
+
if (!isFixedLengthTuple(3, array)) {
|
|
96
|
+
return;
|
|
99
97
|
}
|
|
98
|
+
|
|
99
|
+
expectType<typeof array, FixedLengthTuple<3, number>>('=');
|
|
100
|
+
|
|
101
|
+
expect(array).toHaveLength(3);
|
|
100
102
|
});
|
|
101
103
|
});
|
|
102
104
|
|
|
@@ -180,11 +182,13 @@ describe('Arr structural tuple length guards', () => {
|
|
|
180
182
|
test('should work as type guard for at least length (additional)', () => {
|
|
181
183
|
const array: readonly number[] = [1, 2, 3] as const;
|
|
182
184
|
|
|
183
|
-
if (isMinLengthTuple(2, array)) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
expect(array.length).toBeGreaterThanOrEqual(2);
|
|
185
|
+
if (!isMinLengthTuple(2, array)) {
|
|
186
|
+
return;
|
|
187
187
|
}
|
|
188
|
+
|
|
189
|
+
expectType<typeof array, MinLengthTuple<2, number>>('=');
|
|
190
|
+
|
|
191
|
+
expect(array.length).toBeGreaterThanOrEqual(2);
|
|
188
192
|
});
|
|
189
193
|
});
|
|
190
194
|
|
|
@@ -255,11 +259,13 @@ describe('Arr structural tuple length guards', () => {
|
|
|
255
259
|
test('should work as type guard for at most length (additional)', () => {
|
|
256
260
|
const array: readonly number[] = [1, 2] as const;
|
|
257
261
|
|
|
258
|
-
if (isMaxLengthTuple(3, array)) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
expect(array.length).toBeLessThanOrEqual(3);
|
|
262
|
+
if (!isMaxLengthTuple(3, array)) {
|
|
263
|
+
return;
|
|
262
264
|
}
|
|
265
|
+
|
|
266
|
+
expectType<typeof array, MaxLengthTuple<3, number>>('=');
|
|
267
|
+
|
|
268
|
+
expect(array.length).toBeLessThanOrEqual(3);
|
|
263
269
|
});
|
|
264
270
|
});
|
|
265
271
|
|
|
@@ -332,13 +338,15 @@ describe('Arr structural tuple length guards', () => {
|
|
|
332
338
|
test('should work as type guard for bounded length (additional)', () => {
|
|
333
339
|
const array: readonly number[] = [1, 2] as const;
|
|
334
340
|
|
|
335
|
-
if (isBoundedLengthTuple(1, 3, array)) {
|
|
336
|
-
|
|
341
|
+
if (!isBoundedLengthTuple(1, 3, array)) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
337
344
|
|
|
338
|
-
|
|
345
|
+
expectType<typeof array, BoundedLengthTuple<1, 3, number>>('=');
|
|
339
346
|
|
|
340
|
-
|
|
341
|
-
|
|
347
|
+
expect(array.length).toBeGreaterThanOrEqual(1);
|
|
348
|
+
|
|
349
|
+
expect(array.length).toBeLessThanOrEqual(3);
|
|
342
350
|
});
|
|
343
351
|
});
|
|
344
352
|
|
|
@@ -364,14 +372,16 @@ describe('Arr structural tuple length guards', () => {
|
|
|
364
372
|
|
|
365
373
|
assert.isTrue(isNonEmptyTuple(values));
|
|
366
374
|
|
|
367
|
-
if (isNonEmptyTuple(values)) {
|
|
368
|
-
|
|
375
|
+
if (!isNonEmptyTuple(values)) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
expectType<typeof values, MinLengthTuple<1, number>>('=');
|
|
369
380
|
|
|
370
|
-
|
|
371
|
-
|
|
381
|
+
// The structural prefix makes the first element defined.
|
|
382
|
+
const first: number = values[0];
|
|
372
383
|
|
|
373
|
-
|
|
374
|
-
}
|
|
384
|
+
assert.strictEqual(first, 1);
|
|
375
385
|
});
|
|
376
386
|
|
|
377
387
|
test('rejects an empty array', () => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type {
|
|
2
|
+
BoundedLengthArray,
|
|
3
|
+
FixedLengthArray,
|
|
4
|
+
FixedLengthTuple,
|
|
5
|
+
MaxLengthArray,
|
|
6
|
+
MinLengthArray,
|
|
7
|
+
Seq,
|
|
8
8
|
} from 'ts-type-forge';
|
|
9
9
|
import { expectType } from '../../expect-type.mjs';
|
|
10
10
|
import { copy, create, seq, zeros } from './array-utils-creation.mjs';
|
|
@@ -39,7 +39,7 @@ describe('map preserves length constraints', () => {
|
|
|
39
39
|
// The structural prefix survives, so in-range access is not `undefined`.
|
|
40
40
|
const first: string = result[0];
|
|
41
41
|
|
|
42
|
-
assert.
|
|
42
|
+
assert.strictEqual(first, '#0');
|
|
43
43
|
|
|
44
44
|
assert.deepStrictEqual<readonly string[]>(result, ['#0', '#1', '#2', '#3']);
|
|
45
45
|
});
|
|
@@ -56,7 +56,7 @@ describe('map preserves length constraints', () => {
|
|
|
56
56
|
|
|
57
57
|
const length: 3 = result.length;
|
|
58
58
|
|
|
59
|
-
assert.
|
|
59
|
+
assert.strictEqual(length, 3);
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
test('a minimum above the structural prefix cap survives, clamped like MinLengthArray itself', () => {
|
|
@@ -199,7 +199,7 @@ describe('other length-preserving utilities preserve length constraints', () =>
|
|
|
199
199
|
// The structural prefix survives the reversal too.
|
|
200
200
|
const first: number = result[0];
|
|
201
201
|
|
|
202
|
-
assert.
|
|
202
|
+
assert.strictEqual(first, 4);
|
|
203
203
|
|
|
204
204
|
assert.deepStrictEqual<readonly number[]>(result, [4, 3, 2, 1]);
|
|
205
205
|
});
|
|
@@ -242,7 +242,7 @@ describe('partition reports the bounds of each chunk', () => {
|
|
|
242
242
|
|
|
243
243
|
const first: 1 | 2 | 3 | 4 | 5 = firstChunk[0];
|
|
244
244
|
|
|
245
|
-
assert.
|
|
245
|
+
assert.strictEqual(first, 1);
|
|
246
246
|
|
|
247
247
|
assert.deepStrictEqual<readonly (readonly number[])[]>(result, [
|
|
248
248
|
[1, 2],
|
|
@@ -262,7 +262,7 @@ describe('creation utilities report an exact length past their tuple range', ()
|
|
|
262
262
|
|
|
263
263
|
expectType<typeof result, FixedLengthArray<12, 'x'>>('~=');
|
|
264
264
|
|
|
265
|
-
assert.
|
|
265
|
+
assert.strictEqual(result.length, 12);
|
|
266
266
|
});
|
|
267
267
|
|
|
268
268
|
test('a length still inside the tuple range keeps its exact tuple type', () => {
|
|
@@ -280,8 +280,8 @@ describe('creation utilities report an exact length past their tuple range', ()
|
|
|
280
280
|
|
|
281
281
|
expectType<typeof seq12, Seq<12>>('=');
|
|
282
282
|
|
|
283
|
-
assert.
|
|
283
|
+
assert.strictEqual(zeros12.length, 12);
|
|
284
284
|
|
|
285
|
-
assert.
|
|
285
|
+
assert.strictEqual(seq12.length, 12);
|
|
286
286
|
});
|
|
287
287
|
});
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import type {
|
|
2
|
+
ChangeArrayElement,
|
|
3
|
+
ConstrainedList,
|
|
4
|
+
FixedLengthTuple,
|
|
5
|
+
Increment,
|
|
6
|
+
IsFixedLengthList,
|
|
7
|
+
NonEmptyArray,
|
|
8
|
+
UnknownBrand,
|
|
9
9
|
} from 'ts-type-forge';
|
|
10
10
|
import { asPositiveUint32 } from '../../number/index.mjs';
|
|
11
11
|
import { castMutable } from '../../others/index.mjs';
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
import type {
|
|
13
|
+
ArgArrayIndex,
|
|
14
|
+
ArgArrayIndexWithNegative,
|
|
15
|
+
SizeType,
|
|
16
16
|
} from '../../types.mjs';
|
|
17
17
|
import { copy, create } from './array-utils-creation.mjs';
|
|
18
18
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type {
|
|
2
|
+
BoundedLengthArray,
|
|
3
|
+
FixedLengthArray,
|
|
4
|
+
FixedLengthTuple,
|
|
5
|
+
MinLengthArray,
|
|
6
|
+
NonEmptyArray,
|
|
7
7
|
} from 'ts-type-forge';
|
|
8
8
|
import { expectType } from '../../expect-type.mjs';
|
|
9
9
|
import { asUint32 } from '../../number/index.mjs';
|
|
10
|
-
import {
|
|
10
|
+
import type { SizeType } from '../../types.mjs';
|
|
11
11
|
import {
|
|
12
12
|
asBoundedLengthArray,
|
|
13
13
|
asFixedLengthArray,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
2
|
import { pipe } from '../../functional/index.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import type { SizeType } from '../../types.mjs';
|
|
4
4
|
import { range } from './array-utils-creation.mjs';
|
|
5
5
|
import { findIndex } from './array-utils-search.mjs';
|
|
6
6
|
import { filterNot, partition } from './array-utils-transformation.mjs';
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { isError } from '@sindresorhus/is';
|
|
2
|
-
import {
|
|
2
|
+
import type { Int, NonEmptyTuple, Uint } from 'ts-type-forge';
|
|
3
3
|
import { IMap } from '../../collections/index.mjs';
|
|
4
4
|
import { Optional, Result } from '../../functional/index.mjs';
|
|
5
5
|
import { isString, isUndefined } from '../../guard/index.mjs';
|
|
6
6
|
import { asUint32, Num, Uint32 } from '../../number/index.mjs';
|
|
7
7
|
import { unknownToString } from '../../others/index.mjs';
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
import type {
|
|
9
|
+
ArrayIndex,
|
|
10
|
+
MapSetKeyType,
|
|
11
|
+
SizeType,
|
|
12
|
+
Some,
|
|
13
13
|
} from '../../types.mjs';
|
|
14
14
|
import { isNonEmpty } from './array-utils-length-bounded-array-guard.mjs';
|
|
15
15
|
|
|
@@ -605,11 +605,9 @@ export function join(
|
|
|
605
605
|
case 1: {
|
|
606
606
|
const [arg] = args;
|
|
607
607
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
return joinImpl(arg, undefined);
|
|
608
|
+
return isString(arg) || isUndefined(arg)
|
|
609
|
+
? (array) => joinImpl(array, arg)
|
|
610
|
+
: joinImpl(arg, undefined);
|
|
613
611
|
}
|
|
614
612
|
|
|
615
613
|
case 2: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Uint32 } from 'ts-type-forge';
|
|
2
2
|
import { IMap } from '../../collections/index.mjs';
|
|
3
3
|
import { expectType } from '../../expect-type.mjs';
|
|
4
4
|
import { Optional, Result } from '../../functional/index.mjs';
|
|
5
|
-
import {
|
|
5
|
+
import type { Some } from '../../types.mjs';
|
|
6
6
|
import {
|
|
7
7
|
count,
|
|
8
8
|
countBy,
|