ts-data-forge 1.0.0 → 1.0.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 +1 -1
- package/dist/array/array-utils.d.mts +2617 -0
- package/dist/array/array-utils.d.mts.map +1 -0
- package/dist/array/array-utils.mjs +2915 -0
- package/dist/array/array-utils.mjs.map +1 -0
- package/dist/array/index.d.mts +3 -0
- package/dist/array/index.d.mts.map +1 -0
- package/dist/array/index.mjs +3 -0
- package/dist/array/index.mjs.map +1 -0
- package/dist/array/tuple-utils.d.mts +421 -0
- package/dist/array/tuple-utils.d.mts.map +1 -0
- package/dist/array/tuple-utils.mjs +391 -0
- package/dist/array/tuple-utils.mjs.map +1 -0
- package/dist/collections/imap-mapped.d.mts +445 -0
- package/dist/collections/imap-mapped.d.mts.map +1 -0
- package/dist/collections/imap-mapped.mjs +424 -0
- package/dist/collections/imap-mapped.mjs.map +1 -0
- package/dist/collections/imap.d.mts +359 -0
- package/dist/collections/imap.d.mts.map +1 -0
- package/dist/collections/imap.mjs +338 -0
- package/dist/collections/imap.mjs.map +1 -0
- package/dist/collections/index.d.mts +7 -0
- package/dist/collections/index.d.mts.map +1 -0
- package/dist/collections/index.mjs +7 -0
- package/dist/collections/index.mjs.map +1 -0
- package/dist/collections/iset-mapped.d.mts +576 -0
- package/dist/collections/iset-mapped.d.mts.map +1 -0
- package/dist/collections/iset-mapped.mjs +522 -0
- package/dist/collections/iset-mapped.mjs.map +1 -0
- package/dist/collections/iset.d.mts +426 -0
- package/dist/collections/iset.d.mts.map +1 -0
- package/dist/collections/iset.mjs +437 -0
- package/dist/collections/iset.mjs.map +1 -0
- package/dist/collections/queue.d.mts +190 -0
- package/dist/collections/queue.d.mts.map +1 -0
- package/dist/collections/queue.mjs +317 -0
- package/dist/collections/queue.mjs.map +1 -0
- package/dist/collections/stack.d.mts +210 -0
- package/dist/collections/stack.d.mts.map +1 -0
- package/dist/collections/stack.mjs +353 -0
- package/dist/collections/stack.mjs.map +1 -0
- package/dist/expect-type.d.mts +199 -0
- package/dist/expect-type.d.mts.map +1 -0
- package/dist/expect-type.mjs +201 -0
- package/dist/expect-type.mjs.map +1 -0
- package/dist/functional/index.d.mts +5 -0
- package/dist/functional/index.d.mts.map +1 -0
- package/dist/functional/index.mjs +5 -0
- package/dist/functional/index.mjs.map +1 -0
- package/dist/functional/match.d.mts +215 -0
- package/dist/functional/match.d.mts.map +1 -0
- package/dist/functional/match.mjs +139 -0
- package/dist/functional/match.mjs.map +1 -0
- package/dist/functional/optional.d.mts +517 -0
- package/dist/functional/optional.d.mts.map +1 -0
- package/dist/functional/optional.mjs +532 -0
- package/dist/functional/optional.mjs.map +1 -0
- package/dist/functional/pipe.d.mts +185 -0
- package/dist/functional/pipe.d.mts.map +1 -0
- package/dist/functional/pipe.mjs +129 -0
- package/dist/functional/pipe.mjs.map +1 -0
- package/dist/functional/result.d.mts +796 -0
- package/dist/functional/result.d.mts.map +1 -0
- package/dist/functional/result.mjs +844 -0
- package/dist/functional/result.mjs.map +1 -0
- package/dist/globals.d.mts +38 -0
- package/dist/guard/has-key.d.mts +100 -0
- package/dist/guard/has-key.d.mts.map +1 -0
- package/dist/guard/has-key.mjs +94 -0
- package/dist/guard/has-key.mjs.map +1 -0
- package/dist/guard/index.d.mts +8 -0
- package/dist/guard/index.d.mts.map +1 -0
- package/dist/guard/index.mjs +8 -0
- package/dist/guard/index.mjs.map +1 -0
- package/dist/guard/is-non-empty-string.d.mts +106 -0
- package/dist/guard/is-non-empty-string.d.mts.map +1 -0
- package/dist/guard/is-non-empty-string.mjs +108 -0
- package/dist/guard/is-non-empty-string.mjs.map +1 -0
- package/dist/guard/is-non-null-object.d.mts +105 -0
- package/dist/guard/is-non-null-object.d.mts.map +1 -0
- package/dist/guard/is-non-null-object.mjs +108 -0
- package/dist/guard/is-non-null-object.mjs.map +1 -0
- package/dist/guard/is-primitive.d.mts +146 -0
- package/dist/guard/is-primitive.d.mts.map +1 -0
- package/dist/guard/is-primitive.mjs +161 -0
- package/dist/guard/is-primitive.mjs.map +1 -0
- package/dist/guard/is-record.d.mts +151 -0
- package/dist/guard/is-record.d.mts.map +1 -0
- package/dist/guard/is-record.mjs +155 -0
- package/dist/guard/is-record.mjs.map +1 -0
- package/dist/guard/is-type.d.mts +430 -0
- package/dist/guard/is-type.d.mts.map +1 -0
- package/dist/guard/is-type.mjs +432 -0
- package/dist/guard/is-type.mjs.map +1 -0
- package/dist/guard/key-is-in.d.mts +158 -0
- package/dist/guard/key-is-in.d.mts.map +1 -0
- package/dist/guard/key-is-in.mjs +160 -0
- package/dist/guard/key-is-in.mjs.map +1 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +61 -0
- package/dist/index.mjs.map +1 -0
- package/dist/iterator/index.d.mts +2 -0
- package/dist/iterator/index.d.mts.map +1 -0
- package/dist/iterator/index.mjs +2 -0
- package/dist/iterator/index.mjs.map +1 -0
- package/dist/iterator/range.d.mts +97 -0
- package/dist/iterator/range.d.mts.map +1 -0
- package/dist/iterator/range.mjs +130 -0
- package/dist/iterator/range.mjs.map +1 -0
- package/dist/json/index.d.mts +2 -0
- package/dist/json/index.d.mts.map +1 -0
- package/dist/json/index.mjs +2 -0
- package/dist/json/index.mjs.map +1 -0
- package/dist/json/json.d.mts +597 -0
- package/dist/json/json.d.mts.map +1 -0
- package/dist/json/json.mjs +687 -0
- package/dist/json/json.mjs.map +1 -0
- package/dist/number/branded-types/finite-number.d.mts +291 -0
- package/dist/number/branded-types/finite-number.d.mts.map +1 -0
- package/dist/number/branded-types/finite-number.mjs +296 -0
- package/dist/number/branded-types/finite-number.mjs.map +1 -0
- package/dist/number/branded-types/index.d.mts +27 -0
- package/dist/number/branded-types/index.d.mts.map +1 -0
- package/dist/number/branded-types/index.mjs +27 -0
- package/dist/number/branded-types/index.mjs.map +1 -0
- package/dist/number/branded-types/int.d.mts +242 -0
- package/dist/number/branded-types/int.d.mts.map +1 -0
- package/dist/number/branded-types/int.mjs +239 -0
- package/dist/number/branded-types/int.mjs.map +1 -0
- package/dist/number/branded-types/int16.d.mts +162 -0
- package/dist/number/branded-types/int16.d.mts.map +1 -0
- package/dist/number/branded-types/int16.mjs +141 -0
- package/dist/number/branded-types/int16.mjs.map +1 -0
- package/dist/number/branded-types/int32.d.mts +155 -0
- package/dist/number/branded-types/int32.d.mts.map +1 -0
- package/dist/number/branded-types/int32.mjs +142 -0
- package/dist/number/branded-types/int32.mjs.map +1 -0
- package/dist/number/branded-types/non-negative-finite-number.d.mts +165 -0
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -0
- package/dist/number/branded-types/non-negative-finite-number.mjs +160 -0
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -0
- package/dist/number/branded-types/non-negative-int16.d.mts +160 -0
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -0
- package/dist/number/branded-types/non-negative-int16.mjs +138 -0
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -0
- package/dist/number/branded-types/non-negative-int32.d.mts +156 -0
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -0
- package/dist/number/branded-types/non-negative-int32.mjs +138 -0
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-finite-number.d.mts +154 -0
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-finite-number.mjs +160 -0
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-int.d.mts +131 -0
- package/dist/number/branded-types/non-zero-int.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-int.mjs +128 -0
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-int16.d.mts +166 -0
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-int16.mjs +145 -0
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-int32.d.mts +158 -0
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-int32.mjs +145 -0
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-safe-int.d.mts +148 -0
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-safe-int.mjs +145 -0
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-uint16.d.mts +160 -0
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-uint16.mjs +140 -0
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-uint32.d.mts +156 -0
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-uint32.mjs +140 -0
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -0
- package/dist/number/branded-types/positive-finite-number.d.mts +171 -0
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -0
- package/dist/number/branded-types/positive-finite-number.mjs +165 -0
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -0
- package/dist/number/branded-types/positive-int.d.mts +270 -0
- package/dist/number/branded-types/positive-int.d.mts.map +1 -0
- package/dist/number/branded-types/positive-int.mjs +257 -0
- package/dist/number/branded-types/positive-int.mjs.map +1 -0
- package/dist/number/branded-types/positive-int16.d.mts +162 -0
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -0
- package/dist/number/branded-types/positive-int16.mjs +139 -0
- package/dist/number/branded-types/positive-int16.mjs.map +1 -0
- package/dist/number/branded-types/positive-int32.d.mts +158 -0
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -0
- package/dist/number/branded-types/positive-int32.mjs +139 -0
- package/dist/number/branded-types/positive-int32.mjs.map +1 -0
- package/dist/number/branded-types/positive-safe-int.d.mts +152 -0
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -0
- package/dist/number/branded-types/positive-safe-int.mjs +138 -0
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -0
- package/dist/number/branded-types/positive-uint16.d.mts +160 -0
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -0
- package/dist/number/branded-types/positive-uint16.mjs +139 -0
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -0
- package/dist/number/branded-types/positive-uint32.d.mts +156 -0
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -0
- package/dist/number/branded-types/positive-uint32.mjs +139 -0
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -0
- package/dist/number/branded-types/safe-int.d.mts +243 -0
- package/dist/number/branded-types/safe-int.d.mts.map +1 -0
- package/dist/number/branded-types/safe-int.mjs +240 -0
- package/dist/number/branded-types/safe-int.mjs.map +1 -0
- package/dist/number/branded-types/safe-uint.d.mts +151 -0
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -0
- package/dist/number/branded-types/safe-uint.mjs +138 -0
- package/dist/number/branded-types/safe-uint.mjs.map +1 -0
- package/dist/number/branded-types/uint.d.mts +144 -0
- package/dist/number/branded-types/uint.d.mts.map +1 -0
- package/dist/number/branded-types/uint.mjs +132 -0
- package/dist/number/branded-types/uint.mjs.map +1 -0
- package/dist/number/branded-types/uint16.d.mts +157 -0
- package/dist/number/branded-types/uint16.d.mts.map +1 -0
- package/dist/number/branded-types/uint16.mjs +137 -0
- package/dist/number/branded-types/uint16.mjs.map +1 -0
- package/dist/number/branded-types/uint32.d.mts +185 -0
- package/dist/number/branded-types/uint32.d.mts.map +1 -0
- package/dist/number/branded-types/uint32.mjs +169 -0
- package/dist/number/branded-types/uint32.mjs.map +1 -0
- package/dist/number/enum/index.d.mts +3 -0
- package/dist/number/enum/index.d.mts.map +1 -0
- package/dist/number/enum/index.mjs +3 -0
- package/dist/number/enum/index.mjs.map +1 -0
- package/dist/number/enum/int8.d.mts +202 -0
- package/dist/number/enum/int8.d.mts.map +1 -0
- package/dist/number/enum/int8.mjs +296 -0
- package/dist/number/enum/int8.mjs.map +1 -0
- package/dist/number/enum/uint8.d.mts +128 -0
- package/dist/number/enum/uint8.d.mts.map +1 -0
- package/dist/number/enum/uint8.mjs +251 -0
- package/dist/number/enum/uint8.mjs.map +1 -0
- package/dist/number/index.d.mts +5 -0
- package/dist/number/index.d.mts.map +1 -0
- package/dist/number/index.mjs +31 -0
- package/dist/number/index.mjs.map +1 -0
- package/dist/number/num.d.mts +515 -0
- package/dist/number/num.d.mts.map +1 -0
- package/dist/number/num.mjs +513 -0
- package/dist/number/num.mjs.map +1 -0
- package/dist/number/refined-number-utils.d.mts +191 -0
- package/dist/number/refined-number-utils.d.mts.map +1 -0
- package/dist/number/refined-number-utils.mjs +179 -0
- package/dist/number/refined-number-utils.mjs.map +1 -0
- package/dist/object/index.d.mts +2 -0
- package/dist/object/index.d.mts.map +1 -0
- package/dist/object/index.mjs +2 -0
- package/dist/object/index.mjs.map +1 -0
- package/dist/object/object.d.mts +296 -0
- package/dist/object/object.d.mts.map +1 -0
- package/dist/object/object.mjs +295 -0
- package/dist/object/object.mjs.map +1 -0
- package/dist/others/cast-mutable.d.mts +110 -0
- package/dist/others/cast-mutable.d.mts.map +1 -0
- package/dist/others/cast-mutable.mjs +114 -0
- package/dist/others/cast-mutable.mjs.map +1 -0
- package/dist/others/cast-readonly.d.mts +189 -0
- package/dist/others/cast-readonly.d.mts.map +1 -0
- package/dist/others/cast-readonly.mjs +193 -0
- package/dist/others/cast-readonly.mjs.map +1 -0
- package/dist/others/if-then.d.mts +98 -0
- package/dist/others/if-then.d.mts.map +1 -0
- package/dist/others/if-then.mjs +100 -0
- package/dist/others/if-then.mjs.map +1 -0
- package/dist/others/index.d.mts +8 -0
- package/dist/others/index.d.mts.map +1 -0
- package/dist/others/index.mjs +8 -0
- package/dist/others/index.mjs.map +1 -0
- package/dist/others/map-nullable.d.mts +151 -0
- package/dist/others/map-nullable.d.mts.map +1 -0
- package/dist/others/map-nullable.mjs +159 -0
- package/dist/others/map-nullable.mjs.map +1 -0
- package/dist/others/memoize-function.d.mts +173 -0
- package/dist/others/memoize-function.d.mts.map +1 -0
- package/dist/others/memoize-function.mjs +189 -0
- package/dist/others/memoize-function.mjs.map +1 -0
- package/dist/others/tuple.d.mts +159 -0
- package/dist/others/tuple.d.mts.map +1 -0
- package/dist/others/tuple.mjs +161 -0
- package/dist/others/tuple.mjs.map +1 -0
- package/dist/others/unknown-to-string.d.mts +180 -0
- package/dist/others/unknown-to-string.d.mts.map +1 -0
- package/dist/others/unknown-to-string.mjs +211 -0
- package/dist/others/unknown-to-string.mjs.map +1 -0
- package/dist/tsconfig.json +1 -0
- package/package.json +16 -14
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { TsVerifiedInternals } from '../refined-number-utils.mjs';
|
|
2
|
+
|
|
3
|
+
const typeNameInMessage = 'a non-negative safe integer';
|
|
4
|
+
const { MIN_VALUE, MAX_VALUE, min: min_, max: max_, pow, add, sub, mul, div, random, is, castType, clamp, } = TsVerifiedInternals.RefinedNumberUtils.operatorsForInteger({
|
|
5
|
+
integerOrSafeInteger: 'SafeInteger',
|
|
6
|
+
MIN_VALUE: 0,
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
8
|
+
MAX_VALUE: Number.MAX_SAFE_INTEGER,
|
|
9
|
+
typeNameInMessage,
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Checks if a number is a SafeUint.
|
|
13
|
+
* @param value The value to check.
|
|
14
|
+
* @returns `true` if the value is a SafeUint, `false` otherwise.
|
|
15
|
+
*/
|
|
16
|
+
const isSafeUint = is;
|
|
17
|
+
/**
|
|
18
|
+
* Casts a number to a SafeUint type.
|
|
19
|
+
* @param value The value to cast.
|
|
20
|
+
* @returns The value as a SafeUint type.
|
|
21
|
+
* @throws {TypeError} If the value is not a non-negative safe integer.
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const x = asSafeUint(5); // SafeUint
|
|
25
|
+
* const y = asSafeUint(0); // SafeUint
|
|
26
|
+
* // asSafeUint(-1); // throws TypeError
|
|
27
|
+
* // asSafeUint(1.5); // throws TypeError
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const asSafeUint = castType;
|
|
31
|
+
/**
|
|
32
|
+
* Namespace providing type-safe arithmetic operations for safe unsigned integers.
|
|
33
|
+
*
|
|
34
|
+
* All operations automatically clamp results to the safe unsigned integer range [0, MAX_SAFE_INTEGER].
|
|
35
|
+
* This ensures that all arithmetic maintains both the non-negative constraint and IEEE 754 precision guarantees,
|
|
36
|
+
* preventing precision loss while ensuring results are never negative.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const a = asSafeUint(9007199254740000); // Near MAX_SAFE_INTEGER
|
|
41
|
+
* const b = asSafeUint(1000);
|
|
42
|
+
*
|
|
43
|
+
* // Arithmetic operations with safe unsigned range clamping
|
|
44
|
+
* const sum = SafeUint.add(a, b); // SafeUint (clamped to MAX_SAFE_INTEGER)
|
|
45
|
+
* const diff = SafeUint.sub(b, a); // SafeUint (0 - clamped to MIN_VALUE)
|
|
46
|
+
* const product = SafeUint.mul(a, b); // SafeUint (clamped to MAX_SAFE_INTEGER)
|
|
47
|
+
*
|
|
48
|
+
* // Range operations
|
|
49
|
+
* const clamped = SafeUint.clamp(-100); // SafeUint (0)
|
|
50
|
+
* const minimum = SafeUint.min(a, b); // SafeUint (1000)
|
|
51
|
+
* const maximum = SafeUint.max(a, b); // SafeUint (a)
|
|
52
|
+
*
|
|
53
|
+
* // Utility operations
|
|
54
|
+
* const random = SafeUint.random(); // SafeUint (random safe unsigned integer)
|
|
55
|
+
* const power = SafeUint.pow(asSafeUint(2), asSafeUint(20)); // SafeUint (1048576)
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
const SafeUint = {
|
|
59
|
+
/**
|
|
60
|
+
* Type guard to check if a value is a SafeUint.
|
|
61
|
+
* @param value The value to check.
|
|
62
|
+
* @returns `true` if the value is a non-negative safe integer, `false` otherwise.
|
|
63
|
+
*/
|
|
64
|
+
is,
|
|
65
|
+
/**
|
|
66
|
+
* The minimum value for a safe unsigned integer.
|
|
67
|
+
* @readonly
|
|
68
|
+
*/
|
|
69
|
+
MIN_VALUE,
|
|
70
|
+
/**
|
|
71
|
+
* The maximum safe integer value (2^53 - 1).
|
|
72
|
+
* @readonly
|
|
73
|
+
*/
|
|
74
|
+
MAX_VALUE,
|
|
75
|
+
/**
|
|
76
|
+
* Returns the smaller of two SafeUint values.
|
|
77
|
+
* @param a The first SafeUint.
|
|
78
|
+
* @param b The second SafeUint.
|
|
79
|
+
* @returns The minimum value as a SafeUint.
|
|
80
|
+
*/
|
|
81
|
+
min: min_,
|
|
82
|
+
/**
|
|
83
|
+
* Returns the larger of two SafeUint values.
|
|
84
|
+
* @param a The first SafeUint.
|
|
85
|
+
* @param b The second SafeUint.
|
|
86
|
+
* @returns The maximum value as a SafeUint.
|
|
87
|
+
*/
|
|
88
|
+
max: max_,
|
|
89
|
+
/**
|
|
90
|
+
* Clamps a number to the safe unsigned integer range.
|
|
91
|
+
* @param value The number to clamp.
|
|
92
|
+
* @returns The value clamped to [0, MAX_SAFE_INTEGER] as a SafeUint.
|
|
93
|
+
*/
|
|
94
|
+
clamp,
|
|
95
|
+
/**
|
|
96
|
+
* Generates a random SafeUint value within the valid range.
|
|
97
|
+
* @returns A random SafeUint between 0 and MAX_SAFE_INTEGER.
|
|
98
|
+
*/
|
|
99
|
+
random,
|
|
100
|
+
/**
|
|
101
|
+
* Raises a SafeUint to the power of another SafeUint.
|
|
102
|
+
* @param a The base SafeUint.
|
|
103
|
+
* @param b The exponent SafeUint.
|
|
104
|
+
* @returns `a ** b` clamped to [0, MAX_SAFE_INTEGER] as a SafeUint.
|
|
105
|
+
*/
|
|
106
|
+
pow,
|
|
107
|
+
/**
|
|
108
|
+
* Adds two SafeUint values.
|
|
109
|
+
* @param a The first SafeUint.
|
|
110
|
+
* @param b The second SafeUint.
|
|
111
|
+
* @returns `a + b` clamped to [0, MAX_SAFE_INTEGER] as a SafeUint.
|
|
112
|
+
*/
|
|
113
|
+
add,
|
|
114
|
+
/**
|
|
115
|
+
* Subtracts one SafeUint from another.
|
|
116
|
+
* @param a The minuend SafeUint.
|
|
117
|
+
* @param b The subtrahend SafeUint.
|
|
118
|
+
* @returns `a - b` clamped to [0, MAX_SAFE_INTEGER] as a SafeUint (minimum 0).
|
|
119
|
+
*/
|
|
120
|
+
sub,
|
|
121
|
+
/**
|
|
122
|
+
* Multiplies two SafeUint values.
|
|
123
|
+
* @param a The first SafeUint.
|
|
124
|
+
* @param b The second SafeUint.
|
|
125
|
+
* @returns `a * b` clamped to [0, MAX_SAFE_INTEGER] as a SafeUint.
|
|
126
|
+
*/
|
|
127
|
+
mul,
|
|
128
|
+
/**
|
|
129
|
+
* Divides one SafeUint by another using floor division.
|
|
130
|
+
* @param a The dividend SafeUint.
|
|
131
|
+
* @param b The divisor SafeUint.
|
|
132
|
+
* @returns `⌊a / b⌋` clamped to [0, MAX_SAFE_INTEGER] as a SafeUint.
|
|
133
|
+
*/
|
|
134
|
+
div,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export { SafeUint, asSafeUint, isSafeUint };
|
|
138
|
+
//# sourceMappingURL=safe-uint.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-uint.mjs","sources":["../../../src/number/branded-types/safe-uint.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA,MAAM,iBAAiB,GAAG,6BAA6B;AAEvD,MAAM,EACJ,SAAS,EACT,SAAS,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,MAAM,EACN,EAAE,EACF,QAAQ,EACR,KAAK,GACN,GAAG,mBAAmB,CAAC,kBAAkB,CAAC,mBAAmB,CAI5D;AACA,IAAA,oBAAoB,EAAE,aAAa;AACnC,IAAA,SAAS,EAAE,CAAC;;IAEZ,SAAS,EAAE,MAAM,CAAC,gBAA4B;IAC9C,iBAAiB;AACT,CAAA,CAAC;AAEX;;;;AAIG;AACI,MAAM,UAAU,GAAG;AAE1B;;;;;;;;;;;;AAYG;AACI,MAAM,UAAU,GAAG;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACI,MAAM,QAAQ,GAAG;AACtB;;;;AAIG;IACH,EAAE;AAEF;;;AAGG;IACH,SAAS;AAET;;;AAGG;IACH,SAAS;AAET;;;;;AAKG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;;AAKG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;AAIG;IACH,KAAK;AAEL;;;AAGG;IACH,MAAM;AAEN;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;;;;;"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a number is a Uint.
|
|
3
|
+
* @param value The value to check.
|
|
4
|
+
* @returns `true` if the value is a Uint, `false` otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isUint: (a: number) => a is NonNegativeInt;
|
|
7
|
+
/**
|
|
8
|
+
* Casts a number to a Uint type.
|
|
9
|
+
* @param value The value to cast.
|
|
10
|
+
* @returns The value as a Uint type.
|
|
11
|
+
* @throws {TypeError} If the value is not a non-negative integer.
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const x = asUint(5); // Uint
|
|
15
|
+
* const y = asUint(0); // Uint
|
|
16
|
+
* // asUint(-1); // throws TypeError
|
|
17
|
+
* // asUint(1.5); // throws TypeError
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const asUint: <N extends number>(x: N) => number & {
|
|
21
|
+
readonly NaNValue: false;
|
|
22
|
+
readonly "> -2^16": true;
|
|
23
|
+
readonly "> -2^32": true;
|
|
24
|
+
readonly ">= -2^15": true;
|
|
25
|
+
readonly ">= -2^31": true;
|
|
26
|
+
readonly ">=0": true;
|
|
27
|
+
readonly Finite: true;
|
|
28
|
+
readonly Int: true;
|
|
29
|
+
} & Readonly<{
|
|
30
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
31
|
+
}> & N;
|
|
32
|
+
/**
|
|
33
|
+
* Namespace providing type-safe arithmetic operations for unsigned integers.
|
|
34
|
+
*
|
|
35
|
+
* All operations maintain the non-negative constraint by clamping negative results to 0.
|
|
36
|
+
* This ensures that all arithmetic preserves the unsigned integer property.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const a = asUint(100);
|
|
41
|
+
* const b = asUint(150);
|
|
42
|
+
*
|
|
43
|
+
* // Arithmetic operations with non-negative clamping
|
|
44
|
+
* const sum = Uint.add(a, b); // Uint (250)
|
|
45
|
+
* const diff = Uint.sub(a, b); // Uint (0 - clamped to MIN_VALUE)
|
|
46
|
+
* const product = Uint.mul(a, b); // Uint (15000)
|
|
47
|
+
* const quotient = Uint.div(b, a); // Uint (1)
|
|
48
|
+
*
|
|
49
|
+
* // Range operations
|
|
50
|
+
* const clamped = Uint.clamp(-50); // Uint (0)
|
|
51
|
+
* const minimum = Uint.min(a, b); // Uint (100)
|
|
52
|
+
* const maximum = Uint.max(a, b); // Uint (150)
|
|
53
|
+
*
|
|
54
|
+
* // Utility operations
|
|
55
|
+
* const random = Uint.random(); // Uint (random non-negative integer)
|
|
56
|
+
* const power = Uint.pow(asUint(2), asUint(8)); // Uint (256)
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare const Uint: {
|
|
60
|
+
/**
|
|
61
|
+
* Type guard to check if a value is a Uint.
|
|
62
|
+
* @param value The value to check.
|
|
63
|
+
* @returns `true` if the value is a non-negative integer, `false` otherwise.
|
|
64
|
+
*/
|
|
65
|
+
readonly is: (a: number) => a is NonNegativeInt;
|
|
66
|
+
/**
|
|
67
|
+
* The minimum value for an unsigned integer.
|
|
68
|
+
* @readonly
|
|
69
|
+
*/
|
|
70
|
+
readonly MIN_VALUE: 0;
|
|
71
|
+
/**
|
|
72
|
+
* Returns the smaller of two Uint values.
|
|
73
|
+
* @param a The first Uint.
|
|
74
|
+
* @param b The second Uint.
|
|
75
|
+
* @returns The minimum value as a Uint.
|
|
76
|
+
*/
|
|
77
|
+
readonly min: (...values: readonly WithSmallInt<NonNegativeInt, 40>[]) => NonNegativeInt;
|
|
78
|
+
/**
|
|
79
|
+
* Returns the larger of two Uint values.
|
|
80
|
+
* @param a The first Uint.
|
|
81
|
+
* @param b The second Uint.
|
|
82
|
+
* @returns The maximum value as a Uint.
|
|
83
|
+
*/
|
|
84
|
+
readonly max: (...values: readonly WithSmallInt<NonNegativeInt, 40>[]) => NonNegativeInt;
|
|
85
|
+
/**
|
|
86
|
+
* Clamps a number to the Uint range (non-negative).
|
|
87
|
+
* @param value The number to clamp.
|
|
88
|
+
* @returns The value clamped to [0, +∞) as a Uint.
|
|
89
|
+
*/
|
|
90
|
+
readonly clamp: (x: number) => NonNegativeInt;
|
|
91
|
+
/**
|
|
92
|
+
* Generates a random Uint value.
|
|
93
|
+
* @returns A random non-negative integer as a Uint.
|
|
94
|
+
*/
|
|
95
|
+
readonly random: (min: WithSmallInt<NonNegativeInt, 40>, max: WithSmallInt<NonNegativeInt, 40>) => NonNegativeInt;
|
|
96
|
+
/**
|
|
97
|
+
* Raises a Uint to the power of another Uint.
|
|
98
|
+
* @param a The base Uint.
|
|
99
|
+
* @param b The exponent Uint.
|
|
100
|
+
* @returns `a ** b` clamped to [0, +∞) as a Uint.
|
|
101
|
+
*/
|
|
102
|
+
readonly pow: (x: WithSmallInt<NonNegativeInt, 40>, y: WithSmallInt<NonNegativeInt, 40>) => NonNegativeInt;
|
|
103
|
+
/**
|
|
104
|
+
* Adds two Uint values.
|
|
105
|
+
* @param a The first Uint.
|
|
106
|
+
* @param b The second Uint.
|
|
107
|
+
* @returns `a + b` clamped to [0, +∞) as a Uint.
|
|
108
|
+
*/
|
|
109
|
+
readonly add: (x: WithSmallInt<NonNegativeInt, 40>, y: WithSmallInt<NonNegativeInt, 40>) => NonNegativeInt;
|
|
110
|
+
/**
|
|
111
|
+
* Subtracts one Uint from another.
|
|
112
|
+
* @param a The minuend Uint.
|
|
113
|
+
* @param b The subtrahend Uint.
|
|
114
|
+
* @returns `a - b` clamped to [0, +∞) as a Uint (minimum 0).
|
|
115
|
+
*/
|
|
116
|
+
readonly sub: (x: WithSmallInt<NonNegativeInt, 40>, y: WithSmallInt<NonNegativeInt, 40>) => NonNegativeInt;
|
|
117
|
+
/**
|
|
118
|
+
* Multiplies two Uint values.
|
|
119
|
+
* @param a The first Uint.
|
|
120
|
+
* @param b The second Uint.
|
|
121
|
+
* @returns `a * b` clamped to [0, +∞) as a Uint.
|
|
122
|
+
*/
|
|
123
|
+
readonly mul: (x: WithSmallInt<NonNegativeInt, 40>, y: WithSmallInt<NonNegativeInt, 40>) => NonNegativeInt;
|
|
124
|
+
/**
|
|
125
|
+
* Divides one Uint by another using floor division.
|
|
126
|
+
* @param a The dividend Uint.
|
|
127
|
+
* @param b The divisor Uint.
|
|
128
|
+
* @returns `⌊a / b⌋` clamped to [0, +∞) as a Uint.
|
|
129
|
+
*/
|
|
130
|
+
readonly div: (x: WithSmallInt<NonNegativeInt, 40>, y: 1 | 2 | 3 | 32 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 10 | 24 | 14 | 34 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | NormalizeBrandUnion<number & {
|
|
131
|
+
readonly NaNValue: false;
|
|
132
|
+
readonly "!=0": true;
|
|
133
|
+
readonly "> -2^16": true;
|
|
134
|
+
readonly "> -2^32": true;
|
|
135
|
+
readonly ">= -2^15": true;
|
|
136
|
+
readonly ">= -2^31": true;
|
|
137
|
+
readonly ">=0": true;
|
|
138
|
+
readonly Finite: true;
|
|
139
|
+
readonly Int: true;
|
|
140
|
+
} & Readonly<{
|
|
141
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
142
|
+
}>>) => NonNegativeInt;
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=uint.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uint.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/uint.mts"],"names":[],"mappings":"AA+BA;;;;GAIG;AACH,eAAO,MAAM,MAAM,oCAAK,CAAC;AAEzB;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;MAAW,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,IAAI;IACf;;;;OAIG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;OAIG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;;;;;;;;;;;;;CAEK,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { TsVerifiedInternals } from '../refined-number-utils.mjs';
|
|
2
|
+
|
|
3
|
+
const typeNameInMessage = 'a non-negative integer';
|
|
4
|
+
const { MIN_VALUE, min: min_, max: max_, pow, add, sub, mul, div, random, is, castType, clamp, } = TsVerifiedInternals.RefinedNumberUtils.operatorsForInteger({
|
|
5
|
+
integerOrSafeInteger: 'Integer',
|
|
6
|
+
MIN_VALUE: 0,
|
|
7
|
+
MAX_VALUE: undefined,
|
|
8
|
+
typeNameInMessage,
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a number is a Uint.
|
|
12
|
+
* @param value The value to check.
|
|
13
|
+
* @returns `true` if the value is a Uint, `false` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
const isUint = is;
|
|
16
|
+
/**
|
|
17
|
+
* Casts a number to a Uint type.
|
|
18
|
+
* @param value The value to cast.
|
|
19
|
+
* @returns The value as a Uint type.
|
|
20
|
+
* @throws {TypeError} If the value is not a non-negative integer.
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const x = asUint(5); // Uint
|
|
24
|
+
* const y = asUint(0); // Uint
|
|
25
|
+
* // asUint(-1); // throws TypeError
|
|
26
|
+
* // asUint(1.5); // throws TypeError
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const asUint = castType;
|
|
30
|
+
/**
|
|
31
|
+
* Namespace providing type-safe arithmetic operations for unsigned integers.
|
|
32
|
+
*
|
|
33
|
+
* All operations maintain the non-negative constraint by clamping negative results to 0.
|
|
34
|
+
* This ensures that all arithmetic preserves the unsigned integer property.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const a = asUint(100);
|
|
39
|
+
* const b = asUint(150);
|
|
40
|
+
*
|
|
41
|
+
* // Arithmetic operations with non-negative clamping
|
|
42
|
+
* const sum = Uint.add(a, b); // Uint (250)
|
|
43
|
+
* const diff = Uint.sub(a, b); // Uint (0 - clamped to MIN_VALUE)
|
|
44
|
+
* const product = Uint.mul(a, b); // Uint (15000)
|
|
45
|
+
* const quotient = Uint.div(b, a); // Uint (1)
|
|
46
|
+
*
|
|
47
|
+
* // Range operations
|
|
48
|
+
* const clamped = Uint.clamp(-50); // Uint (0)
|
|
49
|
+
* const minimum = Uint.min(a, b); // Uint (100)
|
|
50
|
+
* const maximum = Uint.max(a, b); // Uint (150)
|
|
51
|
+
*
|
|
52
|
+
* // Utility operations
|
|
53
|
+
* const random = Uint.random(); // Uint (random non-negative integer)
|
|
54
|
+
* const power = Uint.pow(asUint(2), asUint(8)); // Uint (256)
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
const Uint = {
|
|
58
|
+
/**
|
|
59
|
+
* Type guard to check if a value is a Uint.
|
|
60
|
+
* @param value The value to check.
|
|
61
|
+
* @returns `true` if the value is a non-negative integer, `false` otherwise.
|
|
62
|
+
*/
|
|
63
|
+
is,
|
|
64
|
+
/**
|
|
65
|
+
* The minimum value for an unsigned integer.
|
|
66
|
+
* @readonly
|
|
67
|
+
*/
|
|
68
|
+
MIN_VALUE,
|
|
69
|
+
/**
|
|
70
|
+
* Returns the smaller of two Uint values.
|
|
71
|
+
* @param a The first Uint.
|
|
72
|
+
* @param b The second Uint.
|
|
73
|
+
* @returns The minimum value as a Uint.
|
|
74
|
+
*/
|
|
75
|
+
min: min_,
|
|
76
|
+
/**
|
|
77
|
+
* Returns the larger of two Uint values.
|
|
78
|
+
* @param a The first Uint.
|
|
79
|
+
* @param b The second Uint.
|
|
80
|
+
* @returns The maximum value as a Uint.
|
|
81
|
+
*/
|
|
82
|
+
max: max_,
|
|
83
|
+
/**
|
|
84
|
+
* Clamps a number to the Uint range (non-negative).
|
|
85
|
+
* @param value The number to clamp.
|
|
86
|
+
* @returns The value clamped to [0, +∞) as a Uint.
|
|
87
|
+
*/
|
|
88
|
+
clamp,
|
|
89
|
+
/**
|
|
90
|
+
* Generates a random Uint value.
|
|
91
|
+
* @returns A random non-negative integer as a Uint.
|
|
92
|
+
*/
|
|
93
|
+
random,
|
|
94
|
+
/**
|
|
95
|
+
* Raises a Uint to the power of another Uint.
|
|
96
|
+
* @param a The base Uint.
|
|
97
|
+
* @param b The exponent Uint.
|
|
98
|
+
* @returns `a ** b` clamped to [0, +∞) as a Uint.
|
|
99
|
+
*/
|
|
100
|
+
pow,
|
|
101
|
+
/**
|
|
102
|
+
* Adds two Uint values.
|
|
103
|
+
* @param a The first Uint.
|
|
104
|
+
* @param b The second Uint.
|
|
105
|
+
* @returns `a + b` clamped to [0, +∞) as a Uint.
|
|
106
|
+
*/
|
|
107
|
+
add,
|
|
108
|
+
/**
|
|
109
|
+
* Subtracts one Uint from another.
|
|
110
|
+
* @param a The minuend Uint.
|
|
111
|
+
* @param b The subtrahend Uint.
|
|
112
|
+
* @returns `a - b` clamped to [0, +∞) as a Uint (minimum 0).
|
|
113
|
+
*/
|
|
114
|
+
sub,
|
|
115
|
+
/**
|
|
116
|
+
* Multiplies two Uint values.
|
|
117
|
+
* @param a The first Uint.
|
|
118
|
+
* @param b The second Uint.
|
|
119
|
+
* @returns `a * b` clamped to [0, +∞) as a Uint.
|
|
120
|
+
*/
|
|
121
|
+
mul,
|
|
122
|
+
/**
|
|
123
|
+
* Divides one Uint by another using floor division.
|
|
124
|
+
* @param a The dividend Uint.
|
|
125
|
+
* @param b The divisor Uint.
|
|
126
|
+
* @returns `⌊a / b⌋` clamped to [0, +∞) as a Uint.
|
|
127
|
+
*/
|
|
128
|
+
div,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export { Uint, asUint, isUint };
|
|
132
|
+
//# sourceMappingURL=uint.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uint.mjs","sources":["../../../src/number/branded-types/uint.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA,MAAM,iBAAiB,GAAG,wBAAwB;AAElD,MAAM,EACJ,SAAS,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,MAAM,EACN,EAAE,EACF,QAAQ,EACR,KAAK,GACN,GAAG,mBAAmB,CAAC,kBAAkB,CAAC,mBAAmB,CAI5D;AACA,IAAA,oBAAoB,EAAE,SAAS;AAC/B,IAAA,SAAS,EAAE,CAAC;AACZ,IAAA,SAAS,EAAE,SAAS;IACpB,iBAAiB;AACT,CAAA,CAAC;AAEX;;;;AAIG;AACI,MAAM,MAAM,GAAG;AAEtB;;;;;;;;;;;;AAYG;AACI,MAAM,MAAM,GAAG;AAEtB;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACI,MAAM,IAAI,GAAG;AAClB;;;;AAIG;IACH,EAAE;AAEF;;;AAGG;IACH,SAAS;AAET;;;;;AAKG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;;AAKG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;AAIG;IACH,KAAK;AAEL;;;AAGG;IACH,MAAM;AAEN;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;;;;;"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a number is a Uint16 (16-bit unsigned integer in the range [0, 2^16)).
|
|
3
|
+
* @param value The value to check.
|
|
4
|
+
* @returns `true` if the value is a Uint16, `false` otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isUint16: (a: number) => a is Uint16;
|
|
7
|
+
/**
|
|
8
|
+
* Casts a number to a Uint16 type.
|
|
9
|
+
* @param value The value to cast.
|
|
10
|
+
* @returns The value as a Uint16 type.
|
|
11
|
+
* @throws {TypeError} If the value is not a non-negative integer less than 2^16.
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const x = asUint16(1000); // Uint16
|
|
15
|
+
* const y = asUint16(0); // Uint16
|
|
16
|
+
* // asUint16(-1); // throws TypeError
|
|
17
|
+
* // asUint16(70000); // throws TypeError
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const asUint16: <N extends number>(x: N) => number & {
|
|
21
|
+
readonly NaNValue: false;
|
|
22
|
+
readonly "> -2^16": true;
|
|
23
|
+
readonly "> -2^32": true;
|
|
24
|
+
readonly ">= -2^15": true;
|
|
25
|
+
readonly ">= -2^31": true;
|
|
26
|
+
readonly ">=0": true;
|
|
27
|
+
readonly "< 2^16": true;
|
|
28
|
+
readonly "< 2^31": true;
|
|
29
|
+
readonly "< 2^32": true;
|
|
30
|
+
readonly Finite: true;
|
|
31
|
+
readonly Int: true;
|
|
32
|
+
readonly SafeInt: true;
|
|
33
|
+
} & Readonly<{
|
|
34
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
35
|
+
}> & N;
|
|
36
|
+
/**
|
|
37
|
+
* Namespace providing type-safe arithmetic operations for 16-bit unsigned integers.
|
|
38
|
+
*
|
|
39
|
+
* All operations automatically clamp results to the valid Uint16 range [0, 65535].
|
|
40
|
+
* This ensures that all arithmetic maintains the 16-bit unsigned integer constraint,
|
|
41
|
+
* with negative results clamped to 0 and overflow results clamped to MAX_VALUE.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const a = asUint16(60000);
|
|
46
|
+
* const b = asUint16(10000);
|
|
47
|
+
*
|
|
48
|
+
* // Arithmetic operations with automatic clamping
|
|
49
|
+
* const sum = Uint16.add(a, b); // Uint16 (65535 - clamped to MAX_VALUE)
|
|
50
|
+
* const diff = Uint16.sub(b, a); // Uint16 (0 - clamped to MIN_VALUE)
|
|
51
|
+
* const product = Uint16.mul(a, b); // Uint16 (65535 - clamped due to overflow)
|
|
52
|
+
*
|
|
53
|
+
* // Range operations
|
|
54
|
+
* const clamped = Uint16.clamp(-100); // Uint16 (0)
|
|
55
|
+
* const minimum = Uint16.min(a, b); // Uint16 (10000)
|
|
56
|
+
* const maximum = Uint16.max(a, b); // Uint16 (60000)
|
|
57
|
+
*
|
|
58
|
+
* // Utility operations
|
|
59
|
+
* const random = Uint16.random(); // Uint16 (random value in [0, 65535])
|
|
60
|
+
* const power = Uint16.pow(asUint16(2), asUint16(10)); // Uint16 (1024)
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare const Uint16: {
|
|
64
|
+
/**
|
|
65
|
+
* Type guard to check if a value is a Uint16.
|
|
66
|
+
* @param value The value to check.
|
|
67
|
+
* @returns `true` if the value is a 16-bit unsigned integer, `false` otherwise.
|
|
68
|
+
*/
|
|
69
|
+
readonly is: (a: number) => a is Uint16;
|
|
70
|
+
/**
|
|
71
|
+
* The minimum value for a 16-bit unsigned integer.
|
|
72
|
+
* @readonly
|
|
73
|
+
*/
|
|
74
|
+
readonly MIN_VALUE: 0;
|
|
75
|
+
/**
|
|
76
|
+
* The maximum value for a 16-bit unsigned integer.
|
|
77
|
+
* @readonly
|
|
78
|
+
*/
|
|
79
|
+
readonly MAX_VALUE: number;
|
|
80
|
+
/**
|
|
81
|
+
* Returns the smaller of two Uint16 values.
|
|
82
|
+
* @param a The first Uint16.
|
|
83
|
+
* @param b The second Uint16.
|
|
84
|
+
* @returns The minimum value as a Uint16.
|
|
85
|
+
*/
|
|
86
|
+
readonly min: (...values: readonly WithSmallInt<Uint16, 40>[]) => Uint16;
|
|
87
|
+
/**
|
|
88
|
+
* Returns the larger of two Uint16 values.
|
|
89
|
+
* @param a The first Uint16.
|
|
90
|
+
* @param b The second Uint16.
|
|
91
|
+
* @returns The maximum value as a Uint16.
|
|
92
|
+
*/
|
|
93
|
+
readonly max: (...values: readonly WithSmallInt<Uint16, 40>[]) => Uint16;
|
|
94
|
+
/**
|
|
95
|
+
* Clamps a number to the Uint16 range.
|
|
96
|
+
* @param value The number to clamp.
|
|
97
|
+
* @returns The value clamped to [0, 65535] as a Uint16.
|
|
98
|
+
*/
|
|
99
|
+
readonly clamp: (x: number) => Uint16;
|
|
100
|
+
/**
|
|
101
|
+
* Generates a random Uint16 value within the valid range.
|
|
102
|
+
* @returns A random Uint16 between 0 and 65535.
|
|
103
|
+
*/
|
|
104
|
+
readonly random: (min: WithSmallInt<Uint16, 40>, max: WithSmallInt<Uint16, 40>) => Uint16;
|
|
105
|
+
/**
|
|
106
|
+
* Raises a Uint16 to the power of another Uint16.
|
|
107
|
+
* @param a The base Uint16.
|
|
108
|
+
* @param b The exponent Uint16.
|
|
109
|
+
* @returns `a ** b` clamped to [0, 65535] as a Uint16.
|
|
110
|
+
*/
|
|
111
|
+
readonly pow: (x: WithSmallInt<Uint16, 40>, y: WithSmallInt<Uint16, 40>) => Uint16;
|
|
112
|
+
/**
|
|
113
|
+
* Adds two Uint16 values.
|
|
114
|
+
* @param a The first Uint16.
|
|
115
|
+
* @param b The second Uint16.
|
|
116
|
+
* @returns `a + b` clamped to [0, 65535] as a Uint16.
|
|
117
|
+
*/
|
|
118
|
+
readonly add: (x: WithSmallInt<Uint16, 40>, y: WithSmallInt<Uint16, 40>) => Uint16;
|
|
119
|
+
/**
|
|
120
|
+
* Subtracts one Uint16 from another.
|
|
121
|
+
* @param a The minuend Uint16.
|
|
122
|
+
* @param b The subtrahend Uint16.
|
|
123
|
+
* @returns `a - b` clamped to [0, 65535] as a Uint16 (minimum 0).
|
|
124
|
+
*/
|
|
125
|
+
readonly sub: (x: WithSmallInt<Uint16, 40>, y: WithSmallInt<Uint16, 40>) => Uint16;
|
|
126
|
+
/**
|
|
127
|
+
* Multiplies two Uint16 values.
|
|
128
|
+
* @param a The first Uint16.
|
|
129
|
+
* @param b The second Uint16.
|
|
130
|
+
* @returns `a * b` clamped to [0, 65535] as a Uint16.
|
|
131
|
+
*/
|
|
132
|
+
readonly mul: (x: WithSmallInt<Uint16, 40>, y: WithSmallInt<Uint16, 40>) => Uint16;
|
|
133
|
+
/**
|
|
134
|
+
* Divides one Uint16 by another using floor division.
|
|
135
|
+
* @param a The dividend Uint16.
|
|
136
|
+
* @param b The divisor Uint16.
|
|
137
|
+
* @returns `⌊a / b⌋` clamped to [0, 65535] as a Uint16.
|
|
138
|
+
*/
|
|
139
|
+
readonly div: (x: WithSmallInt<Uint16, 40>, y: 1 | 2 | 3 | 32 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 10 | 24 | 14 | 34 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | NormalizeBrandUnion<number & {
|
|
140
|
+
readonly NaNValue: false;
|
|
141
|
+
readonly "!=0": true;
|
|
142
|
+
readonly "> -2^16": true;
|
|
143
|
+
readonly "> -2^32": true;
|
|
144
|
+
readonly ">= -2^15": true;
|
|
145
|
+
readonly ">= -2^31": true;
|
|
146
|
+
readonly ">=0": true;
|
|
147
|
+
readonly "< 2^16": true;
|
|
148
|
+
readonly "< 2^31": true;
|
|
149
|
+
readonly "< 2^32": true;
|
|
150
|
+
readonly Finite: true;
|
|
151
|
+
readonly Int: true;
|
|
152
|
+
readonly SafeInt: true;
|
|
153
|
+
} & Readonly<{
|
|
154
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
155
|
+
}>>) => Uint16;
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=uint16.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uint16.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/uint16.mts"],"names":[],"mappings":"AAgCA;;;;GAIG;AACH,eAAO,MAAM,QAAQ,4BAAK,CAAC;AAE3B;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;MAAW,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,MAAM;IACjB;;;;OAIG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;OAIG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;;;;;;;;;;;;;;;;;CAEK,CAAC"}
|