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
package/src/number/num.mts
CHANGED
|
@@ -26,7 +26,7 @@ export namespace Num {
|
|
|
26
26
|
*
|
|
27
27
|
* const result = Num.from(input);
|
|
28
28
|
*
|
|
29
|
-
* assert(result === 123.45);
|
|
29
|
+
* assert.isTrue(result === 123.45);
|
|
30
30
|
* ```
|
|
31
31
|
*
|
|
32
32
|
* @param n The value to convert.
|
|
@@ -51,10 +51,10 @@ export namespace Num {
|
|
|
51
51
|
* // eslint-disable-next-line total-functions/no-partial-division
|
|
52
52
|
* const inverted = 1 / value;
|
|
53
53
|
*
|
|
54
|
-
* assert(inverted === 0.2);
|
|
54
|
+
* assert.isTrue(inverted === 0.2);
|
|
55
55
|
* }
|
|
56
56
|
*
|
|
57
|
-
* assert.
|
|
57
|
+
* assert.isFalse(Num.isNonZero(0));
|
|
58
58
|
* ```
|
|
59
59
|
*
|
|
60
60
|
* @template N - The numeric literal type or number type to check
|
|
@@ -83,10 +83,10 @@ export namespace Num {
|
|
|
83
83
|
* if (Num.isNonNegative(candidate)) {
|
|
84
84
|
* const index: number = candidate;
|
|
85
85
|
*
|
|
86
|
-
* assert(index === 10);
|
|
86
|
+
* assert.isTrue(index === 10);
|
|
87
87
|
* }
|
|
88
88
|
*
|
|
89
|
-
* assert.
|
|
89
|
+
* assert.isFalse(Num.isNonNegative(-1));
|
|
90
90
|
* ```
|
|
91
91
|
*
|
|
92
92
|
* @template N - The numeric literal type or number type to check
|
|
@@ -111,10 +111,10 @@ export namespace Num {
|
|
|
111
111
|
* const amount = 42;
|
|
112
112
|
*
|
|
113
113
|
* if (Num.isPositive(amount)) {
|
|
114
|
-
* assert.
|
|
114
|
+
* assert.isTrue(amount > 0);
|
|
115
115
|
* }
|
|
116
116
|
*
|
|
117
|
-
* assert.
|
|
117
|
+
* assert.isFalse(Num.isPositive(0));
|
|
118
118
|
* ```
|
|
119
119
|
*
|
|
120
120
|
* @template N - The numeric literal type or number type to check
|
|
@@ -135,9 +135,9 @@ export namespace Num {
|
|
|
135
135
|
* ```ts
|
|
136
136
|
* const isGrade = Num.isInRange(0, 100);
|
|
137
137
|
*
|
|
138
|
-
* assert.
|
|
138
|
+
* assert.isTrue(isGrade(50));
|
|
139
139
|
*
|
|
140
|
-
* assert.
|
|
140
|
+
* assert.isFalse(isGrade(100));
|
|
141
141
|
* ```
|
|
142
142
|
*
|
|
143
143
|
* @param lowerBound The lower bound (inclusive).
|
|
@@ -159,9 +159,9 @@ export namespace Num {
|
|
|
159
159
|
* ```ts
|
|
160
160
|
* const isPercentage = Num.isInRangeInclusive(0, 100);
|
|
161
161
|
*
|
|
162
|
-
* assert.
|
|
162
|
+
* assert.isTrue(isPercentage(100));
|
|
163
163
|
*
|
|
164
|
-
* assert.
|
|
164
|
+
* assert.isFalse(isPercentage(-1));
|
|
165
165
|
* ```
|
|
166
166
|
*
|
|
167
167
|
* @param lowerBound The lower bound (inclusive).
|
|
@@ -219,11 +219,11 @@ export namespace Num {
|
|
|
219
219
|
* ```ts
|
|
220
220
|
* const indexGuard = Num.isUintInRange(0, 5);
|
|
221
221
|
*
|
|
222
|
-
* assert.
|
|
222
|
+
* assert.isTrue(indexGuard(3));
|
|
223
223
|
*
|
|
224
|
-
* assert.
|
|
224
|
+
* assert.isFalse(indexGuard(5));
|
|
225
225
|
*
|
|
226
|
-
* assert.
|
|
226
|
+
* assert.isFalse(indexGuard(-1));
|
|
227
227
|
* ```
|
|
228
228
|
*
|
|
229
229
|
* @template L - The lower bound as a SmallUint literal type
|
|
@@ -255,9 +255,9 @@ export namespace Num {
|
|
|
255
255
|
* ```ts
|
|
256
256
|
* const inclusiveGuard = Num.isUintInRangeInclusive(0, 5);
|
|
257
257
|
*
|
|
258
|
-
* assert.
|
|
258
|
+
* assert.isTrue(inclusiveGuard(5));
|
|
259
259
|
*
|
|
260
|
-
* assert.
|
|
260
|
+
* assert.isFalse(inclusiveGuard(6));
|
|
261
261
|
* ```
|
|
262
262
|
*
|
|
263
263
|
* @template L - The lower bound as a SmallUint literal type
|
|
@@ -284,15 +284,15 @@ export namespace Num {
|
|
|
284
284
|
* @example
|
|
285
285
|
*
|
|
286
286
|
* ```ts
|
|
287
|
-
* assert(Num.clamp(150, 0, 100) === 100);
|
|
287
|
+
* assert.isTrue(Num.clamp(150, 0, 100) === 100);
|
|
288
288
|
*
|
|
289
|
-
* assert(Num.clamp(-50, 0, 100) === 0);
|
|
289
|
+
* assert.isTrue(Num.clamp(-50, 0, 100) === 0);
|
|
290
290
|
*
|
|
291
291
|
* const clampToPercentage = Num.clamp(0, 100);
|
|
292
292
|
*
|
|
293
|
-
* assert(clampToPercentage(75) === 75);
|
|
293
|
+
* assert.isTrue(clampToPercentage(75) === 75);
|
|
294
294
|
*
|
|
295
|
-
* assert(clampToPercentage(150) === 100);
|
|
295
|
+
* assert.isTrue(clampToPercentage(150) === 100);
|
|
296
296
|
* ```
|
|
297
297
|
*/
|
|
298
298
|
export function clamp(
|
package/src/number/num.test.mts
CHANGED
|
@@ -93,7 +93,7 @@ describe('Num test', () => {
|
|
|
93
93
|
expectType<typeof x, number>('=');
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
assert.isTrue(f(x));
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
test('falsy case', () => {
|
|
@@ -107,7 +107,7 @@ describe('Num test', () => {
|
|
|
107
107
|
expectType<typeof x, number>('=');
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
assert.isFalse(f(x));
|
|
111
111
|
});
|
|
112
112
|
});
|
|
113
113
|
|
|
@@ -135,15 +135,15 @@ describe('Num test', () => {
|
|
|
135
135
|
test('checks range (lower inclusive, upper exclusive)', () => {
|
|
136
136
|
const inRange = Num.isInRange(0, 10);
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
assert.isTrue(inRange(5));
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
assert.isTrue(inRange(0)); // inclusive lower bound
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
assert.isFalse(inRange(10)); // exclusive upper bound
|
|
143
143
|
|
|
144
|
-
|
|
144
|
+
assert.isFalse(inRange(-1));
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
assert.isFalse(inRange(15));
|
|
147
147
|
});
|
|
148
148
|
});
|
|
149
149
|
|
|
@@ -151,15 +151,15 @@ describe('Num test', () => {
|
|
|
151
151
|
test('checks range (inclusive)', () => {
|
|
152
152
|
const inRange = Num.isInRangeInclusive(0, 10);
|
|
153
153
|
|
|
154
|
-
|
|
154
|
+
assert.isTrue(inRange(5));
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
assert.isTrue(inRange(0)); // inclusive
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
assert.isTrue(inRange(10)); // inclusive
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
assert.isFalse(inRange(-1));
|
|
161
161
|
|
|
162
|
-
|
|
162
|
+
assert.isFalse(inRange(15));
|
|
163
163
|
});
|
|
164
164
|
});
|
|
165
165
|
|
|
@@ -167,13 +167,13 @@ describe('Num test', () => {
|
|
|
167
167
|
test('checks uint range (lower inclusive, upper exclusive)', () => {
|
|
168
168
|
const inRange = Num.isUintInRange(0, 5);
|
|
169
169
|
|
|
170
|
-
|
|
170
|
+
assert.isTrue(inRange(2));
|
|
171
171
|
|
|
172
|
-
|
|
172
|
+
assert.isTrue(inRange(0)); // inclusive lower bound
|
|
173
173
|
|
|
174
|
-
|
|
174
|
+
assert.isFalse(inRange(5)); // exclusive upper bound
|
|
175
175
|
|
|
176
|
-
|
|
176
|
+
assert.isFalse(inRange(-1));
|
|
177
177
|
});
|
|
178
178
|
});
|
|
179
179
|
|
|
@@ -185,33 +185,33 @@ describe('Num test', () => {
|
|
|
185
185
|
expectType<typeof x, NonZeroNumber>('=');
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
|
|
188
|
+
assert.isTrue(Num.isNonZero(5));
|
|
189
189
|
|
|
190
|
-
|
|
190
|
+
assert.isTrue(Num.isNonZero(-3));
|
|
191
191
|
|
|
192
|
-
|
|
192
|
+
assert.isFalse(Num.isNonZero(0));
|
|
193
193
|
});
|
|
194
194
|
});
|
|
195
195
|
|
|
196
196
|
describe('isNonNegative', () => {
|
|
197
197
|
test('type guard for non-negative numbers', () => {
|
|
198
|
-
|
|
198
|
+
assert.isTrue(Num.isNonNegative(5));
|
|
199
199
|
|
|
200
|
-
|
|
200
|
+
assert.isTrue(Num.isNonNegative(0));
|
|
201
201
|
|
|
202
|
-
|
|
202
|
+
assert.isFalse(Num.isNonNegative(-1));
|
|
203
203
|
});
|
|
204
204
|
});
|
|
205
205
|
|
|
206
206
|
describe('isPositive', () => {
|
|
207
207
|
test('type guard for positive numbers', () => {
|
|
208
|
-
|
|
208
|
+
assert.isTrue(Num.isPositive(5));
|
|
209
209
|
|
|
210
|
-
|
|
210
|
+
assert.isTrue(Num.isPositive(0.1));
|
|
211
211
|
|
|
212
|
-
|
|
212
|
+
assert.isFalse(Num.isPositive(0));
|
|
213
213
|
|
|
214
|
-
|
|
214
|
+
assert.isFalse(Num.isPositive(-1));
|
|
215
215
|
});
|
|
216
216
|
});
|
|
217
217
|
|
|
@@ -224,8 +224,8 @@ export namespace TsDataForgeInternals {
|
|
|
224
224
|
ElementType extends Int,
|
|
225
225
|
MIN_VALUE extends number,
|
|
226
226
|
MAX_VALUE extends number,
|
|
227
|
-
ElementTypeWithSmallInt extends
|
|
228
|
-
WithSmallInt<ElementType
|
|
227
|
+
ElementTypeWithSmallInt extends WithSmallInt<ElementType> =
|
|
228
|
+
WithSmallInt<ElementType>,
|
|
229
229
|
> = Readonly<{
|
|
230
230
|
MIN_VALUE: MIN_VALUE;
|
|
231
231
|
MAX_VALUE: MAX_VALUE;
|
|
@@ -324,17 +324,17 @@ export namespace TsDataForgeInternals {
|
|
|
324
324
|
*
|
|
325
325
|
* const randomValue = intOps.random();
|
|
326
326
|
*
|
|
327
|
-
* assert(sum === 10);
|
|
327
|
+
* assert.isTrue(sum === 10);
|
|
328
328
|
*
|
|
329
|
-
* assert(difference === 2);
|
|
329
|
+
* assert.isTrue(difference === 2);
|
|
330
330
|
*
|
|
331
|
-
* assert(product === 24);
|
|
331
|
+
* assert.isTrue(product === 24);
|
|
332
332
|
*
|
|
333
|
-
* assert(quotient === 3);
|
|
333
|
+
* assert.isTrue(quotient === 3);
|
|
334
334
|
*
|
|
335
|
-
* assert(roundedClamp === 2);
|
|
335
|
+
* assert.isTrue(roundedClamp === 2);
|
|
336
336
|
*
|
|
337
|
-
* assert.
|
|
337
|
+
* assert.isTrue(Number.isSafeInteger(randomValue));
|
|
338
338
|
* ```
|
|
339
339
|
*
|
|
340
340
|
* @template ElementType - The integer branded type
|
|
@@ -552,15 +552,15 @@ export namespace TsDataForgeInternals {
|
|
|
552
552
|
*
|
|
553
553
|
* const nonZeroRandom = floatOps.randomNonZero();
|
|
554
554
|
*
|
|
555
|
-
* assert(sum === 50);
|
|
555
|
+
* assert.isTrue(sum === 50);
|
|
556
556
|
*
|
|
557
|
-
* assert(ratio === 5);
|
|
557
|
+
* assert.isTrue(ratio === 5);
|
|
558
558
|
*
|
|
559
|
-
* assert.
|
|
559
|
+
* assert.isTrue(clamped >= Number.MIN_VALUE);
|
|
560
560
|
*
|
|
561
|
-
* assert.
|
|
561
|
+
* assert.isTrue(boundedRandom >= 10 && boundedRandom <= 20);
|
|
562
562
|
*
|
|
563
|
-
* assert.
|
|
563
|
+
* assert.isTrue(nonZeroRandom > 0);
|
|
564
564
|
* ```
|
|
565
565
|
*
|
|
566
566
|
* @template ElementType - The floating-point branded type
|
package/src/object/object.mts
CHANGED
|
@@ -22,9 +22,9 @@ export namespace Obj {
|
|
|
22
22
|
*
|
|
23
23
|
* const obj3 = { name: 'Alice', age: 31 };
|
|
24
24
|
*
|
|
25
|
-
* assert.
|
|
25
|
+
* assert.isTrue(Obj.shallowEq(obj1, obj2));
|
|
26
26
|
*
|
|
27
|
-
* assert.
|
|
27
|
+
* assert.isFalse(Obj.shallowEq(obj1, obj3));
|
|
28
28
|
*
|
|
29
29
|
* // Custom equality function
|
|
30
30
|
* const obj4 = { value: 1 };
|
|
@@ -39,7 +39,7 @@ export namespace Obj {
|
|
|
39
39
|
* return Object.is(a, b);
|
|
40
40
|
* };
|
|
41
41
|
*
|
|
42
|
-
* assert.
|
|
42
|
+
* assert.isTrue(Obj.shallowEq(obj4, obj5, closeEnough));
|
|
43
43
|
* ```
|
|
44
44
|
*
|
|
45
45
|
* @param a - The first record to compare
|
|
@@ -370,6 +370,7 @@ export namespace Obj {
|
|
|
370
370
|
: TypeEq<Entries['length'], 0> extends true
|
|
371
371
|
? K
|
|
372
372
|
: ValuesOfEntriesImpl<
|
|
373
|
+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
373
374
|
K | Entries[0][1],
|
|
374
375
|
List.Tail<Entries>,
|
|
375
376
|
Decrement<RemainingNumRecursions>
|
|
@@ -4,27 +4,27 @@ import { Obj } from './object.mjs';
|
|
|
4
4
|
|
|
5
5
|
describe('shallowEq', () => {
|
|
6
6
|
test('truthy case 1', () => {
|
|
7
|
-
|
|
7
|
+
assert.isTrue(Obj.shallowEq({ x: 0 }, { x: 0 }));
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
test('truthy case 2', () => {
|
|
11
|
-
|
|
11
|
+
assert.isTrue(Obj.shallowEq({}, {}));
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
test('falsy case 1', () => {
|
|
15
|
-
|
|
15
|
+
assert.isFalse(Obj.shallowEq({ x: 0 }, { x: 0, y: 0 }));
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
test('falsy case 2', () => {
|
|
19
|
-
|
|
19
|
+
assert.isFalse(Obj.shallowEq({ x: 0, y: 0 }, { x: 0 }));
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
test('falsy case 3', () => {
|
|
23
|
-
|
|
23
|
+
assert.isFalse(Obj.shallowEq({ x: 0 }, { y: 0 }));
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
test('falsy case 4', () => {
|
|
27
|
-
|
|
27
|
+
assert.isFalse(Obj.shallowEq({ x: [] }, { y: 0 }));
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
30
|
|
|
@@ -28,7 +28,7 @@ describe(castReadonly, () => {
|
|
|
28
28
|
|
|
29
29
|
expect(readonly.value).toBe(42);
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
assert.isTrue(Object.is(readonly, original));
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
test('castReadonly should work with primitives', () => {
|
|
@@ -36,7 +36,7 @@ describe(castReadonly, () => {
|
|
|
36
36
|
|
|
37
37
|
expect(castReadonly('hello')).toBe('hello');
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
assert.isTrue(castReadonly(true));
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
test('castReadonly should work with null and undefined', () => {
|
|
@@ -75,7 +75,7 @@ describe(castDeepReadonly, () => {
|
|
|
75
75
|
|
|
76
76
|
expect(readonly.users[0]?.profile.name).toBe('Alice');
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
assert.isTrue(readonly.settings.options.debug);
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
test('should work with arrays of objects', () => {
|
|
@@ -98,7 +98,7 @@ describe(castDeepReadonly, () => {
|
|
|
98
98
|
|
|
99
99
|
expect(castDeepReadonly('hello')).toBe('hello');
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
assert.isTrue(castDeepReadonly(true));
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
test('castDeepReadonly should work with null and undefined', () => {
|
|
@@ -3,16 +3,16 @@ import { ifThen } from './if-then.mjs';
|
|
|
3
3
|
describe(ifThen, () => {
|
|
4
4
|
test('should implement logical implication truth table', () => {
|
|
5
5
|
// True antecedent, true consequent -> true
|
|
6
|
-
|
|
6
|
+
assert.isTrue(ifThen(true, true));
|
|
7
7
|
|
|
8
8
|
// True antecedent, false consequent -> false
|
|
9
|
-
|
|
9
|
+
assert.isFalse(ifThen(true, false));
|
|
10
10
|
|
|
11
11
|
// False antecedent, true consequent -> true (vacuously true)
|
|
12
|
-
|
|
12
|
+
assert.isTrue(ifThen(false, true));
|
|
13
13
|
|
|
14
14
|
// False antecedent, false consequent -> true (vacuously true)
|
|
15
|
-
|
|
15
|
+
assert.isTrue(ifThen(false, false));
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
test('should work for validation logic', () => {
|
|
@@ -22,13 +22,13 @@ describe(ifThen, () => {
|
|
|
22
22
|
return ifThen(isRequired, hasValue);
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
assert.isTrue(validateField('hello', true)); // required and has value
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
assert.isFalse(validateField('', true)); // required but no value
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
assert.isTrue(validateField('', false)); // not required, so valid
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
assert.isTrue(validateField('hello', false)); // not required, has value
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
test('should work for access control logic', () => {
|
|
@@ -39,13 +39,13 @@ describe(ifThen, () => {
|
|
|
39
39
|
// If admin, then must have permission
|
|
40
40
|
ifThen(isAdmin, hasPermission);
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
assert.isTrue(checkPermission(true, true)); // admin with permission
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
assert.isFalse(checkPermission(true, false)); // admin without permission
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
assert.isTrue(checkPermission(false, true)); // non-admin with permission
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
assert.isTrue(checkPermission(false, false)); // non-admin without permission
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
test('should work for contract validation', () => {
|
|
@@ -56,26 +56,26 @@ describe(ifThen, () => {
|
|
|
56
56
|
// If premium, then all premium features must be enabled
|
|
57
57
|
ifThen(isPremium, hasAllFeatures);
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
assert.isTrue(validateSubscription(true, true)); // premium with all features
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
assert.isFalse(validateSubscription(true, false)); // premium without all features
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
assert.isTrue(validateSubscription(false, true)); // non-premium with features
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
assert.isTrue(validateSubscription(false, false)); // non-premium without features
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
test('should work in chaining scenarios', () => {
|
|
69
69
|
const validateChain = (a: boolean, b: boolean, c: boolean): boolean =>
|
|
70
70
|
ifThen(a, b) && ifThen(b, c);
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
assert.isTrue(validateChain(true, true, true)); // valid chain
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
assert.isFalse(validateChain(true, false, true)); // breaks at first implication
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
assert.isTrue(validateChain(false, false, false)); // vacuously true chain
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
assert.isFalse(validateChain(true, true, false)); // breaks at second implication
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
test('should work with negation patterns', () => {
|
|
@@ -83,12 +83,12 @@ describe(ifThen, () => {
|
|
|
83
83
|
// "If not expired then valid" is equivalent to "expired OR valid"
|
|
84
84
|
ifThen(!isExpired, isValid);
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
assert.isTrue(checkExpiredLogic(false, true)); // not expired and valid
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
assert.isFalse(checkExpiredLogic(false, false)); // not expired but invalid
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
assert.isTrue(checkExpiredLogic(true, true)); // expired but valid (vacuous)
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
assert.isTrue(checkExpiredLogic(true, false)); // expired and invalid (vacuous)
|
|
93
93
|
});
|
|
94
94
|
});
|
package/src/others/tuple.mts
CHANGED
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
*
|
|
36
36
|
* expectType<typeof rgb, readonly [255, 128, 0]>('=');
|
|
37
37
|
*
|
|
38
|
-
* assert(rgb[0] === 255);
|
|
38
|
+
* assert.isTrue(rgb[0] === 255);
|
|
39
39
|
*
|
|
40
|
-
* assert(rgb[1] === 128);
|
|
40
|
+
* assert.isTrue(rgb[1] === 128);
|
|
41
41
|
*
|
|
42
|
-
* assert(rgb[2] === 0);
|
|
42
|
+
* assert.isTrue(rgb[2] === 0);
|
|
43
43
|
* ```
|
|
44
44
|
*
|
|
45
45
|
* @template T - A tuple type with literal types inferred from the arguments
|
package/src/promise/promise.mts
CHANGED
|
@@ -18,10 +18,10 @@ import { Result } from '../functional/index.mjs';
|
|
|
18
18
|
*
|
|
19
19
|
* const successResult = await successPromise;
|
|
20
20
|
*
|
|
21
|
-
* assert.
|
|
21
|
+
* assert.isTrue(Result.isOk(successResult));
|
|
22
22
|
*
|
|
23
23
|
* if (Result.isOk(successResult)) {
|
|
24
|
-
* assert(successResult.value === 42);
|
|
24
|
+
* assert.isTrue(successResult.value === 42);
|
|
25
25
|
* }
|
|
26
26
|
*
|
|
27
27
|
* // Create a promise that rejects with an error
|
|
@@ -33,10 +33,10 @@ import { Result } from '../functional/index.mjs';
|
|
|
33
33
|
*
|
|
34
34
|
* const errorResult = await errorPromise;
|
|
35
35
|
*
|
|
36
|
-
* assert.
|
|
36
|
+
* assert.isTrue(Result.isErr(errorResult));
|
|
37
37
|
*
|
|
38
38
|
* if (Result.isErr(errorResult)) {
|
|
39
|
-
* assert(errorResult.value === 'Something went wrong');
|
|
39
|
+
* assert.isTrue(errorResult.value === 'Something went wrong');
|
|
40
40
|
* }
|
|
41
41
|
* ```
|
|
42
42
|
*
|
|
@@ -12,11 +12,9 @@ describe(createPromise, () => {
|
|
|
12
12
|
|
|
13
13
|
const result = await resultPromise;
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
assert.isTrue(Result.isOk(result));
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
expect(result.value).toBe(42);
|
|
19
|
-
}
|
|
17
|
+
expect(result.value).toBe(42);
|
|
20
18
|
});
|
|
21
19
|
|
|
22
20
|
test('resolves to Result.err when executor rejects', async () => {
|
|
@@ -26,11 +24,9 @@ describe(createPromise, () => {
|
|
|
26
24
|
reject(rejection);
|
|
27
25
|
});
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
assert.isTrue(Result.isErr(result));
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
expect(result.value).toBe(rejection);
|
|
33
|
-
}
|
|
29
|
+
expect(result.value).toBe(rejection);
|
|
34
30
|
});
|
|
35
31
|
|
|
36
32
|
test('supports non-Error rejection reasons', async () => {
|
|
@@ -38,12 +34,10 @@ describe(createPromise, () => {
|
|
|
38
34
|
reject('failure');
|
|
39
35
|
});
|
|
40
36
|
|
|
41
|
-
|
|
37
|
+
assert.isTrue(Result.isErr(result));
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
expectType<typeof result.value, string>('=');
|
|
39
|
+
expectType<typeof result.value, string>('=');
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
}
|
|
41
|
+
expect(result.value).toBe('failure');
|
|
48
42
|
});
|
|
49
43
|
});
|