ts-data-forge 11.0.0 → 12.0.0
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 +2 -2
- 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 +71 -59
- package/dist/number/branded-types/int16.d.mts.map +1 -1
- package/dist/number/branded-types/int16.mjs +56 -47
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.d.mts +71 -59
- package/dist/number/branded-types/int32.d.mts.map +1 -1
- package/dist/number/branded-types/int32.mjs +56 -47
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +76 -60
- package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-finite-number.mjs +62 -49
- package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +66 -49
- package/dist/number/branded-types/negative-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-int.mjs +48 -39
- package/dist/number/branded-types/negative-int.mjs.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +64 -57
- package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-safe-int.mjs +49 -44
- package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +80 -65
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +65 -53
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +71 -58
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +55 -45
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +71 -59
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +55 -46
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +70 -55
- package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.mjs +55 -43
- package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts +46 -146
- package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-int.mjs +33 -108
- package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts +62 -54
- package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.mjs +46 -41
- 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 +59 -54
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +44 -41
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +59 -55
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +44 -42
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +60 -55
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +44 -42
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +59 -54
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +43 -41
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +59 -54
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +43 -41
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +82 -64
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +67 -52
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +53 -70
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +42 -52
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +68 -58
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int16.mjs +52 -45
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +68 -58
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int32.mjs +52 -45
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +72 -61
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +56 -48
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +68 -58
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +52 -45
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +68 -59
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +52 -46
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +52 -66
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +45 -47
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +68 -58
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +53 -46
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.d.mts +72 -55
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +52 -45
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +66 -59
- package/dist/number/branded-types/uint16.d.mts.map +1 -1
- package/dist/number/branded-types/uint16.mjs +51 -45
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +66 -57
- package/dist/number/branded-types/uint32.d.mts.map +1 -1
- package/dist/number/branded-types/uint32.mjs +50 -45
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.d.mts +62 -66
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/int8.mjs +57 -51
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.d.mts +66 -59
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/enum/uint8.mjs +57 -51
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/number/refined-number-utils.d.mts +9 -9
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +7 -7
- package/dist/number/refined-number-utils.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 +72 -60
- package/src/number/branded-types/int32.mts +72 -60
- package/src/number/branded-types/negative-finite-number.mts +78 -71
- package/src/number/branded-types/negative-finite-number.test.mts +4 -4
- package/src/number/branded-types/negative-int.mts +68 -60
- package/src/number/branded-types/negative-int.test.mts +5 -5
- package/src/number/branded-types/negative-safe-int.mts +66 -68
- package/src/number/branded-types/negative-safe-int.test.mts +4 -4
- package/src/number/branded-types/non-negative-finite-number.mts +81 -66
- package/src/number/branded-types/non-negative-int16.mts +72 -59
- package/src/number/branded-types/non-negative-int32.mts +72 -60
- package/src/number/branded-types/non-positive-finite-number.mts +71 -56
- package/src/number/branded-types/non-positive-finite-number.test.mts +7 -7
- package/src/number/branded-types/non-positive-int.mts +47 -147
- package/src/number/branded-types/non-positive-int.test.mts +7 -7
- package/src/number/branded-types/non-positive-safe-int.mts +63 -55
- package/src/number/branded-types/non-positive-safe-int.test.mts +7 -7
- 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 +60 -55
- package/src/number/branded-types/non-zero-int32.mts +60 -56
- package/src/number/branded-types/non-zero-safe-int.mts +61 -56
- package/src/number/branded-types/non-zero-uint16.mts +60 -55
- package/src/number/branded-types/non-zero-uint32.mts +60 -55
- package/src/number/branded-types/positive-finite-number.mts +83 -65
- package/src/number/branded-types/positive-int.mts +54 -71
- package/src/number/branded-types/positive-int16.mts +69 -59
- package/src/number/branded-types/positive-int32.mts +69 -59
- package/src/number/branded-types/positive-safe-int.mts +73 -62
- package/src/number/branded-types/positive-uint16.mts +69 -59
- package/src/number/branded-types/positive-uint32.mts +69 -60
- package/src/number/branded-types/safe-int.mts +53 -67
- package/src/number/branded-types/safe-uint.mts +69 -59
- package/src/number/branded-types/uint.mts +73 -56
- package/src/number/branded-types/uint16.mts +67 -60
- package/src/number/branded-types/uint32.mts +67 -58
- package/src/number/enum/int8.mts +70 -73
- package/src/number/enum/int8.test.mts +7 -4
- package/src/number/enum/uint8.mts +74 -66
- package/src/number/enum/uint8.test.mts +7 -4
- package/src/number/refined-number-utils.mts +22 -19
|
@@ -43,9 +43,9 @@ const Int = {
|
|
|
43
43
|
/**
|
|
44
44
|
* Returns the absolute value of an integer.
|
|
45
45
|
*
|
|
46
|
-
* The result is
|
|
47
|
-
* Math.abs(Number.MIN_SAFE_INTEGER) exceeds Number.MAX_SAFE_INTEGER
|
|
48
|
-
* SafeInt for guaranteed precision.
|
|
46
|
+
* The result is non-negative and keeps the `Int` brand. Note that
|
|
47
|
+
* `Math.abs(Number.MIN_SAFE_INTEGER)` exceeds `Number.MAX_SAFE_INTEGER`, so
|
|
48
|
+
* use `SafeInt` for guaranteed precision.
|
|
49
49
|
*
|
|
50
50
|
* @example
|
|
51
51
|
*
|
|
@@ -60,11 +60,11 @@ const Int = {
|
|
|
60
60
|
* ```
|
|
61
61
|
*
|
|
62
62
|
* @param a - The integer value
|
|
63
|
-
* @returns The absolute value as a non-negative Int
|
|
63
|
+
* @returns The absolute value as a non-negative `Int`
|
|
64
64
|
*/
|
|
65
65
|
abs,
|
|
66
66
|
/**
|
|
67
|
-
* Returns the
|
|
67
|
+
* Returns the smallest of the given integers.
|
|
68
68
|
*
|
|
69
69
|
* @example
|
|
70
70
|
*
|
|
@@ -75,11 +75,11 @@ const Int = {
|
|
|
75
75
|
* ```
|
|
76
76
|
*
|
|
77
77
|
* @param values - The integers to compare (at least one required)
|
|
78
|
-
* @returns The smallest value as an Int
|
|
78
|
+
* @returns The smallest value as an `Int`
|
|
79
79
|
*/
|
|
80
80
|
min: min_,
|
|
81
81
|
/**
|
|
82
|
-
* Returns the
|
|
82
|
+
* Returns the largest of the given integers.
|
|
83
83
|
*
|
|
84
84
|
* @example
|
|
85
85
|
*
|
|
@@ -90,14 +90,13 @@ const Int = {
|
|
|
90
90
|
* ```
|
|
91
91
|
*
|
|
92
92
|
* @param values - The integers to compare (at least one required)
|
|
93
|
-
* @returns The largest value as an Int
|
|
93
|
+
* @returns The largest value as an `Int`
|
|
94
94
|
*/
|
|
95
95
|
max: max_,
|
|
96
96
|
/**
|
|
97
|
-
* Generates a random
|
|
97
|
+
* Generates a random `Int` within the given range.
|
|
98
98
|
*
|
|
99
|
-
* The range is inclusive on both ends
|
|
100
|
-
* 2, 3, 4, 5, or 6.
|
|
99
|
+
* The range is inclusive on both ends.
|
|
101
100
|
*
|
|
102
101
|
* @example
|
|
103
102
|
*
|
|
@@ -115,11 +114,12 @@ const Int = {
|
|
|
115
114
|
*
|
|
116
115
|
* @param min - The minimum value (inclusive)
|
|
117
116
|
* @param max - The maximum value (inclusive)
|
|
118
|
-
* @returns A random Int in
|
|
117
|
+
* @returns A random `Int` in `[min, max]`
|
|
119
118
|
*/
|
|
120
119
|
random,
|
|
121
120
|
/**
|
|
122
|
-
* Raises an
|
|
121
|
+
* Raises `a` to the power `b`, returning `a ** b` as an `Int` (floored to an
|
|
122
|
+
* integer).
|
|
123
123
|
*
|
|
124
124
|
* @example
|
|
125
125
|
*
|
|
@@ -135,11 +135,11 @@ const Int = {
|
|
|
135
135
|
*
|
|
136
136
|
* @param a - The base integer
|
|
137
137
|
* @param b - The exponent integer
|
|
138
|
-
* @returns `a ** b` as an Int
|
|
138
|
+
* @returns `a ** b` as an `Int`
|
|
139
139
|
*/
|
|
140
140
|
pow,
|
|
141
141
|
/**
|
|
142
|
-
* Adds two integers
|
|
142
|
+
* Adds two integers, returning `a + b` as an `Int`.
|
|
143
143
|
*
|
|
144
144
|
* @example
|
|
145
145
|
*
|
|
@@ -149,13 +149,13 @@ const Int = {
|
|
|
149
149
|
* assert.isTrue(sum === 20);
|
|
150
150
|
* ```
|
|
151
151
|
*
|
|
152
|
-
* @param a -
|
|
153
|
-
* @param b -
|
|
154
|
-
* @returns `a
|
|
152
|
+
* @param a - The first integer
|
|
153
|
+
* @param b - The second integer
|
|
154
|
+
* @returns The sum of `a` and `b` as an `Int`
|
|
155
155
|
*/
|
|
156
156
|
add,
|
|
157
157
|
/**
|
|
158
|
-
* Subtracts two integers
|
|
158
|
+
* Subtracts two integers, returning `a - b` as an `Int`.
|
|
159
159
|
*
|
|
160
160
|
* @example
|
|
161
161
|
*
|
|
@@ -165,13 +165,13 @@ const Int = {
|
|
|
165
165
|
* assert.isTrue(difference === 4);
|
|
166
166
|
* ```
|
|
167
167
|
*
|
|
168
|
-
* @param a -
|
|
169
|
-
* @param b -
|
|
170
|
-
* @returns `a
|
|
168
|
+
* @param a - The first integer
|
|
169
|
+
* @param b - The second integer
|
|
170
|
+
* @returns The difference of `a` and `b` as an `Int`
|
|
171
171
|
*/
|
|
172
172
|
sub,
|
|
173
173
|
/**
|
|
174
|
-
* Multiplies two integers
|
|
174
|
+
* Multiplies two integers, returning `a * b` as an `Int`.
|
|
175
175
|
*
|
|
176
176
|
* @example
|
|
177
177
|
*
|
|
@@ -181,16 +181,14 @@ const Int = {
|
|
|
181
181
|
* assert.isTrue(product === -24);
|
|
182
182
|
* ```
|
|
183
183
|
*
|
|
184
|
-
* @param a -
|
|
185
|
-
* @param b -
|
|
186
|
-
* @returns `a
|
|
184
|
+
* @param a - The first integer
|
|
185
|
+
* @param b - The second integer
|
|
186
|
+
* @returns The product of `a` and `b` as an `Int`
|
|
187
187
|
*/
|
|
188
188
|
mul,
|
|
189
189
|
/**
|
|
190
|
-
* Divides two integers using floor division
|
|
191
|
-
*
|
|
192
|
-
* Performs mathematical floor division: `⌊a / b⌋`. The result is always an
|
|
193
|
-
* integer, rounding toward negative infinity.
|
|
190
|
+
* Divides two integers using floor division (`⌊a / b⌋`): the result is `a /
|
|
191
|
+
* b` rounded toward negative infinity, as an `Int`.
|
|
194
192
|
*
|
|
195
193
|
* @example
|
|
196
194
|
*
|
|
@@ -206,7 +204,7 @@ const Int = {
|
|
|
206
204
|
*
|
|
207
205
|
* @param a - The dividend
|
|
208
206
|
* @param b - The divisor (must be non-zero)
|
|
209
|
-
* @returns The
|
|
207
|
+
* @returns The floored quotient as an `Int`
|
|
210
208
|
*/
|
|
211
209
|
div
|
|
212
210
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"int.mjs","sources":["../../../src/number/branded-types/int.mts"],"sourcesContent":["import { type Int as TtfImported_Int } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Int = TtfImported_Int;\n\ntype ElementType = Int;\n\nconst typeNameInMessage = 'an integer';\n\nconst {\n abs,\n add,\n castType,\n div,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n number\n>({\n integerOrSafeInteger: 'Integer',\n MIN_VALUE: -Number.MAX_VALUE,\n MAX_VALUE: Number.MAX_VALUE,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is an integer.\n *\n * Returns `true`
|
|
1
|
+
{"version":3,"file":"int.mjs","sources":["../../../src/number/branded-types/int.mts"],"sourcesContent":["import { type Int as TtfImported_Int } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Int = TtfImported_Int;\n\ntype ElementType = Int;\n\nconst typeNameInMessage = 'an integer';\n\nconst {\n abs,\n add,\n castType,\n div,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n number\n>({\n integerOrSafeInteger: 'Integer',\n MIN_VALUE: -Number.MAX_VALUE,\n MAX_VALUE: Number.MAX_VALUE,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is an integer.\n *\n * Returns `true` for an integer — a value with no fractional component,\n * including values outside the safe integer range (unlike `SafeInt`).\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isInt(5));\n *\n * assert.isFalse(isInt(5.25));\n *\n * assert.isTrue(Int.is(-10));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is an integer, `false` otherwise\n */\nexport const isInt = is;\n\n/**\n * Casts a `number` to the `Int` branded type.\n *\n * Validates that the value is an integer and returns it with the `Int` brand.\n * Throws a `TypeError` otherwise.\n *\n * @example\n *\n * ```ts\n * const branded = asInt(42);\n *\n * assert.isTrue(branded === 42);\n *\n * assert.isTrue(Int.is(branded));\n * ```\n *\n * @param value - The value to cast\n * @returns The value as an `Int`\n * @throws {TypeError} If the value is not an integer\n */\nexport const asInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `Int` branded type.\n *\n * The `Int` type represents an integer. Division (`div`) uses floor division.\n *\n * Unlike `SafeInt`, `Int` allows values outside the safe integer range (±2^53 −\n * 1), so very large magnitudes may lose precision in JavaScript's `number`\n * type.\n */\nexport const Int = {\n /**\n * Type guard that checks if a value is an integer.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isInt(5));\n *\n * assert.isFalse(isInt(5.25));\n *\n * assert.isTrue(Int.is(-10));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is an integer, `false` otherwise\n * @see {@link isInt} for usage examples\n */\n is,\n\n /**\n * Returns the absolute value of an integer.\n *\n * The result is non-negative and keeps the `Int` brand. Note that\n * `Math.abs(Number.MIN_SAFE_INTEGER)` exceeds `Number.MAX_SAFE_INTEGER`, so\n * use `SafeInt` for guaranteed precision.\n *\n * @example\n *\n * ```ts\n * const negative = asInt(-12);\n *\n * const absolute = Int.abs(negative);\n *\n * assert.isTrue(absolute === 12);\n *\n * assert.isTrue(Int.is(absolute));\n * ```\n *\n * @param a - The integer value\n * @returns The absolute value as a non-negative `Int`\n */\n abs,\n\n /**\n * Returns the smallest of the given integers.\n *\n * @example\n *\n * ```ts\n * const smallest = Int.min(asInt(7), asInt(-3), asInt(2));\n *\n * assert.isTrue(smallest === -3);\n * ```\n *\n * @param values - The integers to compare (at least one required)\n * @returns The smallest value as an `Int`\n */\n min: min_,\n\n /**\n * Returns the largest of the given integers.\n *\n * @example\n *\n * ```ts\n * const largest = Int.max(asInt(7), asInt(-3), asInt(2));\n *\n * assert.isTrue(largest === 7);\n * ```\n *\n * @param values - The integers to compare (at least one required)\n * @returns The largest value as an `Int`\n */\n max: max_,\n\n /**\n * Generates a random `Int` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @example\n *\n * ```ts\n * const min = asInt(1);\n *\n * const max = asInt(6);\n *\n * const randomValue = Int.random(min, max);\n *\n * assert.isTrue(Int.is(randomValue));\n *\n * assert.isTrue(randomValue >= 1 && randomValue <= 6);\n * ```\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `Int` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as an `Int` (floored to an\n * integer).\n *\n * @example\n *\n * ```ts\n * const base = asInt(2);\n *\n * const exponent = asInt(5);\n *\n * const power = Int.pow(base, exponent);\n *\n * assert.isTrue(power === 32);\n * ```\n *\n * @param a - The base integer\n * @param b - The exponent integer\n * @returns `a ** b` as an `Int`\n */\n pow,\n\n /**\n * Adds two integers, returning `a + b` as an `Int`.\n *\n * @example\n *\n * ```ts\n * const sum = Int.add(asInt(12), asInt(8));\n *\n * assert.isTrue(sum === 20);\n * ```\n *\n * @param a - The first integer\n * @param b - The second integer\n * @returns The sum of `a` and `b` as an `Int`\n */\n add,\n\n /**\n * Subtracts two integers, returning `a - b` as an `Int`.\n *\n * @example\n *\n * ```ts\n * const difference = Int.sub(asInt(12), asInt(8));\n *\n * assert.isTrue(difference === 4);\n * ```\n *\n * @param a - The first integer\n * @param b - The second integer\n * @returns The difference of `a` and `b` as an `Int`\n */\n sub,\n\n /**\n * Multiplies two integers, returning `a * b` as an `Int`.\n *\n * @example\n *\n * ```ts\n * const product = Int.mul(asInt(-4), asInt(6));\n *\n * assert.isTrue(product === -24);\n * ```\n *\n * @param a - The first integer\n * @param b - The second integer\n * @returns The product of `a` and `b` as an `Int`\n */\n mul,\n\n /**\n * Divides two integers using floor division (`⌊a / b⌋`): the result is `a /\n * b` rounded toward negative infinity, as an `Int`.\n *\n * @example\n *\n * ```ts\n * const dividend = asInt(17);\n *\n * const divisor = asInt(5);\n *\n * const quotient = Int.div(dividend, divisor);\n *\n * assert.isTrue(quotient === 3);\n * ```\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as an `Int`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof Int,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<ElementType, 'int'>\n>('=');\n\nexpectType<\n typeof Int,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<ElementType, 'int'>\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,YAAA;AAE1B,MAAM;AAAA,EACJ,GAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,GAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,SAAA;AAAA,EACtB,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB,WAAW,MAAA,CAAO,SAAA;AAAA,EAClB;AACF,CAAU,CAAA;AAqBH,MAAM,KAAA,GAAQ;AAsBd,MAAM,KAAA,GAAQ;AAWd,MAAM,GAAA,GAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBjB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBL,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBA;AACF;;;;"}
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { type Int16 as TtfImported_Int16 } from 'ts-type-forge';
|
|
2
2
|
export type Int16 = TtfImported_Int16;
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* 2^15)).
|
|
4
|
+
* Type guard that checks if a value is an integer in [-2^15, 2^15).
|
|
6
5
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Returns `true` for an integer in [-2^15, 2^15) — a value with no fractional
|
|
7
|
+
* component.
|
|
8
|
+
*
|
|
9
|
+
* @param value - The value to check
|
|
10
|
+
* @returns `true` if the value is an integer in [-2^15, 2^15), `false` otherwise
|
|
9
11
|
*/
|
|
10
12
|
export declare const isInt16: (a: number) => a is TtfImported_Int16;
|
|
11
13
|
/**
|
|
12
|
-
* Casts a number to
|
|
14
|
+
* Casts a `number` to the `Int16` branded type.
|
|
15
|
+
*
|
|
16
|
+
* Validates that the value is an integer in [-2^15, 2^15) and returns it with
|
|
17
|
+
* the `Int16` brand. Throws a `TypeError` otherwise.
|
|
13
18
|
*
|
|
14
|
-
* @param value The value to cast
|
|
15
|
-
* @returns The value as an Int16
|
|
16
|
-
* @throws {TypeError} If the value is not an integer in [-2^15, 2^15)
|
|
19
|
+
* @param value - The value to cast
|
|
20
|
+
* @returns The value as an `Int16`
|
|
21
|
+
* @throws {TypeError} If the value is not an integer in [-2^15, 2^15)
|
|
17
22
|
*/
|
|
18
23
|
export declare const asInt16: <N extends number>(x: N) => number & {
|
|
19
24
|
readonly "< 2^15": true;
|
|
@@ -32,107 +37,114 @@ export declare const asInt16: <N extends number>(x: N) => number & {
|
|
|
32
37
|
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
33
38
|
}> & N;
|
|
34
39
|
/**
|
|
35
|
-
* Namespace providing type-safe
|
|
36
|
-
* integers.
|
|
40
|
+
* Namespace providing type-safe operations for the `Int16` branded type.
|
|
37
41
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* constraint.
|
|
42
|
+
* The `Int16` type represents an integer in [-2^15, 2^15). Division (`div`)
|
|
43
|
+
* uses floor division.
|
|
41
44
|
*/
|
|
42
45
|
export declare const Int16: {
|
|
43
46
|
/**
|
|
44
|
-
* Type guard
|
|
47
|
+
* Type guard that checks if a value is an integer in [-2^15, 2^15).
|
|
45
48
|
*
|
|
46
|
-
* @param value The value to check
|
|
47
|
-
* @returns `true` if the value is
|
|
49
|
+
* @param value - The value to check
|
|
50
|
+
* @returns `true` if the value is an integer in [-2^15, 2^15), `false` otherwise
|
|
51
|
+
* @see {@link isInt16} for usage examples
|
|
48
52
|
*/
|
|
49
53
|
readonly is: (a: number) => a is TtfImported_Int16;
|
|
50
54
|
/**
|
|
51
|
-
* The
|
|
52
|
-
*
|
|
53
|
-
* @readonly
|
|
55
|
+
* The smallest value representable as `Int16` (the lower saturation target of
|
|
56
|
+
* `fromNumber`).
|
|
54
57
|
*/
|
|
55
58
|
readonly MIN_VALUE: number;
|
|
56
59
|
/**
|
|
57
|
-
* The
|
|
58
|
-
*
|
|
59
|
-
* @readonly
|
|
60
|
+
* The largest value representable as `Int16` (the upper saturation target of
|
|
61
|
+
* `fromNumber`).
|
|
60
62
|
*/
|
|
61
63
|
readonly MAX_VALUE: number;
|
|
62
64
|
/**
|
|
63
|
-
* Returns the absolute value of
|
|
65
|
+
* Returns the absolute value of an integer in [-2^15, 2^15).
|
|
64
66
|
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
+
* The result is non-negative and keeps the `Int16` brand.
|
|
68
|
+
*
|
|
69
|
+
* @param a - The integer value
|
|
70
|
+
* @returns The absolute value as a non-negative `Int16`
|
|
67
71
|
*/
|
|
68
72
|
readonly abs: (x: import("ts-type-forge").WithSmallInt<TtfImported_Int16>) => import("ts-type-forge").IntersectBrand<TtfImported_Int16, import("ts-type-forge").NonNegativeNumber>;
|
|
69
73
|
/**
|
|
70
|
-
* Returns the
|
|
74
|
+
* Returns the smallest of the given integers.
|
|
71
75
|
*
|
|
72
|
-
* @param
|
|
73
|
-
* @
|
|
74
|
-
* @returns The minimum value as an Int16.
|
|
76
|
+
* @param values - The integers to compare (at least one required)
|
|
77
|
+
* @returns The smallest value as an `Int16`
|
|
75
78
|
*/
|
|
76
79
|
readonly min: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_Int16>[]) => TtfImported_Int16;
|
|
77
80
|
/**
|
|
78
|
-
* Returns the
|
|
81
|
+
* Returns the largest of the given integers.
|
|
79
82
|
*
|
|
80
|
-
* @param
|
|
81
|
-
* @
|
|
82
|
-
* @returns The maximum value as an Int16.
|
|
83
|
+
* @param values - The integers to compare (at least one required)
|
|
84
|
+
* @returns The largest value as an `Int16`
|
|
83
85
|
*/
|
|
84
86
|
readonly max: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_Int16>[]) => TtfImported_Int16;
|
|
85
87
|
/**
|
|
86
|
-
*
|
|
88
|
+
* Converts an arbitrary `number` into an `Int16`, rounding to the nearest
|
|
89
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
90
|
+
*
|
|
91
|
+
* Unlike `asInt16`, this is total: out-of-range inputs are clamped to the
|
|
92
|
+
* nearest representable `Int16` instead of throwing.
|
|
87
93
|
*
|
|
88
|
-
* @param value The
|
|
89
|
-
* @returns The value
|
|
94
|
+
* @param value - The value to convert
|
|
95
|
+
* @returns The value as an `Int16`
|
|
90
96
|
*/
|
|
91
|
-
readonly
|
|
97
|
+
readonly fromNumber: (x: number) => TtfImported_Int16;
|
|
92
98
|
/**
|
|
93
|
-
* Generates a random Int16
|
|
99
|
+
* Generates a random `Int16` within the given range.
|
|
100
|
+
*
|
|
101
|
+
* The range is inclusive on both ends.
|
|
94
102
|
*
|
|
95
|
-
* @
|
|
103
|
+
* @param min - The minimum value (inclusive)
|
|
104
|
+
* @param max - The maximum value (inclusive)
|
|
105
|
+
* @returns A random `Int16` in `[min, max]`
|
|
96
106
|
*/
|
|
97
107
|
readonly random: (min?: import("ts-type-forge").WithSmallInt<TtfImported_Int16> | undefined, max?: import("ts-type-forge").WithSmallInt<TtfImported_Int16> | undefined) => TtfImported_Int16;
|
|
98
108
|
/**
|
|
99
|
-
* Raises
|
|
109
|
+
* Raises `a` to the power `b`, returning `a ** b` as an `Int16` (floored to
|
|
110
|
+
* an integer).
|
|
100
111
|
*
|
|
101
|
-
* @param a The base
|
|
102
|
-
* @param b The exponent
|
|
103
|
-
* @returns `a ** b`
|
|
112
|
+
* @param a - The base integer
|
|
113
|
+
* @param b - The exponent integer
|
|
114
|
+
* @returns `a ** b` as an `Int16`
|
|
104
115
|
*/
|
|
105
116
|
readonly pow: (x: import("ts-type-forge").WithSmallInt<TtfImported_Int16>, y: import("ts-type-forge").WithSmallInt<TtfImported_Int16>) => TtfImported_Int16;
|
|
106
117
|
/**
|
|
107
|
-
* Adds two Int16
|
|
118
|
+
* Adds two integers, returning `a + b` as an `Int16`.
|
|
108
119
|
*
|
|
109
|
-
* @param a The first
|
|
110
|
-
* @param b The second
|
|
111
|
-
* @returns `a
|
|
120
|
+
* @param a - The first integer
|
|
121
|
+
* @param b - The second integer
|
|
122
|
+
* @returns The sum of `a` and `b` as an `Int16`
|
|
112
123
|
*/
|
|
113
124
|
readonly add: (x: import("ts-type-forge").WithSmallInt<TtfImported_Int16>, y: import("ts-type-forge").WithSmallInt<TtfImported_Int16>) => TtfImported_Int16;
|
|
114
125
|
/**
|
|
115
|
-
* Subtracts
|
|
126
|
+
* Subtracts two integers, returning `a - b` as an `Int16`.
|
|
116
127
|
*
|
|
117
|
-
* @param a The
|
|
118
|
-
* @param b The
|
|
119
|
-
* @returns `a
|
|
128
|
+
* @param a - The first integer
|
|
129
|
+
* @param b - The second integer
|
|
130
|
+
* @returns The difference of `a` and `b` as an `Int16`
|
|
120
131
|
*/
|
|
121
132
|
readonly sub: (x: import("ts-type-forge").WithSmallInt<TtfImported_Int16>, y: import("ts-type-forge").WithSmallInt<TtfImported_Int16>) => TtfImported_Int16;
|
|
122
133
|
/**
|
|
123
|
-
* Multiplies two Int16
|
|
134
|
+
* Multiplies two integers, returning `a * b` as an `Int16`.
|
|
124
135
|
*
|
|
125
|
-
* @param a The first
|
|
126
|
-
* @param b The second
|
|
127
|
-
* @returns `a
|
|
136
|
+
* @param a - The first integer
|
|
137
|
+
* @param b - The second integer
|
|
138
|
+
* @returns The product of `a` and `b` as an `Int16`
|
|
128
139
|
*/
|
|
129
140
|
readonly mul: (x: import("ts-type-forge").WithSmallInt<TtfImported_Int16>, y: import("ts-type-forge").WithSmallInt<TtfImported_Int16>) => TtfImported_Int16;
|
|
130
141
|
/**
|
|
131
|
-
* Divides
|
|
142
|
+
* Divides two integers using floor division (`⌊a / b⌋`): the result is `a /
|
|
143
|
+
* b` rounded toward negative infinity, as an `Int16`.
|
|
132
144
|
*
|
|
133
|
-
* @param a The dividend
|
|
134
|
-
* @param b The divisor
|
|
135
|
-
* @returns
|
|
145
|
+
* @param a - The dividend
|
|
146
|
+
* @param b - The divisor (must be non-zero)
|
|
147
|
+
* @returns The floored quotient as an `Int16`
|
|
136
148
|
*/
|
|
137
149
|
readonly div: (x: import("ts-type-forge").WithSmallInt<TtfImported_Int16>, y: -40 | -39 | -38 | -37 | -36 | -35 | -34 | -33 | -32 | -31 | -30 | -29 | -28 | -27 | -26 | -25 | -24 | -23 | -22 | -21 | -20 | -19 | -18 | -17 | -16 | -15 | -14 | -13 | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | import("ts-type-forge").NormalizeBrandUnion<number & {
|
|
138
150
|
readonly "!=0": true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"int16.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/int16.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAIhE,MAAM,MAAM,KAAK,GAAG,iBAAiB,CAAC;AAgCtC
|
|
1
|
+
{"version":3,"file":"int16.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/int16.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAIhE,MAAM,MAAM,KAAK,GAAG,iBAAiB,CAAC;AAgCtC;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,uCAAK,CAAC;AAE1B;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;MAAW,CAAC;AAEhC;;;;;GAKG;AACH,eAAO,MAAM,KAAK;IAChB;;;;;;OAMG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;;;OAOG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;;;;;;;;;;;;;;;;;CAEK,CAAC"}
|
|
@@ -7,8 +7,8 @@ const {
|
|
|
7
7
|
abs,
|
|
8
8
|
add,
|
|
9
9
|
castType,
|
|
10
|
-
clamp,
|
|
11
10
|
div,
|
|
11
|
+
fromNumber,
|
|
12
12
|
is,
|
|
13
13
|
max: max_,
|
|
14
14
|
min: min_,
|
|
@@ -26,98 +26,107 @@ const isInt16 = is;
|
|
|
26
26
|
const asInt16 = castType;
|
|
27
27
|
const Int16 = {
|
|
28
28
|
/**
|
|
29
|
-
* Type guard
|
|
29
|
+
* Type guard that checks if a value is an integer in [-2^15, 2^15).
|
|
30
30
|
*
|
|
31
|
-
* @param value The value to check
|
|
32
|
-
* @returns `true` if the value is
|
|
31
|
+
* @param value - The value to check
|
|
32
|
+
* @returns `true` if the value is an integer in [-2^15, 2^15), `false` otherwise
|
|
33
|
+
* @see {@link isInt16} for usage examples
|
|
33
34
|
*/
|
|
34
35
|
is,
|
|
35
36
|
/**
|
|
36
|
-
* The
|
|
37
|
-
*
|
|
38
|
-
* @readonly
|
|
37
|
+
* The smallest value representable as `Int16` (the lower saturation target of
|
|
38
|
+
* `fromNumber`).
|
|
39
39
|
*/
|
|
40
40
|
MIN_VALUE,
|
|
41
41
|
/**
|
|
42
|
-
* The
|
|
43
|
-
*
|
|
44
|
-
* @readonly
|
|
42
|
+
* The largest value representable as `Int16` (the upper saturation target of
|
|
43
|
+
* `fromNumber`).
|
|
45
44
|
*/
|
|
46
45
|
MAX_VALUE,
|
|
47
46
|
/**
|
|
48
|
-
* Returns the absolute value of
|
|
47
|
+
* Returns the absolute value of an integer in [-2^15, 2^15).
|
|
48
|
+
*
|
|
49
|
+
* The result is non-negative and keeps the `Int16` brand.
|
|
49
50
|
*
|
|
50
|
-
* @param a The
|
|
51
|
-
* @returns The absolute value as
|
|
51
|
+
* @param a - The integer value
|
|
52
|
+
* @returns The absolute value as a non-negative `Int16`
|
|
52
53
|
*/
|
|
53
54
|
abs,
|
|
54
55
|
/**
|
|
55
|
-
* Returns the
|
|
56
|
+
* Returns the smallest of the given integers.
|
|
56
57
|
*
|
|
57
|
-
* @param
|
|
58
|
-
* @
|
|
59
|
-
* @returns The minimum value as an Int16.
|
|
58
|
+
* @param values - The integers to compare (at least one required)
|
|
59
|
+
* @returns The smallest value as an `Int16`
|
|
60
60
|
*/
|
|
61
61
|
min: min_,
|
|
62
62
|
/**
|
|
63
|
-
* Returns the
|
|
63
|
+
* Returns the largest of the given integers.
|
|
64
64
|
*
|
|
65
|
-
* @param
|
|
66
|
-
* @
|
|
67
|
-
* @returns The maximum value as an Int16.
|
|
65
|
+
* @param values - The integers to compare (at least one required)
|
|
66
|
+
* @returns The largest value as an `Int16`
|
|
68
67
|
*/
|
|
69
68
|
max: max_,
|
|
70
69
|
/**
|
|
71
|
-
*
|
|
70
|
+
* Converts an arbitrary `number` into an `Int16`, rounding to the nearest
|
|
71
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
72
72
|
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
73
|
+
* Unlike `asInt16`, this is total: out-of-range inputs are clamped to the
|
|
74
|
+
* nearest representable `Int16` instead of throwing.
|
|
75
|
+
*
|
|
76
|
+
* @param value - The value to convert
|
|
77
|
+
* @returns The value as an `Int16`
|
|
75
78
|
*/
|
|
76
|
-
|
|
79
|
+
fromNumber,
|
|
77
80
|
/**
|
|
78
|
-
* Generates a random Int16
|
|
81
|
+
* Generates a random `Int16` within the given range.
|
|
82
|
+
*
|
|
83
|
+
* The range is inclusive on both ends.
|
|
79
84
|
*
|
|
80
|
-
* @
|
|
85
|
+
* @param min - The minimum value (inclusive)
|
|
86
|
+
* @param max - The maximum value (inclusive)
|
|
87
|
+
* @returns A random `Int16` in `[min, max]`
|
|
81
88
|
*/
|
|
82
89
|
random,
|
|
83
90
|
/**
|
|
84
|
-
* Raises
|
|
91
|
+
* Raises `a` to the power `b`, returning `a ** b` as an `Int16` (floored to
|
|
92
|
+
* an integer).
|
|
85
93
|
*
|
|
86
|
-
* @param a The base
|
|
87
|
-
* @param b The exponent
|
|
88
|
-
* @returns `a ** b`
|
|
94
|
+
* @param a - The base integer
|
|
95
|
+
* @param b - The exponent integer
|
|
96
|
+
* @returns `a ** b` as an `Int16`
|
|
89
97
|
*/
|
|
90
98
|
pow,
|
|
91
99
|
/**
|
|
92
|
-
* Adds two Int16
|
|
100
|
+
* Adds two integers, returning `a + b` as an `Int16`.
|
|
93
101
|
*
|
|
94
|
-
* @param a The first
|
|
95
|
-
* @param b The second
|
|
96
|
-
* @returns `a
|
|
102
|
+
* @param a - The first integer
|
|
103
|
+
* @param b - The second integer
|
|
104
|
+
* @returns The sum of `a` and `b` as an `Int16`
|
|
97
105
|
*/
|
|
98
106
|
add,
|
|
99
107
|
/**
|
|
100
|
-
* Subtracts
|
|
108
|
+
* Subtracts two integers, returning `a - b` as an `Int16`.
|
|
101
109
|
*
|
|
102
|
-
* @param a The
|
|
103
|
-
* @param b The
|
|
104
|
-
* @returns `a
|
|
110
|
+
* @param a - The first integer
|
|
111
|
+
* @param b - The second integer
|
|
112
|
+
* @returns The difference of `a` and `b` as an `Int16`
|
|
105
113
|
*/
|
|
106
114
|
sub,
|
|
107
115
|
/**
|
|
108
|
-
* Multiplies two Int16
|
|
116
|
+
* Multiplies two integers, returning `a * b` as an `Int16`.
|
|
109
117
|
*
|
|
110
|
-
* @param a The first
|
|
111
|
-
* @param b The second
|
|
112
|
-
* @returns `a
|
|
118
|
+
* @param a - The first integer
|
|
119
|
+
* @param b - The second integer
|
|
120
|
+
* @returns The product of `a` and `b` as an `Int16`
|
|
113
121
|
*/
|
|
114
122
|
mul,
|
|
115
123
|
/**
|
|
116
|
-
* Divides
|
|
124
|
+
* Divides two integers using floor division (`⌊a / b⌋`): the result is `a /
|
|
125
|
+
* b` rounded toward negative infinity, as an `Int16`.
|
|
117
126
|
*
|
|
118
|
-
* @param a The dividend
|
|
119
|
-
* @param b The divisor
|
|
120
|
-
* @returns
|
|
127
|
+
* @param a - The dividend
|
|
128
|
+
* @param b - The divisor (must be non-zero)
|
|
129
|
+
* @returns The floored quotient as an `Int16`
|
|
121
130
|
*/
|
|
122
131
|
div
|
|
123
132
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"int16.mjs","sources":["../../../src/number/branded-types/int16.mts"],"sourcesContent":["import { type Int16 as TtfImported_Int16 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Int16 = TtfImported_Int16;\n\ntype ElementType = Int16;\n\nconst typeNameInMessage = 'an integer in [-2^15, 2^15)';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n abs,\n add,\n castType,\n
|
|
1
|
+
{"version":3,"file":"int16.mjs","sources":["../../../src/number/branded-types/int16.mts"],"sourcesContent":["import { type Int16 as TtfImported_Int16 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Int16 = TtfImported_Int16;\n\ntype ElementType = Int16;\n\nconst typeNameInMessage = 'an integer in [-2^15, 2^15)';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n abs,\n add,\n castType,\n div,\n fromNumber,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n number\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: -(2 ** 15),\n MAX_VALUE: 2 ** 15 - 1,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is an integer in [-2^15, 2^15).\n *\n * Returns `true` for an integer in [-2^15, 2^15) — a value with no fractional\n * component.\n *\n * @param value - The value to check\n * @returns `true` if the value is an integer in [-2^15, 2^15), `false` otherwise\n */\nexport const isInt16 = is;\n\n/**\n * Casts a `number` to the `Int16` branded type.\n *\n * Validates that the value is an integer in [-2^15, 2^15) and returns it with\n * the `Int16` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as an `Int16`\n * @throws {TypeError} If the value is not an integer in [-2^15, 2^15)\n */\nexport const asInt16 = castType;\n\n/**\n * Namespace providing type-safe operations for the `Int16` branded type.\n *\n * The `Int16` type represents an integer in [-2^15, 2^15). Division (`div`)\n * uses floor division.\n */\nexport const Int16 = {\n /**\n * Type guard that checks if a value is an integer in [-2^15, 2^15).\n *\n * @param value - The value to check\n * @returns `true` if the value is an integer in [-2^15, 2^15), `false` otherwise\n * @see {@link isInt16} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `Int16` (the lower saturation target of\n * `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `Int16` (the upper saturation target of\n * `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of an integer in [-2^15, 2^15).\n *\n * The result is non-negative and keeps the `Int16` brand.\n *\n * @param a - The integer value\n * @returns The absolute value as a non-negative `Int16`\n */\n abs,\n\n /**\n * Returns the smallest of the given integers.\n *\n * @param values - The integers to compare (at least one required)\n * @returns The smallest value as an `Int16`\n */\n min: min_,\n\n /**\n * Returns the largest of the given integers.\n *\n * @param values - The integers to compare (at least one required)\n * @returns The largest value as an `Int16`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into an `Int16`, rounding to the nearest\n * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asInt16`, this is total: out-of-range inputs are clamped to the\n * nearest representable `Int16` instead of throwing.\n *\n * @param value - The value to convert\n * @returns The value as an `Int16`\n */\n fromNumber,\n\n /**\n * Generates a random `Int16` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `Int16` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as an `Int16` (floored to\n * an integer).\n *\n * @param a - The base integer\n * @param b - The exponent integer\n * @returns `a ** b` as an `Int16`\n */\n pow,\n\n /**\n * Adds two integers, returning `a + b` as an `Int16`.\n *\n * @param a - The first integer\n * @param b - The second integer\n * @returns The sum of `a` and `b` as an `Int16`\n */\n add,\n\n /**\n * Subtracts two integers, returning `a - b` as an `Int16`.\n *\n * @param a - The first integer\n * @param b - The second integer\n * @returns The difference of `a` and `b` as an `Int16`\n */\n sub,\n\n /**\n * Multiplies two integers, returning `a * b` as an `Int16`.\n *\n * @param a - The first integer\n * @param b - The second integer\n * @returns The product of `a` and `b` as an `Int16`\n */\n mul,\n\n /**\n * Divides two integers using floor division (`⌊a / b⌋`): the result is `a /\n * b` rounded toward negative infinity, as an `Int16`.\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as an `Int16`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof Int16,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'range'\n >\n>('=');\n\nexpectType<\n typeof Int16,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'range'\n >\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,6BAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,GAAA;AAAA,EACA,UAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA,EACtB,SAAA,EAAW,MAAO;AAAA,EAClB,SAAA,EAAW,KAAK,EAAA,GAAK,CAAA;AAAA,EACrB;AACF,CAAU,CAAA;AAWH,MAAM,OAAA,GAAU;AAYhB,MAAM,OAAA,GAAU;AAQhB,MAAM,KAAA,GAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQnB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYL,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
|