ts-data-forge 11.0.0 → 11.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/dist/number/branded-types/finite-number.d.mts +47 -61
- package/dist/number/branded-types/finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/finite-number.mjs +37 -41
- package/dist/number/branded-types/finite-number.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +40 -46
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int.mjs +29 -31
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/int16.d.mts +65 -58
- package/dist/number/branded-types/int16.d.mts.map +1 -1
- package/dist/number/branded-types/int16.mjs +49 -45
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.d.mts +65 -58
- package/dist/number/branded-types/int32.d.mts.map +1 -1
- package/dist/number/branded-types/int32.mjs +49 -45
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +68 -59
- package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-finite-number.mjs +52 -46
- package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +60 -48
- package/dist/number/branded-types/negative-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-int.mjs +40 -36
- package/dist/number/branded-types/negative-int.mjs.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +57 -56
- package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-safe-int.mjs +40 -41
- package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +74 -64
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +58 -51
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +64 -57
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +47 -43
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +64 -58
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +47 -44
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +64 -54
- package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.mjs +48 -41
- package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts +41 -146
- package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-int.mjs +27 -107
- package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts +54 -53
- package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.mjs +37 -39
- package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts +62 -49
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.mjs +46 -37
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int.d.mts +51 -38
- package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int.mjs +31 -27
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts +52 -53
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +36 -39
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +52 -54
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +36 -40
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +53 -54
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +36 -40
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +52 -53
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +35 -39
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +52 -53
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +35 -39
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +74 -63
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +58 -50
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +46 -68
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +34 -49
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +61 -57
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int16.mjs +44 -43
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +61 -57
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int32.mjs +44 -43
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +62 -57
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +45 -43
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +61 -57
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +44 -43
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +61 -58
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +44 -44
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +43 -62
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +35 -42
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +62 -57
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +46 -44
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.d.mts +63 -50
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +42 -39
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +60 -58
- package/dist/number/branded-types/uint16.d.mts.map +1 -1
- package/dist/number/branded-types/uint16.mjs +44 -43
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +59 -55
- package/dist/number/branded-types/uint32.d.mts.map +1 -1
- package/dist/number/branded-types/uint32.mjs +42 -42
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.d.mts +56 -65
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/int8.mjs +44 -43
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.d.mts +60 -58
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/enum/uint8.mjs +44 -43
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/package.json +2 -1
- package/src/number/branded-types/finite-number.mts +47 -61
- package/src/number/branded-types/int.mts +40 -46
- package/src/number/branded-types/int16.mts +65 -58
- package/src/number/branded-types/int32.mts +65 -58
- package/src/number/branded-types/negative-finite-number.mts +68 -68
- package/src/number/branded-types/negative-int.mts +60 -57
- package/src/number/branded-types/negative-safe-int.mts +57 -65
- package/src/number/branded-types/non-negative-finite-number.mts +74 -64
- package/src/number/branded-types/non-negative-int16.mts +64 -57
- package/src/number/branded-types/non-negative-int32.mts +64 -58
- package/src/number/branded-types/non-positive-finite-number.mts +64 -54
- package/src/number/branded-types/non-positive-int.mts +41 -146
- package/src/number/branded-types/non-positive-safe-int.mts +54 -53
- package/src/number/branded-types/non-zero-finite-number.mts +62 -51
- package/src/number/branded-types/non-zero-int.mts +51 -38
- package/src/number/branded-types/non-zero-int16.mts +52 -53
- package/src/number/branded-types/non-zero-int32.mts +52 -54
- package/src/number/branded-types/non-zero-safe-int.mts +53 -54
- package/src/number/branded-types/non-zero-uint16.mts +52 -53
- package/src/number/branded-types/non-zero-uint32.mts +52 -53
- package/src/number/branded-types/positive-finite-number.mts +74 -63
- package/src/number/branded-types/positive-int.mts +46 -68
- package/src/number/branded-types/positive-int16.mts +61 -57
- package/src/number/branded-types/positive-int32.mts +61 -57
- package/src/number/branded-types/positive-safe-int.mts +62 -57
- package/src/number/branded-types/positive-uint16.mts +61 -57
- package/src/number/branded-types/positive-uint32.mts +61 -58
- package/src/number/branded-types/safe-int.mts +43 -62
- package/src/number/branded-types/safe-uint.mts +62 -57
- package/src/number/branded-types/uint.mts +63 -50
- package/src/number/branded-types/uint16.mts +60 -58
- package/src/number/branded-types/uint32.mts +59 -55
- package/src/number/enum/int8.mts +56 -65
- package/src/number/enum/uint8.mts +60 -58
|
@@ -35,131 +35,136 @@ const {
|
|
|
35
35
|
} as const);
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* Type guard that checks if a value is a non-negative safe integer.
|
|
39
39
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
40
|
+
* Returns `true` for a non-negative safe integer — a value with no fractional
|
|
41
|
+
* component.
|
|
42
|
+
*
|
|
43
|
+
* @param value - The value to check
|
|
44
|
+
* @returns `true` if the value is a non-negative safe integer, `false` otherwise
|
|
42
45
|
*/
|
|
43
46
|
export const isSafeUint = is;
|
|
44
47
|
|
|
45
48
|
/**
|
|
46
|
-
* Casts a number to
|
|
49
|
+
* Casts a `number` to the `SafeUint` branded type.
|
|
50
|
+
*
|
|
51
|
+
* Validates that the value is a non-negative safe integer and returns it with
|
|
52
|
+
* the `SafeUint` brand. Throws a `TypeError` otherwise.
|
|
47
53
|
*
|
|
48
|
-
* @param value The value to cast
|
|
49
|
-
* @returns The value as a SafeUint
|
|
50
|
-
* @throws {TypeError} If the value is not a non-negative safe integer
|
|
54
|
+
* @param value - The value to cast
|
|
55
|
+
* @returns The value as a `SafeUint`
|
|
56
|
+
* @throws {TypeError} If the value is not a non-negative safe integer
|
|
51
57
|
*/
|
|
52
58
|
export const asSafeUint = castType;
|
|
53
59
|
|
|
54
60
|
/**
|
|
55
|
-
* Namespace providing type-safe
|
|
56
|
-
* integers.
|
|
61
|
+
* Namespace providing type-safe operations for the `SafeUint` branded type.
|
|
57
62
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* non-negative constraint and IEEE 754 precision guarantees, preventing
|
|
61
|
-
* precision loss while ensuring results are never negative.
|
|
63
|
+
* The `SafeUint` type represents a non-negative safe integer. Division (`div`)
|
|
64
|
+
* uses floor division.
|
|
62
65
|
*/
|
|
63
66
|
export const SafeUint = {
|
|
64
67
|
/**
|
|
65
|
-
* Type guard
|
|
68
|
+
* Type guard that checks if a value is a non-negative safe integer.
|
|
66
69
|
*
|
|
67
|
-
* @param value The value to check
|
|
68
|
-
* @returns `true` if the value is a non-negative safe integer, `false`
|
|
69
|
-
*
|
|
70
|
+
* @param value - The value to check
|
|
71
|
+
* @returns `true` if the value is a non-negative safe integer, `false` otherwise
|
|
72
|
+
* @see {@link isSafeUint} for usage examples
|
|
70
73
|
*/
|
|
71
74
|
is,
|
|
72
75
|
|
|
73
76
|
/**
|
|
74
|
-
* The
|
|
75
|
-
*
|
|
76
|
-
* @readonly
|
|
77
|
+
* The smallest value representable as `SafeUint`.
|
|
77
78
|
*/
|
|
78
79
|
MIN_VALUE,
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
|
-
* The
|
|
82
|
-
*
|
|
83
|
-
* @readonly
|
|
82
|
+
* The largest value representable as `SafeUint`.
|
|
84
83
|
*/
|
|
85
84
|
MAX_VALUE,
|
|
86
85
|
|
|
87
86
|
/**
|
|
88
|
-
* Returns the
|
|
87
|
+
* Returns the smallest of the given non-negative safe integers.
|
|
89
88
|
*
|
|
90
|
-
* @param
|
|
91
|
-
* @
|
|
92
|
-
* @returns The minimum value as a SafeUint.
|
|
89
|
+
* @param values - The non-negative safe integers to compare (at least one required)
|
|
90
|
+
* @returns The smallest value as a `SafeUint`
|
|
93
91
|
*/
|
|
94
92
|
min: min_,
|
|
95
93
|
|
|
96
94
|
/**
|
|
97
|
-
* Returns the
|
|
95
|
+
* Returns the largest of the given non-negative safe integers.
|
|
98
96
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @
|
|
101
|
-
* @returns The maximum value as a SafeUint.
|
|
97
|
+
* @param values - The non-negative safe integers to compare (at least one required)
|
|
98
|
+
* @returns The largest value as a `SafeUint`
|
|
102
99
|
*/
|
|
103
100
|
max: max_,
|
|
104
101
|
|
|
105
102
|
/**
|
|
106
|
-
* Clamps a number
|
|
103
|
+
* Clamps a `number` into the `SafeUint` range, rounding to the nearest
|
|
104
|
+
* integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
107
105
|
*
|
|
108
|
-
* @param value The
|
|
109
|
-
* @returns The
|
|
106
|
+
* @param value - The value to clamp
|
|
107
|
+
* @returns The clamped value as a `SafeUint`
|
|
110
108
|
*/
|
|
111
109
|
clamp,
|
|
112
110
|
|
|
113
111
|
/**
|
|
114
|
-
* Generates a random SafeUint
|
|
112
|
+
* Generates a random `SafeUint` within the given range.
|
|
113
|
+
*
|
|
114
|
+
* The range is inclusive on both ends.
|
|
115
115
|
*
|
|
116
|
-
* @
|
|
116
|
+
* @param min - The minimum value (inclusive)
|
|
117
|
+
* @param max - The maximum value (inclusive)
|
|
118
|
+
* @returns A random `SafeUint` in `[min, max]`
|
|
117
119
|
*/
|
|
118
120
|
random,
|
|
119
121
|
|
|
120
122
|
/**
|
|
121
|
-
* Raises a
|
|
123
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `SafeUint` (floored to
|
|
124
|
+
* an integer).
|
|
122
125
|
*
|
|
123
|
-
* @param a The base
|
|
124
|
-
* @param b The exponent
|
|
125
|
-
* @returns `a ** b`
|
|
126
|
+
* @param a - The base non-negative safe integer
|
|
127
|
+
* @param b - The exponent non-negative safe integer
|
|
128
|
+
* @returns `a ** b` as a `SafeUint`
|
|
126
129
|
*/
|
|
127
130
|
pow,
|
|
128
131
|
|
|
129
132
|
/**
|
|
130
|
-
* Adds two SafeUint
|
|
133
|
+
* Adds two non-negative safe integers, returning `a + b` as a `SafeUint`.
|
|
131
134
|
*
|
|
132
|
-
* @param a The first
|
|
133
|
-
* @param b The second
|
|
134
|
-
* @returns `a
|
|
135
|
+
* @param a - The first non-negative safe integer
|
|
136
|
+
* @param b - The second non-negative safe integer
|
|
137
|
+
* @returns The sum of `a` and `b` as a `SafeUint`
|
|
135
138
|
*/
|
|
136
139
|
add,
|
|
137
140
|
|
|
138
141
|
/**
|
|
139
|
-
* Subtracts
|
|
142
|
+
* Subtracts two non-negative safe integers, returning `a - b` as a
|
|
143
|
+
* `SafeUint`.
|
|
140
144
|
*
|
|
141
|
-
* @param a The
|
|
142
|
-
* @param b The
|
|
143
|
-
* @returns `a
|
|
144
|
-
* 0).
|
|
145
|
+
* @param a - The first non-negative safe integer
|
|
146
|
+
* @param b - The second non-negative safe integer
|
|
147
|
+
* @returns The difference of `a` and `b` as a `SafeUint`
|
|
145
148
|
*/
|
|
146
149
|
sub,
|
|
147
150
|
|
|
148
151
|
/**
|
|
149
|
-
* Multiplies two
|
|
152
|
+
* Multiplies two non-negative safe integers, returning `a * b` as a
|
|
153
|
+
* `SafeUint`.
|
|
150
154
|
*
|
|
151
|
-
* @param a The first
|
|
152
|
-
* @param b The second
|
|
153
|
-
* @returns `a
|
|
155
|
+
* @param a - The first non-negative safe integer
|
|
156
|
+
* @param b - The second non-negative safe integer
|
|
157
|
+
* @returns The product of `a` and `b` as a `SafeUint`
|
|
154
158
|
*/
|
|
155
159
|
mul,
|
|
156
160
|
|
|
157
161
|
/**
|
|
158
|
-
* Divides
|
|
162
|
+
* Divides two non-negative safe integers using floor division (`⌊a / b⌋`):
|
|
163
|
+
* the result is `a / b` rounded toward negative infinity, as a `SafeUint`.
|
|
159
164
|
*
|
|
160
|
-
* @param a The dividend
|
|
161
|
-
* @param b The divisor
|
|
162
|
-
* @returns
|
|
165
|
+
* @param a - The dividend
|
|
166
|
+
* @param b - The divisor (must be non-zero)
|
|
167
|
+
* @returns The floored quotient as a `SafeUint`
|
|
163
168
|
*/
|
|
164
169
|
div,
|
|
165
170
|
} as const;
|
|
@@ -33,7 +33,11 @@ const {
|
|
|
33
33
|
} as const);
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* Type guard that checks if a value is a non-negative integer.
|
|
37
|
+
*
|
|
38
|
+
* Returns `true` for a non-negative integer — a value with no fractional
|
|
39
|
+
* component, including values outside the safe integer range (unlike
|
|
40
|
+
* `SafeInt`).
|
|
37
41
|
*
|
|
38
42
|
* @example
|
|
39
43
|
*
|
|
@@ -45,13 +49,16 @@ const {
|
|
|
45
49
|
* assert.isTrue(Uint.is(0));
|
|
46
50
|
* ```
|
|
47
51
|
*
|
|
48
|
-
* @param value The value to check
|
|
49
|
-
* @returns `true` if the value is a
|
|
52
|
+
* @param value - The value to check
|
|
53
|
+
* @returns `true` if the value is a non-negative integer, `false` otherwise
|
|
50
54
|
*/
|
|
51
55
|
export const isUint = is;
|
|
52
56
|
|
|
53
57
|
/**
|
|
54
|
-
* Casts a number to
|
|
58
|
+
* Casts a `number` to the `Uint` branded type.
|
|
59
|
+
*
|
|
60
|
+
* Validates that the value is a non-negative integer and returns it with the
|
|
61
|
+
* `Uint` brand. Throws a `TypeError` otherwise.
|
|
55
62
|
*
|
|
56
63
|
* @example
|
|
57
64
|
*
|
|
@@ -63,22 +70,25 @@ export const isUint = is;
|
|
|
63
70
|
* assert.isTrue(Uint.is(branded));
|
|
64
71
|
* ```
|
|
65
72
|
*
|
|
66
|
-
* @param value The value to cast
|
|
67
|
-
* @returns The value as
|
|
68
|
-
* @throws {TypeError} If the value is not a non-negative integer
|
|
73
|
+
* @param value - The value to cast
|
|
74
|
+
* @returns The value as an `Uint`
|
|
75
|
+
* @throws {TypeError} If the value is not a non-negative integer
|
|
69
76
|
*/
|
|
70
77
|
export const asUint = castType;
|
|
71
78
|
|
|
72
79
|
/**
|
|
73
|
-
* Namespace providing type-safe
|
|
80
|
+
* Namespace providing type-safe operations for the `Uint` branded type.
|
|
81
|
+
*
|
|
82
|
+
* The `Uint` type represents a non-negative integer. Division (`div`) uses
|
|
83
|
+
* floor division.
|
|
74
84
|
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
85
|
+
* Unlike `SafeInt`, `Uint` allows values outside the safe integer range (±2^53
|
|
86
|
+
* − 1), so very large magnitudes may lose precision in JavaScript's `number`
|
|
87
|
+
* type.
|
|
78
88
|
*/
|
|
79
89
|
export const Uint = {
|
|
80
90
|
/**
|
|
81
|
-
* Type guard
|
|
91
|
+
* Type guard that checks if a value is a non-negative integer.
|
|
82
92
|
*
|
|
83
93
|
* @example
|
|
84
94
|
*
|
|
@@ -90,21 +100,19 @@ export const Uint = {
|
|
|
90
100
|
* assert.isTrue(Uint.is(0));
|
|
91
101
|
* ```
|
|
92
102
|
*
|
|
93
|
-
* @param value The value to check
|
|
94
|
-
* @returns `true` if the value is a non-negative integer, `false` otherwise
|
|
103
|
+
* @param value - The value to check
|
|
104
|
+
* @returns `true` if the value is a non-negative integer, `false` otherwise
|
|
95
105
|
* @see {@link isUint} for usage examples
|
|
96
106
|
*/
|
|
97
107
|
is,
|
|
98
108
|
|
|
99
109
|
/**
|
|
100
|
-
* The
|
|
101
|
-
*
|
|
102
|
-
* @readonly
|
|
110
|
+
* The smallest value representable as `Uint`.
|
|
103
111
|
*/
|
|
104
112
|
MIN_VALUE,
|
|
105
113
|
|
|
106
114
|
/**
|
|
107
|
-
* Returns the
|
|
115
|
+
* Returns the smallest of the given non-negative integers.
|
|
108
116
|
*
|
|
109
117
|
* @example
|
|
110
118
|
*
|
|
@@ -114,14 +122,13 @@ export const Uint = {
|
|
|
114
122
|
* assert.isTrue(smallest === 3);
|
|
115
123
|
* ```
|
|
116
124
|
*
|
|
117
|
-
* @param
|
|
118
|
-
* @
|
|
119
|
-
* @returns The minimum value as a Uint.
|
|
125
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
126
|
+
* @returns The smallest value as an `Uint`
|
|
120
127
|
*/
|
|
121
128
|
min: min_,
|
|
122
129
|
|
|
123
130
|
/**
|
|
124
|
-
* Returns the
|
|
131
|
+
* Returns the largest of the given non-negative integers.
|
|
125
132
|
*
|
|
126
133
|
* @example
|
|
127
134
|
*
|
|
@@ -131,14 +138,14 @@ export const Uint = {
|
|
|
131
138
|
* assert.isTrue(largest === 7);
|
|
132
139
|
* ```
|
|
133
140
|
*
|
|
134
|
-
* @param
|
|
135
|
-
* @
|
|
136
|
-
* @returns The maximum value as a Uint.
|
|
141
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
142
|
+
* @returns The largest value as an `Uint`
|
|
137
143
|
*/
|
|
138
144
|
max: max_,
|
|
139
145
|
|
|
140
146
|
/**
|
|
141
|
-
* Clamps a number
|
|
147
|
+
* Clamps a `number` into the `Uint` range, rounding to the nearest integer
|
|
148
|
+
* and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
142
149
|
*
|
|
143
150
|
* @example
|
|
144
151
|
*
|
|
@@ -152,13 +159,15 @@ export const Uint = {
|
|
|
152
159
|
* assert.isTrue(clampedPositive === 42);
|
|
153
160
|
* ```
|
|
154
161
|
*
|
|
155
|
-
* @param value The
|
|
156
|
-
* @returns The
|
|
162
|
+
* @param value - The value to clamp
|
|
163
|
+
* @returns The clamped value as an `Uint`
|
|
157
164
|
*/
|
|
158
165
|
clamp,
|
|
159
166
|
|
|
160
167
|
/**
|
|
161
|
-
* Generates a random Uint
|
|
168
|
+
* Generates a random `Uint` within the given range.
|
|
169
|
+
*
|
|
170
|
+
* The range is inclusive on both ends.
|
|
162
171
|
*
|
|
163
172
|
* @example
|
|
164
173
|
*
|
|
@@ -174,12 +183,15 @@ export const Uint = {
|
|
|
174
183
|
* assert.isTrue(randomValue >= 0 && randomValue <= 3);
|
|
175
184
|
* ```
|
|
176
185
|
*
|
|
177
|
-
* @
|
|
186
|
+
* @param min - The minimum value (inclusive)
|
|
187
|
+
* @param max - The maximum value (inclusive)
|
|
188
|
+
* @returns A random `Uint` in `[min, max]`
|
|
178
189
|
*/
|
|
179
190
|
random,
|
|
180
191
|
|
|
181
192
|
/**
|
|
182
|
-
* Raises a
|
|
193
|
+
* Raises `a` to the power `b`, returning `a ** b` as an `Uint` (floored to an
|
|
194
|
+
* integer).
|
|
183
195
|
*
|
|
184
196
|
* @example
|
|
185
197
|
*
|
|
@@ -193,14 +205,14 @@ export const Uint = {
|
|
|
193
205
|
* assert.isTrue(power === 32);
|
|
194
206
|
* ```
|
|
195
207
|
*
|
|
196
|
-
* @param a The base
|
|
197
|
-
* @param b The exponent
|
|
198
|
-
* @returns `a ** b`
|
|
208
|
+
* @param a - The base non-negative integer
|
|
209
|
+
* @param b - The exponent non-negative integer
|
|
210
|
+
* @returns `a ** b` as an `Uint`
|
|
199
211
|
*/
|
|
200
212
|
pow,
|
|
201
213
|
|
|
202
214
|
/**
|
|
203
|
-
* Adds two Uint
|
|
215
|
+
* Adds two non-negative integers, returning `a + b` as an `Uint`.
|
|
204
216
|
*
|
|
205
217
|
* @example
|
|
206
218
|
*
|
|
@@ -210,14 +222,14 @@ export const Uint = {
|
|
|
210
222
|
* assert.isTrue(sum === 13);
|
|
211
223
|
* ```
|
|
212
224
|
*
|
|
213
|
-
* @param a The first
|
|
214
|
-
* @param b The second
|
|
215
|
-
* @returns `a
|
|
225
|
+
* @param a - The first non-negative integer
|
|
226
|
+
* @param b - The second non-negative integer
|
|
227
|
+
* @returns The sum of `a` and `b` as an `Uint`
|
|
216
228
|
*/
|
|
217
229
|
add,
|
|
218
230
|
|
|
219
231
|
/**
|
|
220
|
-
* Subtracts
|
|
232
|
+
* Subtracts two non-negative integers, returning `a - b` as an `Uint`.
|
|
221
233
|
*
|
|
222
234
|
* @example
|
|
223
235
|
*
|
|
@@ -227,14 +239,14 @@ export const Uint = {
|
|
|
227
239
|
* assert.isTrue(difference === 0);
|
|
228
240
|
* ```
|
|
229
241
|
*
|
|
230
|
-
* @param a The
|
|
231
|
-
* @param b The
|
|
232
|
-
* @returns `a
|
|
242
|
+
* @param a - The first non-negative integer
|
|
243
|
+
* @param b - The second non-negative integer
|
|
244
|
+
* @returns The difference of `a` and `b` as an `Uint`
|
|
233
245
|
*/
|
|
234
246
|
sub,
|
|
235
247
|
|
|
236
248
|
/**
|
|
237
|
-
* Multiplies two Uint
|
|
249
|
+
* Multiplies two non-negative integers, returning `a * b` as an `Uint`.
|
|
238
250
|
*
|
|
239
251
|
* @example
|
|
240
252
|
*
|
|
@@ -244,14 +256,15 @@ export const Uint = {
|
|
|
244
256
|
* assert.isTrue(product === 42);
|
|
245
257
|
* ```
|
|
246
258
|
*
|
|
247
|
-
* @param a The first
|
|
248
|
-
* @param b The second
|
|
249
|
-
* @returns `a
|
|
259
|
+
* @param a - The first non-negative integer
|
|
260
|
+
* @param b - The second non-negative integer
|
|
261
|
+
* @returns The product of `a` and `b` as an `Uint`
|
|
250
262
|
*/
|
|
251
263
|
mul,
|
|
252
264
|
|
|
253
265
|
/**
|
|
254
|
-
* Divides
|
|
266
|
+
* Divides two non-negative integers using floor division (`⌊a / b⌋`): the
|
|
267
|
+
* result is `a / b` rounded toward negative infinity, as an `Uint`.
|
|
255
268
|
*
|
|
256
269
|
* @example
|
|
257
270
|
*
|
|
@@ -261,9 +274,9 @@ export const Uint = {
|
|
|
261
274
|
* assert.isTrue(quotient === 2);
|
|
262
275
|
* ```
|
|
263
276
|
*
|
|
264
|
-
* @param a The dividend
|
|
265
|
-
* @param b The divisor
|
|
266
|
-
* @returns
|
|
277
|
+
* @param a - The dividend
|
|
278
|
+
* @param b - The divisor (must be non-zero)
|
|
279
|
+
* @returns The floored quotient as an `Uint`
|
|
267
280
|
*/
|
|
268
281
|
div,
|
|
269
282
|
} as const;
|
|
@@ -34,132 +34,134 @@ const {
|
|
|
34
34
|
} as const);
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
* 2^16)).
|
|
37
|
+
* Type guard that checks if a value is a non-negative integer less than 2^16.
|
|
39
38
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* Returns `true` for a non-negative integer less than 2^16 — a value with no
|
|
40
|
+
* fractional component.
|
|
41
|
+
*
|
|
42
|
+
* @param value - The value to check
|
|
43
|
+
* @returns `true` if the value is a non-negative integer less than 2^16, `false` otherwise
|
|
42
44
|
*/
|
|
43
45
|
export const isUint16 = is;
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
|
-
* Casts a number to
|
|
48
|
+
* Casts a `number` to the `Uint16` branded type.
|
|
49
|
+
*
|
|
50
|
+
* Validates that the value is a non-negative integer less than 2^16 and returns
|
|
51
|
+
* it with the `Uint16` brand. Throws a `TypeError` otherwise.
|
|
47
52
|
*
|
|
48
|
-
* @param value The value to cast
|
|
49
|
-
* @returns The value as
|
|
50
|
-
* @throws {TypeError} If the value is not a non-negative integer less than
|
|
51
|
-
* 2^16.
|
|
53
|
+
* @param value - The value to cast
|
|
54
|
+
* @returns The value as an `Uint16`
|
|
55
|
+
* @throws {TypeError} If the value is not a non-negative integer less than 2^16
|
|
52
56
|
*/
|
|
53
57
|
export const asUint16 = castType;
|
|
54
58
|
|
|
55
59
|
/**
|
|
56
|
-
* Namespace providing type-safe
|
|
57
|
-
* integers.
|
|
60
|
+
* Namespace providing type-safe operations for the `Uint16` branded type.
|
|
58
61
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* integer constraint, with negative results clamped to 0 and overflow results
|
|
62
|
-
* clamped to MAX_VALUE.
|
|
62
|
+
* The `Uint16` type represents a non-negative integer less than 2^16. Division
|
|
63
|
+
* (`div`) uses floor division.
|
|
63
64
|
*/
|
|
64
65
|
export const Uint16 = {
|
|
65
66
|
/**
|
|
66
|
-
* Type guard
|
|
67
|
+
* Type guard that checks if a value is a non-negative integer less than 2^16.
|
|
67
68
|
*
|
|
68
|
-
* @param value The value to check
|
|
69
|
-
* @returns `true` if the value is a
|
|
70
|
-
*
|
|
69
|
+
* @param value - The value to check
|
|
70
|
+
* @returns `true` if the value is a non-negative integer less than 2^16, `false` otherwise
|
|
71
|
+
* @see {@link isUint16} for usage examples
|
|
71
72
|
*/
|
|
72
73
|
is,
|
|
73
74
|
|
|
74
75
|
/**
|
|
75
|
-
* The
|
|
76
|
-
*
|
|
77
|
-
* @readonly
|
|
76
|
+
* The smallest value representable as `Uint16`.
|
|
78
77
|
*/
|
|
79
78
|
MIN_VALUE,
|
|
80
79
|
|
|
81
80
|
/**
|
|
82
|
-
* The
|
|
83
|
-
*
|
|
84
|
-
* @readonly
|
|
81
|
+
* The largest value representable as `Uint16`.
|
|
85
82
|
*/
|
|
86
83
|
MAX_VALUE,
|
|
87
84
|
|
|
88
85
|
/**
|
|
89
|
-
* Returns the
|
|
86
|
+
* Returns the smallest of the given non-negative integers.
|
|
90
87
|
*
|
|
91
|
-
* @param
|
|
92
|
-
* @
|
|
93
|
-
* @returns The minimum value as a Uint16.
|
|
88
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
89
|
+
* @returns The smallest value as an `Uint16`
|
|
94
90
|
*/
|
|
95
91
|
min: min_,
|
|
96
92
|
|
|
97
93
|
/**
|
|
98
|
-
* Returns the
|
|
94
|
+
* Returns the largest of the given non-negative integers.
|
|
99
95
|
*
|
|
100
|
-
* @param
|
|
101
|
-
* @
|
|
102
|
-
* @returns The maximum value as a Uint16.
|
|
96
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
97
|
+
* @returns The largest value as an `Uint16`
|
|
103
98
|
*/
|
|
104
99
|
max: max_,
|
|
105
100
|
|
|
106
101
|
/**
|
|
107
|
-
* Clamps a number
|
|
102
|
+
* Clamps a `number` into the `Uint16` range, rounding to the nearest integer
|
|
103
|
+
* and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
108
104
|
*
|
|
109
|
-
* @param value The
|
|
110
|
-
* @returns The
|
|
105
|
+
* @param value - The value to clamp
|
|
106
|
+
* @returns The clamped value as an `Uint16`
|
|
111
107
|
*/
|
|
112
108
|
clamp,
|
|
113
109
|
|
|
114
110
|
/**
|
|
115
|
-
* Generates a random Uint16
|
|
111
|
+
* Generates a random `Uint16` within the given range.
|
|
112
|
+
*
|
|
113
|
+
* The range is inclusive on both ends.
|
|
116
114
|
*
|
|
117
|
-
* @
|
|
115
|
+
* @param min - The minimum value (inclusive)
|
|
116
|
+
* @param max - The maximum value (inclusive)
|
|
117
|
+
* @returns A random `Uint16` in `[min, max]`
|
|
118
118
|
*/
|
|
119
119
|
random,
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
|
-
* Raises a
|
|
122
|
+
* Raises `a` to the power `b`, returning `a ** b` as an `Uint16` (floored to
|
|
123
|
+
* an integer).
|
|
123
124
|
*
|
|
124
|
-
* @param a The base
|
|
125
|
-
* @param b The exponent
|
|
126
|
-
* @returns `a ** b`
|
|
125
|
+
* @param a - The base non-negative integer
|
|
126
|
+
* @param b - The exponent non-negative integer
|
|
127
|
+
* @returns `a ** b` as an `Uint16`
|
|
127
128
|
*/
|
|
128
129
|
pow,
|
|
129
130
|
|
|
130
131
|
/**
|
|
131
|
-
* Adds two Uint16
|
|
132
|
+
* Adds two non-negative integers, returning `a + b` as an `Uint16`.
|
|
132
133
|
*
|
|
133
|
-
* @param a The first
|
|
134
|
-
* @param b The second
|
|
135
|
-
* @returns `a
|
|
134
|
+
* @param a - The first non-negative integer
|
|
135
|
+
* @param b - The second non-negative integer
|
|
136
|
+
* @returns The sum of `a` and `b` as an `Uint16`
|
|
136
137
|
*/
|
|
137
138
|
add,
|
|
138
139
|
|
|
139
140
|
/**
|
|
140
|
-
* Subtracts
|
|
141
|
+
* Subtracts two non-negative integers, returning `a - b` as an `Uint16`.
|
|
141
142
|
*
|
|
142
|
-
* @param a The
|
|
143
|
-
* @param b The
|
|
144
|
-
* @returns `a
|
|
143
|
+
* @param a - The first non-negative integer
|
|
144
|
+
* @param b - The second non-negative integer
|
|
145
|
+
* @returns The difference of `a` and `b` as an `Uint16`
|
|
145
146
|
*/
|
|
146
147
|
sub,
|
|
147
148
|
|
|
148
149
|
/**
|
|
149
|
-
* Multiplies two Uint16
|
|
150
|
+
* Multiplies two non-negative integers, returning `a * b` as an `Uint16`.
|
|
150
151
|
*
|
|
151
|
-
* @param a The first
|
|
152
|
-
* @param b The second
|
|
153
|
-
* @returns `a
|
|
152
|
+
* @param a - The first non-negative integer
|
|
153
|
+
* @param b - The second non-negative integer
|
|
154
|
+
* @returns The product of `a` and `b` as an `Uint16`
|
|
154
155
|
*/
|
|
155
156
|
mul,
|
|
156
157
|
|
|
157
158
|
/**
|
|
158
|
-
* Divides
|
|
159
|
+
* Divides two non-negative integers using floor division (`⌊a / b⌋`): the
|
|
160
|
+
* result is `a / b` rounded toward negative infinity, as an `Uint16`.
|
|
159
161
|
*
|
|
160
|
-
* @param a The dividend
|
|
161
|
-
* @param b The divisor
|
|
162
|
-
* @returns
|
|
162
|
+
* @param a - The dividend
|
|
163
|
+
* @param b - The divisor (must be non-zero)
|
|
164
|
+
* @returns The floored quotient as an `Uint16`
|
|
163
165
|
*/
|
|
164
166
|
div,
|
|
165
167
|
} as const;
|