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