ts-data-forge 5.1.0 → 6.0.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 +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/is-record.d.mts.map +1 -1
- package/dist/guard/is-record.mjs +1 -1
- package/dist/guard/is-record.mjs.map +1 -1
- 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.mts +1 -2
- package/src/guard/is-record.test.mts +57 -67
- 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
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
*
|
|
11
11
|
* const differentNumbers = [1, 2, 4] as const;
|
|
12
12
|
*
|
|
13
|
-
* assert.
|
|
13
|
+
* assert.isTrue(Arr.eq(numbers, sameNumbers));
|
|
14
14
|
*
|
|
15
|
-
* assert.
|
|
15
|
+
* assert.isFalse(Arr.eq(numbers, differentNumbers));
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
export const eq = <E,>(
|
|
@@ -43,9 +43,9 @@ export const equal = eq;
|
|
|
43
43
|
*
|
|
44
44
|
* const notSubset = [2, 4] as const;
|
|
45
45
|
*
|
|
46
|
-
* assert.
|
|
46
|
+
* assert.isTrue(Arr.isSubset(subset, superset));
|
|
47
47
|
*
|
|
48
|
-
* assert.
|
|
48
|
+
* assert.isFalse(Arr.isSubset(notSubset, superset));
|
|
49
49
|
* ```
|
|
50
50
|
*/
|
|
51
51
|
export const isSubset = <E1 extends Primitive, E2 extends Primitive = E1>(
|
|
@@ -69,11 +69,11 @@ export const isSubset = <E1 extends Primitive, E2 extends Primitive = E1>(
|
|
|
69
69
|
*
|
|
70
70
|
* const notSuperset = ['a', 'd'] as const;
|
|
71
71
|
*
|
|
72
|
-
* assert.
|
|
72
|
+
* assert.isTrue(Arr.isSuperset(potentialSuperset, subset));
|
|
73
73
|
*
|
|
74
|
-
* assert.
|
|
74
|
+
* assert.isFalse(Arr.isSuperset(subset, potentialSuperset));
|
|
75
75
|
*
|
|
76
|
-
* assert.
|
|
76
|
+
* assert.isFalse(Arr.isSuperset(potentialSuperset, notSuperset));
|
|
77
77
|
* ```
|
|
78
78
|
*/
|
|
79
79
|
export const isSuperset = <E1 extends Primitive, E2 extends Primitive = E1>(
|
|
@@ -20,7 +20,7 @@ describe('Arr set operations', () => {
|
|
|
20
20
|
expectType<typeof result, boolean>('=');
|
|
21
21
|
|
|
22
22
|
test('should return true for equal arrays of numbers', () => {
|
|
23
|
-
|
|
23
|
+
assert.isTrue(result);
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -34,7 +34,7 @@ describe('Arr set operations', () => {
|
|
|
34
34
|
expectType<typeof result, boolean>('=');
|
|
35
35
|
|
|
36
36
|
test('should return false for different arrays of numbers', () => {
|
|
37
|
-
|
|
37
|
+
assert.isFalse(result);
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -48,7 +48,7 @@ describe('Arr set operations', () => {
|
|
|
48
48
|
expectType<typeof result, boolean>('=');
|
|
49
49
|
|
|
50
50
|
test('should return false for arrays of different lengths', () => {
|
|
51
|
-
|
|
51
|
+
assert.isFalse(result);
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -62,7 +62,7 @@ describe('Arr set operations', () => {
|
|
|
62
62
|
expectType<typeof result, boolean>('=');
|
|
63
63
|
|
|
64
64
|
test('should return true for equal arrays of strings', () => {
|
|
65
|
-
|
|
65
|
+
assert.isTrue(result);
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -76,7 +76,7 @@ describe('Arr set operations', () => {
|
|
|
76
76
|
expectType<typeof result, boolean>('=');
|
|
77
77
|
|
|
78
78
|
test('should return true for empty arrays', () => {
|
|
79
|
-
|
|
79
|
+
assert.isTrue(result);
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -91,7 +91,7 @@ describe('Arr set operations', () => {
|
|
|
91
91
|
expectType<typeof result, boolean>('=');
|
|
92
92
|
|
|
93
93
|
test('should return false for arrays of objects with default equality (reference check)', () => {
|
|
94
|
-
|
|
94
|
+
assert.isFalse(result);
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -109,7 +109,7 @@ describe('Arr set operations', () => {
|
|
|
109
109
|
expectType<typeof result, boolean>('=');
|
|
110
110
|
|
|
111
111
|
test('should return true for arrays of same object references', () => {
|
|
112
|
-
|
|
112
|
+
assert.isTrue(result);
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -127,7 +127,7 @@ describe('Arr set operations', () => {
|
|
|
127
127
|
expectType<typeof result, boolean>('=');
|
|
128
128
|
|
|
129
129
|
test('should return true for arrays of objects with custom equality function', () => {
|
|
130
|
-
|
|
130
|
+
assert.isTrue(result);
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
133
|
});
|
|
@@ -143,7 +143,7 @@ describe('Arr set operations', () => {
|
|
|
143
143
|
expectType<typeof result, boolean>('=');
|
|
144
144
|
|
|
145
145
|
test('case 1', () => {
|
|
146
|
-
|
|
146
|
+
assert.isTrue(result);
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
149
|
|
|
@@ -157,7 +157,7 @@ describe('Arr set operations', () => {
|
|
|
157
157
|
expectType<typeof result, boolean>('=');
|
|
158
158
|
|
|
159
159
|
test('case 2', () => {
|
|
160
|
-
|
|
160
|
+
assert.isFalse(result);
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
});
|
|
@@ -173,13 +173,13 @@ describe('Arr set operations', () => {
|
|
|
173
173
|
expectType<typeof result, boolean>('=');
|
|
174
174
|
|
|
175
175
|
test('case 1', () => {
|
|
176
|
-
|
|
176
|
+
assert.isFalse(result);
|
|
177
177
|
});
|
|
178
178
|
|
|
179
179
|
const result2 = isSuperset(xs, ys);
|
|
180
180
|
|
|
181
181
|
test('case 2', () => {
|
|
182
|
-
|
|
182
|
+
assert.isTrue(result2);
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
185
|
|
|
@@ -193,7 +193,7 @@ describe('Arr set operations', () => {
|
|
|
193
193
|
expectType<typeof result, boolean>('=');
|
|
194
194
|
|
|
195
195
|
test('case 3', () => {
|
|
196
|
-
|
|
196
|
+
assert.isFalse(result);
|
|
197
197
|
});
|
|
198
198
|
}
|
|
199
199
|
});
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
*
|
|
13
13
|
* const sizeOfLetters = Arr.size(letters);
|
|
14
14
|
*
|
|
15
|
-
* assert(sizeOfNumbers === 3);
|
|
15
|
+
* assert.isTrue(sizeOfNumbers === 3);
|
|
16
16
|
*
|
|
17
|
-
* assert(sizeOfLetters === 0);
|
|
17
|
+
* assert.isTrue(sizeOfLetters === 0);
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
export const size = <const Ar extends readonly unknown[]>(
|
|
@@ -16,7 +16,7 @@ import { isEmpty } from './array-utils-validation.mjs';
|
|
|
16
16
|
*
|
|
17
17
|
* assert.deepStrictEqual(remainder, ['Grace', 'Katherine']);
|
|
18
18
|
*
|
|
19
|
-
* assert(remainder.length === 2);
|
|
19
|
+
* assert.isTrue(remainder.length === 2);
|
|
20
20
|
* }
|
|
21
21
|
*
|
|
22
22
|
* {
|
|
@@ -50,7 +50,7 @@ export const tail = <const Ar extends readonly unknown[]>(
|
|
|
50
50
|
*
|
|
51
51
|
* assert.deepStrictEqual(withoutLast, ['task-1', 'task-2']);
|
|
52
52
|
*
|
|
53
|
-
* assert(withoutLast.length === 2);
|
|
53
|
+
* assert.isTrue(withoutLast.length === 2);
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
56
|
export const butLast = <const Ar extends readonly unknown[]>(
|
|
@@ -893,9 +893,9 @@ describe('Arr transformations', () => {
|
|
|
893
893
|
|
|
894
894
|
const vegetables = grouped.get('vegetable');
|
|
895
895
|
|
|
896
|
-
|
|
896
|
+
assert.isTrue(Optional.isSome(fruits));
|
|
897
897
|
|
|
898
|
-
|
|
898
|
+
assert.isTrue(Optional.isSome(vegetables));
|
|
899
899
|
|
|
900
900
|
if (Optional.isSome(fruits)) {
|
|
901
901
|
expect(fruits.value).toHaveLength(2);
|
|
@@ -10,9 +10,9 @@ import { asUint32, Num } from '../../number/index.mjs';
|
|
|
10
10
|
*
|
|
11
11
|
* const maybeValue: unknown = 'Ada';
|
|
12
12
|
*
|
|
13
|
-
* assert.
|
|
13
|
+
* assert.isTrue(Arr.isArray(maybeArray));
|
|
14
14
|
*
|
|
15
|
-
* assert.
|
|
15
|
+
* assert.isFalse(Arr.isArray(maybeValue));
|
|
16
16
|
*
|
|
17
17
|
* if (Arr.isArray(maybeArray)) {
|
|
18
18
|
* assert.deepStrictEqual(maybeArray, [1, 2, 3]);
|
|
@@ -45,9 +45,9 @@ type Cast<A, B> = A extends B ? A : never;
|
|
|
45
45
|
*
|
|
46
46
|
* const words = ['Ada', 'Lovelace'] as const;
|
|
47
47
|
*
|
|
48
|
-
* assert.
|
|
48
|
+
* assert.isTrue(Arr.isEmpty(emptyNumbers));
|
|
49
49
|
*
|
|
50
|
-
* assert.
|
|
50
|
+
* assert.isFalse(Arr.isEmpty(words));
|
|
51
51
|
*
|
|
52
52
|
* if (Arr.isEmpty(emptyNumbers)) {
|
|
53
53
|
* assert.deepStrictEqual(emptyNumbers, []);
|
|
@@ -67,9 +67,9 @@ export const isEmpty = <E,>(array: readonly E[]): array is readonly [] =>
|
|
|
67
67
|
*
|
|
68
68
|
* const emptyUsers: readonly { id: number }[] = [];
|
|
69
69
|
*
|
|
70
|
-
* assert.
|
|
70
|
+
* assert.isTrue(Arr.isNonEmpty(users));
|
|
71
71
|
*
|
|
72
|
-
* assert.
|
|
72
|
+
* assert.isFalse(Arr.isNonEmpty(emptyUsers));
|
|
73
73
|
*
|
|
74
74
|
* if (Arr.isNonEmpty(users)) {
|
|
75
75
|
* assert.deepStrictEqual(users[0], { id: 1 });
|
|
@@ -90,9 +90,9 @@ export const isNonEmpty = <E,>(
|
|
|
90
90
|
*
|
|
91
91
|
* const triple: readonly number[] = [1, 2, 3];
|
|
92
92
|
*
|
|
93
|
-
* assert.
|
|
93
|
+
* assert.isTrue(Arr.isArrayOfLength(pair, 2));
|
|
94
94
|
*
|
|
95
|
-
* assert.
|
|
95
|
+
* assert.isFalse(Arr.isArrayOfLength(triple, 2));
|
|
96
96
|
*
|
|
97
97
|
* if (Arr.isArrayOfLength(pair, 2)) {
|
|
98
98
|
* assert.deepStrictEqual(pair, [1, 2]);
|
|
@@ -114,12 +114,12 @@ export const isArrayOfLength = <E, N extends SizeType.ArgArr>(
|
|
|
114
114
|
*
|
|
115
115
|
* const emptyQueue: readonly string[] = [];
|
|
116
116
|
*
|
|
117
|
-
* assert.
|
|
117
|
+
* assert.isTrue(Arr.isArrayAtLeastLength(queue, 1));
|
|
118
118
|
*
|
|
119
|
-
* assert.
|
|
119
|
+
* assert.isFalse(Arr.isArrayAtLeastLength(emptyQueue, 1));
|
|
120
120
|
*
|
|
121
121
|
* if (Arr.isArrayAtLeastLength(queue, 1)) {
|
|
122
|
-
* assert(queue[0] === 'task-1');
|
|
122
|
+
* assert.isTrue(queue[0] === 'task-1');
|
|
123
123
|
* }
|
|
124
124
|
* ```
|
|
125
125
|
*/
|
|
@@ -142,9 +142,9 @@ export const isArrayAtLeastLength = <E, N extends SizeType.ArgArr>(
|
|
|
142
142
|
*
|
|
143
143
|
* const allStartWithA = Arr.every(words, (value) => value.startsWith('A'));
|
|
144
144
|
*
|
|
145
|
-
* assert.
|
|
145
|
+
* assert.isTrue(allEven);
|
|
146
146
|
*
|
|
147
|
-
* assert.
|
|
147
|
+
* assert.isFalse(allStartWithA);
|
|
148
148
|
* ```
|
|
149
149
|
*/
|
|
150
150
|
// Type guard overloads - narrow the entire array type
|
|
@@ -204,9 +204,9 @@ export function every<E>(
|
|
|
204
204
|
*
|
|
205
205
|
* const hasShortName = Arr.some(words, (value) => value.length <= 3);
|
|
206
206
|
*
|
|
207
|
-
* assert.
|
|
207
|
+
* assert.isFalse(hasEven);
|
|
208
208
|
*
|
|
209
|
-
* assert.
|
|
209
|
+
* assert.isTrue(hasShortName);
|
|
210
210
|
* ```
|
|
211
211
|
*/
|
|
212
212
|
export function some<const Ar extends readonly unknown[]>(
|
|
@@ -249,12 +249,12 @@ export function some<E>(
|
|
|
249
249
|
* ```ts
|
|
250
250
|
* const items = ['Ada', 'Grace', 'Katherine'] as const;
|
|
251
251
|
*
|
|
252
|
-
* assert.
|
|
252
|
+
* assert.isTrue(Arr.indexIsInRange(items, 1));
|
|
253
253
|
*
|
|
254
|
-
* assert.
|
|
254
|
+
* assert.isFalse(Arr.indexIsInRange(items, 3));
|
|
255
255
|
*
|
|
256
256
|
* if (Arr.indexIsInRange(items, 2)) {
|
|
257
|
-
* assert(items[2] === 'Katherine');
|
|
257
|
+
* assert.isTrue(items[2] === 'Katherine');
|
|
258
258
|
* }
|
|
259
259
|
* ```
|
|
260
260
|
*/
|