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
|
@@ -42,11 +42,11 @@ const {
|
|
|
42
42
|
* @example
|
|
43
43
|
*
|
|
44
44
|
* ```ts
|
|
45
|
-
* assert.
|
|
45
|
+
* assert.isTrue(isSafeInt(Number.MAX_SAFE_INTEGER));
|
|
46
46
|
*
|
|
47
|
-
* assert.
|
|
47
|
+
* assert.isFalse(isSafeInt(Number.MAX_SAFE_INTEGER + 0.5));
|
|
48
48
|
*
|
|
49
|
-
* assert.
|
|
49
|
+
* assert.isTrue(SafeInt.is(Number.MIN_SAFE_INTEGER));
|
|
50
50
|
* ```
|
|
51
51
|
*
|
|
52
52
|
* @param value - The value to check
|
|
@@ -66,9 +66,9 @@ export const isSafeInt = is;
|
|
|
66
66
|
* ```ts
|
|
67
67
|
* const branded = asSafeInt(123);
|
|
68
68
|
*
|
|
69
|
-
* assert(branded === 123);
|
|
69
|
+
* assert.isTrue(branded === 123);
|
|
70
70
|
*
|
|
71
|
-
* assert.
|
|
71
|
+
* assert.isTrue(SafeInt.is(branded));
|
|
72
72
|
* ```
|
|
73
73
|
*
|
|
74
74
|
* @param value - The value to cast
|
|
@@ -100,11 +100,11 @@ export const SafeInt = {
|
|
|
100
100
|
* @example
|
|
101
101
|
*
|
|
102
102
|
* ```ts
|
|
103
|
-
* assert.
|
|
103
|
+
* assert.isTrue(isSafeInt(Number.MAX_SAFE_INTEGER));
|
|
104
104
|
*
|
|
105
|
-
* assert.
|
|
105
|
+
* assert.isFalse(isSafeInt(Number.MAX_SAFE_INTEGER + 0.5));
|
|
106
106
|
*
|
|
107
|
-
* assert.
|
|
107
|
+
* assert.isTrue(SafeInt.is(Number.MIN_SAFE_INTEGER));
|
|
108
108
|
* ```
|
|
109
109
|
*
|
|
110
110
|
* @param value - The value to check
|
|
@@ -140,9 +140,9 @@ export const SafeInt = {
|
|
|
140
140
|
*
|
|
141
141
|
* const absolute = SafeInt.abs(negative);
|
|
142
142
|
*
|
|
143
|
-
* assert(absolute === 900);
|
|
143
|
+
* assert.isTrue(absolute === 900);
|
|
144
144
|
*
|
|
145
|
-
* assert.
|
|
145
|
+
* assert.isTrue(SafeInt.is(absolute));
|
|
146
146
|
* ```
|
|
147
147
|
*
|
|
148
148
|
* @param a - The safe integer value
|
|
@@ -158,7 +158,7 @@ export const SafeInt = {
|
|
|
158
158
|
* ```ts
|
|
159
159
|
* const smallest = SafeInt.min(asSafeInt(25), asSafeInt(-14), asSafeInt(99));
|
|
160
160
|
*
|
|
161
|
-
* assert(smallest === -14);
|
|
161
|
+
* assert.isTrue(smallest === -14);
|
|
162
162
|
* ```
|
|
163
163
|
*
|
|
164
164
|
* @param values - The safe integers to compare (at least one required)
|
|
@@ -174,7 +174,7 @@ export const SafeInt = {
|
|
|
174
174
|
* ```ts
|
|
175
175
|
* const largest = SafeInt.max(asSafeInt(25), asSafeInt(-14), asSafeInt(99));
|
|
176
176
|
*
|
|
177
|
-
* assert(largest === 99);
|
|
177
|
+
* assert.isTrue(largest === 99);
|
|
178
178
|
* ```
|
|
179
179
|
*
|
|
180
180
|
* @param values - The safe integers to compare (at least one required)
|
|
@@ -194,11 +194,11 @@ export const SafeInt = {
|
|
|
194
194
|
*
|
|
195
195
|
* const belowRange = SafeInt.clamp(-1e20);
|
|
196
196
|
*
|
|
197
|
-
* assert(aboveRange === Number.MAX_SAFE_INTEGER);
|
|
197
|
+
* assert.isTrue(aboveRange === Number.MAX_SAFE_INTEGER);
|
|
198
198
|
*
|
|
199
|
-
* assert(withinRange === 123);
|
|
199
|
+
* assert.isTrue(withinRange === 123);
|
|
200
200
|
*
|
|
201
|
-
* assert(belowRange === Number.MIN_SAFE_INTEGER);
|
|
201
|
+
* assert.isTrue(belowRange === Number.MIN_SAFE_INTEGER);
|
|
202
202
|
* ```
|
|
203
203
|
*
|
|
204
204
|
* @param value The number to clamp.
|
|
@@ -222,9 +222,9 @@ export const SafeInt = {
|
|
|
222
222
|
*
|
|
223
223
|
* const randomValue = SafeInt.random(min, max);
|
|
224
224
|
*
|
|
225
|
-
* assert.
|
|
225
|
+
* assert.isTrue(SafeInt.is(randomValue));
|
|
226
226
|
*
|
|
227
|
-
* assert.
|
|
227
|
+
* assert.isTrue(randomValue >= -10 && randomValue <= 10);
|
|
228
228
|
* ```
|
|
229
229
|
*
|
|
230
230
|
* @param min - The minimum value (inclusive)
|
|
@@ -245,9 +245,9 @@ export const SafeInt = {
|
|
|
245
245
|
*
|
|
246
246
|
* const power = SafeInt.pow(base, exponent);
|
|
247
247
|
*
|
|
248
|
-
* assert(power === 243);
|
|
248
|
+
* assert.isTrue(power === 243);
|
|
249
249
|
*
|
|
250
|
-
* assert.
|
|
250
|
+
* assert.isTrue(SafeInt.is(power));
|
|
251
251
|
* ```
|
|
252
252
|
*
|
|
253
253
|
* @param a The base SafeInt.
|
|
@@ -264,9 +264,9 @@ export const SafeInt = {
|
|
|
264
264
|
* ```ts
|
|
265
265
|
* const sum = SafeInt.add(asSafeInt(9), asSafeInt(4));
|
|
266
266
|
*
|
|
267
|
-
* assert(sum === 13);
|
|
267
|
+
* assert.isTrue(sum === 13);
|
|
268
268
|
*
|
|
269
|
-
* assert.
|
|
269
|
+
* assert.isTrue(SafeInt.is(sum));
|
|
270
270
|
* ```
|
|
271
271
|
*
|
|
272
272
|
* @param a The first SafeInt.
|
|
@@ -283,9 +283,9 @@ export const SafeInt = {
|
|
|
283
283
|
* ```ts
|
|
284
284
|
* const difference = SafeInt.sub(asSafeInt(9), asSafeInt(14));
|
|
285
285
|
*
|
|
286
|
-
* assert(difference === -5);
|
|
286
|
+
* assert.isTrue(difference === -5);
|
|
287
287
|
*
|
|
288
|
-
* assert.
|
|
288
|
+
* assert.isTrue(SafeInt.is(difference));
|
|
289
289
|
* ```
|
|
290
290
|
*
|
|
291
291
|
* @param a The minuend SafeInt.
|
|
@@ -302,9 +302,9 @@ export const SafeInt = {
|
|
|
302
302
|
* ```ts
|
|
303
303
|
* const product = SafeInt.mul(asSafeInt(-8), asSafeInt(7));
|
|
304
304
|
*
|
|
305
|
-
* assert(product === -56);
|
|
305
|
+
* assert.isTrue(product === -56);
|
|
306
306
|
*
|
|
307
|
-
* assert.
|
|
307
|
+
* assert.isTrue(SafeInt.is(product));
|
|
308
308
|
* ```
|
|
309
309
|
*
|
|
310
310
|
* @param a The first SafeInt.
|
|
@@ -324,9 +324,9 @@ export const SafeInt = {
|
|
|
324
324
|
* ```ts
|
|
325
325
|
* const quotient = SafeInt.div(asSafeInt(-17), asSafeInt(5));
|
|
326
326
|
*
|
|
327
|
-
* assert(quotient === -4);
|
|
327
|
+
* assert.isTrue(quotient === -4);
|
|
328
328
|
*
|
|
329
|
-
* assert.
|
|
329
|
+
* assert.isTrue(SafeInt.is(quotient));
|
|
330
330
|
* ```
|
|
331
331
|
*
|
|
332
332
|
* @param a - The dividend
|
|
@@ -69,41 +69,41 @@ describe('SafeInt test', () => {
|
|
|
69
69
|
|
|
70
70
|
describe('SafeInt.is', () => {
|
|
71
71
|
test('correctly identifies safe integers', () => {
|
|
72
|
-
|
|
72
|
+
assert.isTrue(SafeInt.is(0));
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
assert.isTrue(SafeInt.is(1));
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
assert.isTrue(SafeInt.is(-1));
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
assert.isTrue(SafeInt.is(42));
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
assert.isTrue(SafeInt.is(-42));
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
assert.isTrue(SafeInt.is(Number.MAX_SAFE_INTEGER));
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
assert.isTrue(SafeInt.is(Number.MIN_SAFE_INTEGER));
|
|
85
85
|
});
|
|
86
86
|
|
|
87
87
|
test('correctly identifies values outside safe integer range', () => {
|
|
88
|
-
|
|
88
|
+
assert.isFalse(SafeInt.is(Number.MAX_SAFE_INTEGER + 1));
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
assert.isFalse(SafeInt.is(Number.MIN_SAFE_INTEGER - 1));
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
assert.isFalse(SafeInt.is(Number.MAX_VALUE));
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
assert.isFalse(SafeInt.is(-Number.MAX_VALUE));
|
|
95
95
|
});
|
|
96
96
|
|
|
97
97
|
test('correctly identifies non-integers', () => {
|
|
98
|
-
|
|
98
|
+
assert.isFalse(SafeInt.is(Number.NaN));
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
assert.isFalse(SafeInt.is(Number.POSITIVE_INFINITY));
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
assert.isFalse(SafeInt.is(Number.NEGATIVE_INFINITY));
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
assert.isFalse(SafeInt.is(1.2));
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
assert.isFalse(SafeInt.is(-3.4));
|
|
107
107
|
});
|
|
108
108
|
});
|
|
109
109
|
|
|
@@ -202,9 +202,9 @@ describe('SafeInt test', () => {
|
|
|
202
202
|
|
|
203
203
|
expect(result).toBeLessThanOrEqual(max);
|
|
204
204
|
|
|
205
|
-
|
|
205
|
+
assert.isTrue(SafeInt.is(result));
|
|
206
206
|
|
|
207
|
-
|
|
207
|
+
assert.isTrue(Number.isInteger(result));
|
|
208
208
|
}
|
|
209
209
|
});
|
|
210
210
|
|
|
@@ -68,41 +68,41 @@ describe('SafeUint test', () => {
|
|
|
68
68
|
|
|
69
69
|
describe(isSafeUint, () => {
|
|
70
70
|
test('correctly identifies safe unsigned integers', () => {
|
|
71
|
-
|
|
71
|
+
assert.isTrue(isSafeUint(0));
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
assert.isTrue(isSafeUint(1));
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
assert.isTrue(isSafeUint(42));
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
assert.isTrue(isSafeUint(100));
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
assert.isTrue(isSafeUint(Number.MAX_SAFE_INTEGER));
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
test('correctly identifies negative numbers', () => {
|
|
83
|
-
|
|
83
|
+
assert.isFalse(isSafeUint(-1));
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
assert.isFalse(isSafeUint(-42));
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
assert.isFalse(isSafeUint(Number.MIN_SAFE_INTEGER));
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
test('correctly identifies values outside safe integer range', () => {
|
|
91
|
-
|
|
91
|
+
assert.isFalse(isSafeUint(Number.MAX_SAFE_INTEGER + 1));
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
assert.isFalse(isSafeUint(Number.MAX_VALUE));
|
|
94
94
|
});
|
|
95
95
|
|
|
96
96
|
test('correctly identifies non-integers', () => {
|
|
97
|
-
|
|
97
|
+
assert.isFalse(isSafeUint(Number.NaN));
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
assert.isFalse(isSafeUint(Number.POSITIVE_INFINITY));
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
assert.isFalse(isSafeUint(Number.NEGATIVE_INFINITY));
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
assert.isFalse(isSafeUint(1.2));
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
assert.isFalse(isSafeUint(-3.4));
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
108
|
|
|
@@ -201,9 +201,9 @@ describe('SafeUint test', () => {
|
|
|
201
201
|
|
|
202
202
|
expect(result).toBeLessThanOrEqual(max);
|
|
203
203
|
|
|
204
|
-
|
|
204
|
+
assert.isTrue(SafeUint.is(result));
|
|
205
205
|
|
|
206
|
-
|
|
206
|
+
assert.isTrue(Number.isInteger(result));
|
|
207
207
|
|
|
208
208
|
expect(result).toBeGreaterThanOrEqual(0);
|
|
209
209
|
}
|
|
@@ -35,11 +35,11 @@ const {
|
|
|
35
35
|
* @example
|
|
36
36
|
*
|
|
37
37
|
* ```ts
|
|
38
|
-
* assert.
|
|
38
|
+
* assert.isTrue(isUint(4));
|
|
39
39
|
*
|
|
40
|
-
* assert.
|
|
40
|
+
* assert.isFalse(isUint(-1));
|
|
41
41
|
*
|
|
42
|
-
* assert.
|
|
42
|
+
* assert.isTrue(Uint.is(0));
|
|
43
43
|
* ```
|
|
44
44
|
*
|
|
45
45
|
* @param value The value to check.
|
|
@@ -55,9 +55,9 @@ export const isUint = is;
|
|
|
55
55
|
* ```ts
|
|
56
56
|
* const branded = asUint(12);
|
|
57
57
|
*
|
|
58
|
-
* assert(branded === 12);
|
|
58
|
+
* assert.isTrue(branded === 12);
|
|
59
59
|
*
|
|
60
|
-
* assert.
|
|
60
|
+
* assert.isTrue(Uint.is(branded));
|
|
61
61
|
* ```
|
|
62
62
|
*
|
|
63
63
|
* @param value The value to cast.
|
|
@@ -80,11 +80,11 @@ export const Uint = {
|
|
|
80
80
|
* @example
|
|
81
81
|
*
|
|
82
82
|
* ```ts
|
|
83
|
-
* assert.
|
|
83
|
+
* assert.isTrue(isUint(4));
|
|
84
84
|
*
|
|
85
|
-
* assert.
|
|
85
|
+
* assert.isFalse(isUint(-1));
|
|
86
86
|
*
|
|
87
|
-
* assert.
|
|
87
|
+
* assert.isTrue(Uint.is(0));
|
|
88
88
|
* ```
|
|
89
89
|
*
|
|
90
90
|
* @param value The value to check.
|
|
@@ -108,7 +108,7 @@ export const Uint = {
|
|
|
108
108
|
* ```ts
|
|
109
109
|
* const smallest = Uint.min(asUint(7), asUint(3));
|
|
110
110
|
*
|
|
111
|
-
* assert(smallest === 3);
|
|
111
|
+
* assert.isTrue(smallest === 3);
|
|
112
112
|
* ```
|
|
113
113
|
*
|
|
114
114
|
* @param a The first Uint.
|
|
@@ -125,7 +125,7 @@ export const Uint = {
|
|
|
125
125
|
* ```ts
|
|
126
126
|
* const largest = Uint.max(asUint(7), asUint(3));
|
|
127
127
|
*
|
|
128
|
-
* assert(largest === 7);
|
|
128
|
+
* assert.isTrue(largest === 7);
|
|
129
129
|
* ```
|
|
130
130
|
*
|
|
131
131
|
* @param a The first Uint.
|
|
@@ -144,9 +144,9 @@ export const Uint = {
|
|
|
144
144
|
*
|
|
145
145
|
* const clampedPositive = Uint.clamp(42);
|
|
146
146
|
*
|
|
147
|
-
* assert(clampedNegative === 0);
|
|
147
|
+
* assert.isTrue(clampedNegative === 0);
|
|
148
148
|
*
|
|
149
|
-
* assert(clampedPositive === 42);
|
|
149
|
+
* assert.isTrue(clampedPositive === 42);
|
|
150
150
|
* ```
|
|
151
151
|
*
|
|
152
152
|
* @param value The number to clamp.
|
|
@@ -166,9 +166,9 @@ export const Uint = {
|
|
|
166
166
|
*
|
|
167
167
|
* const randomValue = Uint.random(min, max);
|
|
168
168
|
*
|
|
169
|
-
* assert.
|
|
169
|
+
* assert.isTrue(Uint.is(randomValue));
|
|
170
170
|
*
|
|
171
|
-
* assert.
|
|
171
|
+
* assert.isTrue(randomValue >= 0 && randomValue <= 3);
|
|
172
172
|
* ```
|
|
173
173
|
*
|
|
174
174
|
* @returns A random non-negative integer as a Uint.
|
|
@@ -187,7 +187,7 @@ export const Uint = {
|
|
|
187
187
|
*
|
|
188
188
|
* const power = Uint.pow(base, exponent);
|
|
189
189
|
*
|
|
190
|
-
* assert(power === 32);
|
|
190
|
+
* assert.isTrue(power === 32);
|
|
191
191
|
* ```
|
|
192
192
|
*
|
|
193
193
|
* @param a The base Uint.
|
|
@@ -204,7 +204,7 @@ export const Uint = {
|
|
|
204
204
|
* ```ts
|
|
205
205
|
* const sum = Uint.add(asUint(5), asUint(8));
|
|
206
206
|
*
|
|
207
|
-
* assert(sum === 13);
|
|
207
|
+
* assert.isTrue(sum === 13);
|
|
208
208
|
* ```
|
|
209
209
|
*
|
|
210
210
|
* @param a The first Uint.
|
|
@@ -221,7 +221,7 @@ export const Uint = {
|
|
|
221
221
|
* ```ts
|
|
222
222
|
* const difference = Uint.sub(asUint(5), asUint(8));
|
|
223
223
|
*
|
|
224
|
-
* assert(difference === 0);
|
|
224
|
+
* assert.isTrue(difference === 0);
|
|
225
225
|
* ```
|
|
226
226
|
*
|
|
227
227
|
* @param a The minuend Uint.
|
|
@@ -238,7 +238,7 @@ export const Uint = {
|
|
|
238
238
|
* ```ts
|
|
239
239
|
* const product = Uint.mul(asUint(7), asUint(6));
|
|
240
240
|
*
|
|
241
|
-
* assert(product === 42);
|
|
241
|
+
* assert.isTrue(product === 42);
|
|
242
242
|
* ```
|
|
243
243
|
*
|
|
244
244
|
* @param a The first Uint.
|
|
@@ -255,7 +255,7 @@ export const Uint = {
|
|
|
255
255
|
* ```ts
|
|
256
256
|
* const quotient = Uint.div(asUint(10), asUint(4));
|
|
257
257
|
*
|
|
258
|
-
* assert(quotient === 2);
|
|
258
|
+
* assert.isTrue(quotient === 2);
|
|
259
259
|
* ```
|
|
260
260
|
*
|
|
261
261
|
* @param a The dividend Uint.
|
|
@@ -60,35 +60,35 @@ describe('Uint test', () => {
|
|
|
60
60
|
|
|
61
61
|
describe(isUint, () => {
|
|
62
62
|
test('correctly identifies unsigned integers', () => {
|
|
63
|
-
|
|
63
|
+
assert.isTrue(isUint(0));
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
assert.isTrue(isUint(1));
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
assert.isTrue(isUint(42));
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
assert.isTrue(isUint(100));
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
assert.isTrue(isUint(Number.MAX_SAFE_INTEGER));
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
test('correctly identifies negative integers', () => {
|
|
75
|
-
|
|
75
|
+
assert.isFalse(isUint(-1));
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
assert.isFalse(isUint(-42));
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
assert.isFalse(isUint(Number.MIN_SAFE_INTEGER));
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
test('correctly identifies non-integers', () => {
|
|
83
|
-
|
|
83
|
+
assert.isFalse(isUint(Number.NaN));
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
assert.isFalse(isUint(Number.POSITIVE_INFINITY));
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
assert.isFalse(isUint(Number.NEGATIVE_INFINITY));
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
assert.isFalse(isUint(1.2));
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
assert.isFalse(isUint(-3.4));
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
94
|
|
|
@@ -175,9 +175,9 @@ describe('Uint test', () => {
|
|
|
175
175
|
|
|
176
176
|
expect(result).toBeLessThanOrEqual(max);
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
assert.isTrue(Uint.is(result));
|
|
179
179
|
|
|
180
|
-
|
|
180
|
+
assert.isTrue(Number.isInteger(result));
|
|
181
181
|
|
|
182
182
|
expect(result).toBeGreaterThanOrEqual(0);
|
|
183
183
|
}
|
|
@@ -65,37 +65,37 @@ describe('Uint16 test', () => {
|
|
|
65
65
|
|
|
66
66
|
describe(isUint16, () => {
|
|
67
67
|
test('correctly identifies uint16 values', () => {
|
|
68
|
-
|
|
68
|
+
assert.isTrue(isUint16(0));
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
assert.isTrue(isUint16(1));
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
assert.isTrue(isUint16(65_535));
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
assert.isTrue(isUint16(32_768));
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
test('correctly identifies values outside uint16 range', () => {
|
|
78
|
-
|
|
78
|
+
assert.isFalse(isUint16(65_536));
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
assert.isFalse(isUint16(100_000));
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
test('correctly identifies negative integers', () => {
|
|
84
|
-
|
|
84
|
+
assert.isFalse(isUint16(-1));
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
assert.isFalse(isUint16(-42));
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
test('correctly identifies non-integers', () => {
|
|
90
|
-
|
|
90
|
+
assert.isFalse(isUint16(Number.NaN));
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
assert.isFalse(isUint16(Number.POSITIVE_INFINITY));
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
assert.isFalse(isUint16(Number.NEGATIVE_INFINITY));
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
assert.isFalse(isUint16(1.2));
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
assert.isFalse(isUint16(-3.4));
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
101
|
|
|
@@ -188,9 +188,9 @@ describe('Uint16 test', () => {
|
|
|
188
188
|
|
|
189
189
|
expect(result).toBeLessThanOrEqual(max);
|
|
190
190
|
|
|
191
|
-
|
|
191
|
+
assert.isTrue(Uint16.is(result));
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
assert.isTrue(Number.isInteger(result));
|
|
194
194
|
|
|
195
195
|
expect(result).toBeGreaterThanOrEqual(0);
|
|
196
196
|
}
|
|
@@ -65,37 +65,37 @@ describe('Uint32 test', () => {
|
|
|
65
65
|
|
|
66
66
|
describe(isUint32, () => {
|
|
67
67
|
test('correctly identifies uint32 values', () => {
|
|
68
|
-
|
|
68
|
+
assert.isTrue(isUint32(0));
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
assert.isTrue(isUint32(1));
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
assert.isTrue(isUint32(4_294_967_295));
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
assert.isTrue(isUint32(2_147_483_648));
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
test('correctly identifies values outside uint32 range', () => {
|
|
78
|
-
|
|
78
|
+
assert.isFalse(isUint32(4_294_967_296));
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
assert.isFalse(isUint32(10_000_000_000));
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
test('correctly identifies negative integers', () => {
|
|
84
|
-
|
|
84
|
+
assert.isFalse(isUint32(-1));
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
assert.isFalse(isUint32(-42));
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
test('correctly identifies non-integers', () => {
|
|
90
|
-
|
|
90
|
+
assert.isFalse(isUint32(Number.NaN));
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
assert.isFalse(isUint32(Number.POSITIVE_INFINITY));
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
assert.isFalse(isUint32(Number.NEGATIVE_INFINITY));
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
assert.isFalse(isUint32(1.2));
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
assert.isFalse(isUint32(-3.4));
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
101
|
|
|
@@ -188,9 +188,9 @@ describe('Uint32 test', () => {
|
|
|
188
188
|
|
|
189
189
|
expect(result).toBeLessThanOrEqual(max);
|
|
190
190
|
|
|
191
|
-
|
|
191
|
+
assert.isTrue(Uint32.is(result));
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
assert.isTrue(Number.isInteger(result));
|
|
194
194
|
|
|
195
195
|
expect(result).toBeGreaterThanOrEqual(0);
|
|
196
196
|
}
|