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.
Files changed (185) hide show
  1. package/README.md +2 -2
  2. package/dist/number/branded-types/finite-number.d.mts +47 -61
  3. package/dist/number/branded-types/finite-number.d.mts.map +1 -1
  4. package/dist/number/branded-types/finite-number.mjs +37 -41
  5. package/dist/number/branded-types/finite-number.mjs.map +1 -1
  6. package/dist/number/branded-types/int.d.mts +40 -46
  7. package/dist/number/branded-types/int.d.mts.map +1 -1
  8. package/dist/number/branded-types/int.mjs +29 -31
  9. package/dist/number/branded-types/int.mjs.map +1 -1
  10. package/dist/number/branded-types/int16.d.mts +71 -59
  11. package/dist/number/branded-types/int16.d.mts.map +1 -1
  12. package/dist/number/branded-types/int16.mjs +56 -47
  13. package/dist/number/branded-types/int16.mjs.map +1 -1
  14. package/dist/number/branded-types/int32.d.mts +71 -59
  15. package/dist/number/branded-types/int32.d.mts.map +1 -1
  16. package/dist/number/branded-types/int32.mjs +56 -47
  17. package/dist/number/branded-types/int32.mjs.map +1 -1
  18. package/dist/number/branded-types/negative-finite-number.d.mts +76 -60
  19. package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
  20. package/dist/number/branded-types/negative-finite-number.mjs +62 -49
  21. package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
  22. package/dist/number/branded-types/negative-int.d.mts +66 -49
  23. package/dist/number/branded-types/negative-int.d.mts.map +1 -1
  24. package/dist/number/branded-types/negative-int.mjs +48 -39
  25. package/dist/number/branded-types/negative-int.mjs.map +1 -1
  26. package/dist/number/branded-types/negative-safe-int.d.mts +64 -57
  27. package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
  28. package/dist/number/branded-types/negative-safe-int.mjs +49 -44
  29. package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
  30. package/dist/number/branded-types/non-negative-finite-number.d.mts +80 -65
  31. package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
  32. package/dist/number/branded-types/non-negative-finite-number.mjs +65 -53
  33. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
  34. package/dist/number/branded-types/non-negative-int16.d.mts +71 -58
  35. package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
  36. package/dist/number/branded-types/non-negative-int16.mjs +55 -45
  37. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
  38. package/dist/number/branded-types/non-negative-int32.d.mts +71 -59
  39. package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
  40. package/dist/number/branded-types/non-negative-int32.mjs +55 -46
  41. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
  42. package/dist/number/branded-types/non-positive-finite-number.d.mts +70 -55
  43. package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
  44. package/dist/number/branded-types/non-positive-finite-number.mjs +55 -43
  45. package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
  46. package/dist/number/branded-types/non-positive-int.d.mts +46 -146
  47. package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
  48. package/dist/number/branded-types/non-positive-int.mjs +33 -108
  49. package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
  50. package/dist/number/branded-types/non-positive-safe-int.d.mts +62 -54
  51. package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
  52. package/dist/number/branded-types/non-positive-safe-int.mjs +46 -41
  53. package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
  54. package/dist/number/branded-types/non-zero-finite-number.d.mts +62 -49
  55. package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
  56. package/dist/number/branded-types/non-zero-finite-number.mjs +46 -37
  57. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
  58. package/dist/number/branded-types/non-zero-int.d.mts +51 -38
  59. package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
  60. package/dist/number/branded-types/non-zero-int.mjs +31 -27
  61. package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
  62. package/dist/number/branded-types/non-zero-int16.d.mts +59 -54
  63. package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
  64. package/dist/number/branded-types/non-zero-int16.mjs +44 -41
  65. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
  66. package/dist/number/branded-types/non-zero-int32.d.mts +59 -55
  67. package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
  68. package/dist/number/branded-types/non-zero-int32.mjs +44 -42
  69. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
  70. package/dist/number/branded-types/non-zero-safe-int.d.mts +60 -55
  71. package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
  72. package/dist/number/branded-types/non-zero-safe-int.mjs +44 -42
  73. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
  74. package/dist/number/branded-types/non-zero-uint16.d.mts +59 -54
  75. package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
  76. package/dist/number/branded-types/non-zero-uint16.mjs +43 -41
  77. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
  78. package/dist/number/branded-types/non-zero-uint32.d.mts +59 -54
  79. package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
  80. package/dist/number/branded-types/non-zero-uint32.mjs +43 -41
  81. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
  82. package/dist/number/branded-types/positive-finite-number.d.mts +82 -64
  83. package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
  84. package/dist/number/branded-types/positive-finite-number.mjs +67 -52
  85. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
  86. package/dist/number/branded-types/positive-int.d.mts +53 -70
  87. package/dist/number/branded-types/positive-int.d.mts.map +1 -1
  88. package/dist/number/branded-types/positive-int.mjs +42 -52
  89. package/dist/number/branded-types/positive-int.mjs.map +1 -1
  90. package/dist/number/branded-types/positive-int16.d.mts +68 -58
  91. package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
  92. package/dist/number/branded-types/positive-int16.mjs +52 -45
  93. package/dist/number/branded-types/positive-int16.mjs.map +1 -1
  94. package/dist/number/branded-types/positive-int32.d.mts +68 -58
  95. package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
  96. package/dist/number/branded-types/positive-int32.mjs +52 -45
  97. package/dist/number/branded-types/positive-int32.mjs.map +1 -1
  98. package/dist/number/branded-types/positive-safe-int.d.mts +72 -61
  99. package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
  100. package/dist/number/branded-types/positive-safe-int.mjs +56 -48
  101. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
  102. package/dist/number/branded-types/positive-uint16.d.mts +68 -58
  103. package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
  104. package/dist/number/branded-types/positive-uint16.mjs +52 -45
  105. package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
  106. package/dist/number/branded-types/positive-uint32.d.mts +68 -59
  107. package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
  108. package/dist/number/branded-types/positive-uint32.mjs +52 -46
  109. package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
  110. package/dist/number/branded-types/safe-int.d.mts +52 -66
  111. package/dist/number/branded-types/safe-int.d.mts.map +1 -1
  112. package/dist/number/branded-types/safe-int.mjs +45 -47
  113. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  114. package/dist/number/branded-types/safe-uint.d.mts +68 -58
  115. package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
  116. package/dist/number/branded-types/safe-uint.mjs +53 -46
  117. package/dist/number/branded-types/safe-uint.mjs.map +1 -1
  118. package/dist/number/branded-types/uint.d.mts +72 -55
  119. package/dist/number/branded-types/uint.d.mts.map +1 -1
  120. package/dist/number/branded-types/uint.mjs +52 -45
  121. package/dist/number/branded-types/uint.mjs.map +1 -1
  122. package/dist/number/branded-types/uint16.d.mts +66 -59
  123. package/dist/number/branded-types/uint16.d.mts.map +1 -1
  124. package/dist/number/branded-types/uint16.mjs +51 -45
  125. package/dist/number/branded-types/uint16.mjs.map +1 -1
  126. package/dist/number/branded-types/uint32.d.mts +66 -57
  127. package/dist/number/branded-types/uint32.d.mts.map +1 -1
  128. package/dist/number/branded-types/uint32.mjs +50 -45
  129. package/dist/number/branded-types/uint32.mjs.map +1 -1
  130. package/dist/number/enum/int8.d.mts +62 -66
  131. package/dist/number/enum/int8.d.mts.map +1 -1
  132. package/dist/number/enum/int8.mjs +57 -51
  133. package/dist/number/enum/int8.mjs.map +1 -1
  134. package/dist/number/enum/uint8.d.mts +66 -59
  135. package/dist/number/enum/uint8.d.mts.map +1 -1
  136. package/dist/number/enum/uint8.mjs +57 -51
  137. package/dist/number/enum/uint8.mjs.map +1 -1
  138. package/dist/number/refined-number-utils.d.mts +9 -9
  139. package/dist/number/refined-number-utils.d.mts.map +1 -1
  140. package/dist/number/refined-number-utils.mjs +7 -7
  141. package/dist/number/refined-number-utils.mjs.map +1 -1
  142. package/package.json +2 -1
  143. package/src/number/branded-types/finite-number.mts +47 -61
  144. package/src/number/branded-types/int.mts +40 -46
  145. package/src/number/branded-types/int16.mts +72 -60
  146. package/src/number/branded-types/int32.mts +72 -60
  147. package/src/number/branded-types/negative-finite-number.mts +78 -71
  148. package/src/number/branded-types/negative-finite-number.test.mts +4 -4
  149. package/src/number/branded-types/negative-int.mts +68 -60
  150. package/src/number/branded-types/negative-int.test.mts +5 -5
  151. package/src/number/branded-types/negative-safe-int.mts +66 -68
  152. package/src/number/branded-types/negative-safe-int.test.mts +4 -4
  153. package/src/number/branded-types/non-negative-finite-number.mts +81 -66
  154. package/src/number/branded-types/non-negative-int16.mts +72 -59
  155. package/src/number/branded-types/non-negative-int32.mts +72 -60
  156. package/src/number/branded-types/non-positive-finite-number.mts +71 -56
  157. package/src/number/branded-types/non-positive-finite-number.test.mts +7 -7
  158. package/src/number/branded-types/non-positive-int.mts +47 -147
  159. package/src/number/branded-types/non-positive-int.test.mts +7 -7
  160. package/src/number/branded-types/non-positive-safe-int.mts +63 -55
  161. package/src/number/branded-types/non-positive-safe-int.test.mts +7 -7
  162. package/src/number/branded-types/non-zero-finite-number.mts +62 -51
  163. package/src/number/branded-types/non-zero-int.mts +51 -38
  164. package/src/number/branded-types/non-zero-int16.mts +60 -55
  165. package/src/number/branded-types/non-zero-int32.mts +60 -56
  166. package/src/number/branded-types/non-zero-safe-int.mts +61 -56
  167. package/src/number/branded-types/non-zero-uint16.mts +60 -55
  168. package/src/number/branded-types/non-zero-uint32.mts +60 -55
  169. package/src/number/branded-types/positive-finite-number.mts +83 -65
  170. package/src/number/branded-types/positive-int.mts +54 -71
  171. package/src/number/branded-types/positive-int16.mts +69 -59
  172. package/src/number/branded-types/positive-int32.mts +69 -59
  173. package/src/number/branded-types/positive-safe-int.mts +73 -62
  174. package/src/number/branded-types/positive-uint16.mts +69 -59
  175. package/src/number/branded-types/positive-uint32.mts +69 -60
  176. package/src/number/branded-types/safe-int.mts +53 -67
  177. package/src/number/branded-types/safe-uint.mts +69 -59
  178. package/src/number/branded-types/uint.mts +73 -56
  179. package/src/number/branded-types/uint16.mts +67 -60
  180. package/src/number/branded-types/uint32.mts +67 -58
  181. package/src/number/enum/int8.mts +70 -73
  182. package/src/number/enum/int8.test.mts +7 -4
  183. package/src/number/enum/uint8.mts +74 -66
  184. package/src/number/enum/uint8.test.mts +7 -4
  185. package/src/number/refined-number-utils.mts +22 -19
@@ -1,7 +1,11 @@
1
1
  import { type Uint as TtfImported_Uint } from 'ts-type-forge';
2
2
  export type Uint = TtfImported_Uint;
3
3
  /**
4
- * Checks if a number is a Uint.
4
+ * Type guard that checks if a value is a non-negative integer.
5
+ *
6
+ * Returns `true` for a non-negative integer — a value with no fractional
7
+ * component, including values outside the safe integer range (unlike
8
+ * `SafeInt`).
5
9
  *
6
10
  * @example
7
11
  *
@@ -13,12 +17,15 @@ export type Uint = TtfImported_Uint;
13
17
  * assert.isTrue(Uint.is(0));
14
18
  * ```
15
19
  *
16
- * @param value The value to check.
17
- * @returns `true` if the value is a Uint, `false` otherwise.
20
+ * @param value - The value to check
21
+ * @returns `true` if the value is a non-negative integer, `false` otherwise
18
22
  */
19
23
  export declare const isUint: (a: number) => a is import("ts-type-forge").NonNegativeInt;
20
24
  /**
21
- * Casts a number to a Uint type.
25
+ * Casts a `number` to the `Uint` branded type.
26
+ *
27
+ * Validates that the value is a non-negative integer and returns it with the
28
+ * `Uint` brand. Throws a `TypeError` otherwise.
22
29
  *
23
30
  * @example
24
31
  *
@@ -30,9 +37,9 @@ export declare const isUint: (a: number) => a is import("ts-type-forge").NonNega
30
37
  * assert.isTrue(Uint.is(branded));
31
38
  * ```
32
39
  *
33
- * @param value The value to cast.
34
- * @returns The value as a Uint type.
35
- * @throws {TypeError} If the value is not a non-negative integer.
40
+ * @param value - The value to cast
41
+ * @returns The value as an `Uint`
42
+ * @throws {TypeError} If the value is not a non-negative integer
36
43
  */
37
44
  export declare const asUint: <N extends number>(x: N) => number & {
38
45
  readonly "> -2^16": true;
@@ -47,15 +54,18 @@ export declare const asUint: <N extends number>(x: N) => number & {
47
54
  'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
48
55
  }> & N;
49
56
  /**
50
- * Namespace providing type-safe arithmetic operations for unsigned integers.
57
+ * Namespace providing type-safe operations for the `Uint` branded type.
58
+ *
59
+ * The `Uint` type represents a non-negative integer. Division (`div`) uses
60
+ * floor division.
51
61
  *
52
- * All operations maintain the non-negative constraint by clamping negative
53
- * results to 0. This ensures that all arithmetic preserves the unsigned integer
54
- * property.
62
+ * Unlike `SafeInt`, `Uint` allows values outside the safe integer range (±2^53
63
+ * − 1), so very large magnitudes may lose precision in JavaScript's `number`
64
+ * type.
55
65
  */
56
66
  export declare const Uint: {
57
67
  /**
58
- * Type guard to check if a value is a Uint.
68
+ * Type guard that checks if a value is a non-negative integer.
59
69
  *
60
70
  * @example
61
71
  *
@@ -67,19 +77,18 @@ export declare const Uint: {
67
77
  * assert.isTrue(Uint.is(0));
68
78
  * ```
69
79
  *
70
- * @param value The value to check.
71
- * @returns `true` if the value is a non-negative integer, `false` otherwise.
80
+ * @param value - The value to check
81
+ * @returns `true` if the value is a non-negative integer, `false` otherwise
72
82
  * @see {@link isUint} for usage examples
73
83
  */
74
84
  readonly is: (a: number) => a is import("ts-type-forge").NonNegativeInt;
75
85
  /**
76
- * The minimum value for an unsigned integer.
77
- *
78
- * @readonly
86
+ * The smallest value representable as `Uint` (the lower saturation target of
87
+ * `fromNumber`).
79
88
  */
80
89
  readonly MIN_VALUE: 0;
81
90
  /**
82
- * Returns the smaller of two Uint values.
91
+ * Returns the smallest of the given non-negative integers.
83
92
  *
84
93
  * @example
85
94
  *
@@ -89,13 +98,12 @@ export declare const Uint: {
89
98
  * assert.isTrue(smallest === 3);
90
99
  * ```
91
100
  *
92
- * @param a The first Uint.
93
- * @param b The second Uint.
94
- * @returns The minimum value as a Uint.
101
+ * @param values - The non-negative integers to compare (at least one required)
102
+ * @returns The smallest value as an `Uint`
95
103
  */
96
104
  readonly min: (...values: readonly import("ts-type-forge").WithSmallInt<import("ts-type-forge").NonNegativeInt>[]) => import("ts-type-forge").NonNegativeInt;
97
105
  /**
98
- * Returns the larger of two Uint values.
106
+ * Returns the largest of the given non-negative integers.
99
107
  *
100
108
  * @example
101
109
  *
@@ -105,32 +113,37 @@ export declare const Uint: {
105
113
  * assert.isTrue(largest === 7);
106
114
  * ```
107
115
  *
108
- * @param a The first Uint.
109
- * @param b The second Uint.
110
- * @returns The maximum value as a Uint.
116
+ * @param values - The non-negative integers to compare (at least one required)
117
+ * @returns The largest value as an `Uint`
111
118
  */
112
119
  readonly max: (...values: readonly import("ts-type-forge").WithSmallInt<import("ts-type-forge").NonNegativeInt>[]) => import("ts-type-forge").NonNegativeInt;
113
120
  /**
114
- * Clamps a number to the Uint range (non-negative).
121
+ * Converts an arbitrary `number` into an `Uint`, rounding to the nearest
122
+ * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
123
+ *
124
+ * Unlike `asUint`, this is total: out-of-range inputs are clamped to the
125
+ * nearest representable `Uint` instead of throwing.
115
126
  *
116
127
  * @example
117
128
  *
118
129
  * ```ts
119
- * const clampedNegative = Uint.clamp(-5);
130
+ * const fromNegative = Uint.fromNumber(-5);
120
131
  *
121
- * const clampedPositive = Uint.clamp(42);
132
+ * const fromPositive = Uint.fromNumber(42);
122
133
  *
123
- * assert.isTrue(clampedNegative === 0);
134
+ * assert.isTrue(fromNegative === 0);
124
135
  *
125
- * assert.isTrue(clampedPositive === 42);
136
+ * assert.isTrue(fromPositive === 42);
126
137
  * ```
127
138
  *
128
- * @param value The number to clamp.
129
- * @returns The value clamped to [0, +∞) as a Uint.
139
+ * @param value - The value to convert
140
+ * @returns The value as an `Uint`
130
141
  */
131
- readonly clamp: (x: number) => import("ts-type-forge").NonNegativeInt;
142
+ readonly fromNumber: (x: number) => import("ts-type-forge").NonNegativeInt;
132
143
  /**
133
- * Generates a random Uint value.
144
+ * Generates a random `Uint` within the given range.
145
+ *
146
+ * The range is inclusive on both ends.
134
147
  *
135
148
  * @example
136
149
  *
@@ -146,11 +159,14 @@ export declare const Uint: {
146
159
  * assert.isTrue(randomValue >= 0 && randomValue <= 3);
147
160
  * ```
148
161
  *
149
- * @returns A random non-negative integer as a Uint.
162
+ * @param min - The minimum value (inclusive)
163
+ * @param max - The maximum value (inclusive)
164
+ * @returns A random `Uint` in `[min, max]`
150
165
  */
151
166
  readonly random: (min?: import("ts-type-forge").WithSmallInt<import("ts-type-forge").NonNegativeInt> | undefined, max?: import("ts-type-forge").WithSmallInt<import("ts-type-forge").NonNegativeInt> | undefined) => import("ts-type-forge").NonNegativeInt;
152
167
  /**
153
- * Raises a Uint to the power of another Uint.
168
+ * Raises `a` to the power `b`, returning `a ** b` as an `Uint` (floored to an
169
+ * integer).
154
170
  *
155
171
  * @example
156
172
  *
@@ -164,13 +180,13 @@ export declare const Uint: {
164
180
  * assert.isTrue(power === 32);
165
181
  * ```
166
182
  *
167
- * @param a The base Uint.
168
- * @param b The exponent Uint.
169
- * @returns `a ** b` clamped to [0, +∞) as a Uint.
183
+ * @param a - The base non-negative integer
184
+ * @param b - The exponent non-negative integer
185
+ * @returns `a ** b` as an `Uint`
170
186
  */
171
187
  readonly pow: (x: import("ts-type-forge").WithSmallInt<import("ts-type-forge").NonNegativeInt>, y: import("ts-type-forge").WithSmallInt<import("ts-type-forge").NonNegativeInt>) => import("ts-type-forge").NonNegativeInt;
172
188
  /**
173
- * Adds two Uint values.
189
+ * Adds two non-negative integers, returning `a + b` as an `Uint`.
174
190
  *
175
191
  * @example
176
192
  *
@@ -180,13 +196,13 @@ export declare const Uint: {
180
196
  * assert.isTrue(sum === 13);
181
197
  * ```
182
198
  *
183
- * @param a The first Uint.
184
- * @param b The second Uint.
185
- * @returns `a + b` clamped to [0, +∞) as a Uint.
199
+ * @param a - The first non-negative integer
200
+ * @param b - The second non-negative integer
201
+ * @returns The sum of `a` and `b` as an `Uint`
186
202
  */
187
203
  readonly add: (x: import("ts-type-forge").WithSmallInt<import("ts-type-forge").NonNegativeInt>, y: import("ts-type-forge").WithSmallInt<import("ts-type-forge").NonNegativeInt>) => import("ts-type-forge").NonNegativeInt;
188
204
  /**
189
- * Subtracts one Uint from another.
205
+ * Subtracts two non-negative integers, returning `a - b` as an `Uint`.
190
206
  *
191
207
  * @example
192
208
  *
@@ -196,13 +212,13 @@ export declare const Uint: {
196
212
  * assert.isTrue(difference === 0);
197
213
  * ```
198
214
  *
199
- * @param a The minuend Uint.
200
- * @param b The subtrahend Uint.
201
- * @returns `a - b` clamped to [0, +∞) as a Uint (minimum 0).
215
+ * @param a - The first non-negative integer
216
+ * @param b - The second non-negative integer
217
+ * @returns The difference of `a` and `b` as an `Uint`
202
218
  */
203
219
  readonly sub: (x: import("ts-type-forge").WithSmallInt<import("ts-type-forge").NonNegativeInt>, y: import("ts-type-forge").WithSmallInt<import("ts-type-forge").NonNegativeInt>) => import("ts-type-forge").NonNegativeInt;
204
220
  /**
205
- * Multiplies two Uint values.
221
+ * Multiplies two non-negative integers, returning `a * b` as an `Uint`.
206
222
  *
207
223
  * @example
208
224
  *
@@ -212,13 +228,14 @@ export declare const Uint: {
212
228
  * assert.isTrue(product === 42);
213
229
  * ```
214
230
  *
215
- * @param a The first Uint.
216
- * @param b The second Uint.
217
- * @returns `a * b` clamped to [0, +∞) as a Uint.
231
+ * @param a - The first non-negative integer
232
+ * @param b - The second non-negative integer
233
+ * @returns The product of `a` and `b` as an `Uint`
218
234
  */
219
235
  readonly mul: (x: import("ts-type-forge").WithSmallInt<import("ts-type-forge").NonNegativeInt>, y: import("ts-type-forge").WithSmallInt<import("ts-type-forge").NonNegativeInt>) => import("ts-type-forge").NonNegativeInt;
220
236
  /**
221
- * Divides one Uint by another using floor division.
237
+ * Divides two non-negative integers using floor division (`⌊a / b⌋`): the
238
+ * result is `a / b` rounded toward negative infinity, as an `Uint`.
222
239
  *
223
240
  * @example
224
241
  *
@@ -228,9 +245,9 @@ export declare const Uint: {
228
245
  * assert.isTrue(quotient === 2);
229
246
  * ```
230
247
  *
231
- * @param a The dividend Uint.
232
- * @param b The divisor Uint.
233
- * @returns `⌊a / b⌋` clamped to [0, +∞) as a Uint.
248
+ * @param a - The dividend
249
+ * @param b - The divisor (must be non-zero)
250
+ * @returns The floored quotient as an `Uint`
234
251
  */
235
252
  readonly div: (x: import("ts-type-forge").WithSmallInt<import("ts-type-forge").NonNegativeInt>, y: 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 & {
236
253
  readonly "!=0": true;
@@ -1 +1 @@
1
- {"version":3,"file":"uint.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/uint.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,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;;OAmBG;;IAGH;;;;;;;;;;;;;;OAcG;;IAGH;;;;;;;;;;;;;;OAcG;;IAGH;;;;;;;;;;;;;;OAcG;;IAGH;;;;;;;;;;;;;;;OAeG;;;;;;;;;;;;;;CAEK,CAAC"}
@@ -5,8 +5,8 @@ const {
5
5
  MIN_VALUE,
6
6
  add,
7
7
  castType,
8
- clamp,
9
8
  div,
9
+ fromNumber,
10
10
  is,
11
11
  max: max_,
12
12
  min: min_,
@@ -24,7 +24,7 @@ const isUint = is;
24
24
  const asUint = castType;
25
25
  const Uint = {
26
26
  /**
27
- * Type guard to check if a value is a Uint.
27
+ * Type guard that checks if a value is a non-negative integer.
28
28
  *
29
29
  * @example
30
30
  *
@@ -36,19 +36,18 @@ const Uint = {
36
36
  * assert.isTrue(Uint.is(0));
37
37
  * ```
38
38
  *
39
- * @param value The value to check.
40
- * @returns `true` if the value is a non-negative integer, `false` otherwise.
39
+ * @param value - The value to check
40
+ * @returns `true` if the value is a non-negative integer, `false` otherwise
41
41
  * @see {@link isUint} for usage examples
42
42
  */
43
43
  is,
44
44
  /**
45
- * The minimum value for an unsigned integer.
46
- *
47
- * @readonly
45
+ * The smallest value representable as `Uint` (the lower saturation target of
46
+ * `fromNumber`).
48
47
  */
49
48
  MIN_VALUE,
50
49
  /**
51
- * Returns the smaller of two Uint values.
50
+ * Returns the smallest of the given non-negative integers.
52
51
  *
53
52
  * @example
54
53
  *
@@ -58,13 +57,12 @@ const Uint = {
58
57
  * assert.isTrue(smallest === 3);
59
58
  * ```
60
59
  *
61
- * @param a The first Uint.
62
- * @param b The second Uint.
63
- * @returns The minimum value as a Uint.
60
+ * @param values - The non-negative integers to compare (at least one required)
61
+ * @returns The smallest value as an `Uint`
64
62
  */
65
63
  min: min_,
66
64
  /**
67
- * Returns the larger of two Uint values.
65
+ * Returns the largest of the given non-negative integers.
68
66
  *
69
67
  * @example
70
68
  *
@@ -74,32 +72,37 @@ const Uint = {
74
72
  * assert.isTrue(largest === 7);
75
73
  * ```
76
74
  *
77
- * @param a The first Uint.
78
- * @param b The second Uint.
79
- * @returns The maximum value as a Uint.
75
+ * @param values - The non-negative integers to compare (at least one required)
76
+ * @returns The largest value as an `Uint`
80
77
  */
81
78
  max: max_,
82
79
  /**
83
- * Clamps a number to the Uint range (non-negative).
80
+ * Converts an arbitrary `number` into an `Uint`, rounding to the nearest
81
+ * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
82
+ *
83
+ * Unlike `asUint`, this is total: out-of-range inputs are clamped to the
84
+ * nearest representable `Uint` instead of throwing.
84
85
  *
85
86
  * @example
86
87
  *
87
88
  * ```ts
88
- * const clampedNegative = Uint.clamp(-5);
89
+ * const fromNegative = Uint.fromNumber(-5);
89
90
  *
90
- * const clampedPositive = Uint.clamp(42);
91
+ * const fromPositive = Uint.fromNumber(42);
91
92
  *
92
- * assert.isTrue(clampedNegative === 0);
93
+ * assert.isTrue(fromNegative === 0);
93
94
  *
94
- * assert.isTrue(clampedPositive === 42);
95
+ * assert.isTrue(fromPositive === 42);
95
96
  * ```
96
97
  *
97
- * @param value The number to clamp.
98
- * @returns The value clamped to [0, +∞) as a Uint.
98
+ * @param value - The value to convert
99
+ * @returns The value as an `Uint`
99
100
  */
100
- clamp,
101
+ fromNumber,
101
102
  /**
102
- * Generates a random Uint value.
103
+ * Generates a random `Uint` within the given range.
104
+ *
105
+ * The range is inclusive on both ends.
103
106
  *
104
107
  * @example
105
108
  *
@@ -115,11 +118,14 @@ const Uint = {
115
118
  * assert.isTrue(randomValue >= 0 && randomValue <= 3);
116
119
  * ```
117
120
  *
118
- * @returns A random non-negative integer as a Uint.
121
+ * @param min - The minimum value (inclusive)
122
+ * @param max - The maximum value (inclusive)
123
+ * @returns A random `Uint` in `[min, max]`
119
124
  */
120
125
  random,
121
126
  /**
122
- * Raises a Uint to the power of another Uint.
127
+ * Raises `a` to the power `b`, returning `a ** b` as an `Uint` (floored to an
128
+ * integer).
123
129
  *
124
130
  * @example
125
131
  *
@@ -133,13 +139,13 @@ const Uint = {
133
139
  * assert.isTrue(power === 32);
134
140
  * ```
135
141
  *
136
- * @param a The base Uint.
137
- * @param b The exponent Uint.
138
- * @returns `a ** b` clamped to [0, +∞) as a Uint.
142
+ * @param a - The base non-negative integer
143
+ * @param b - The exponent non-negative integer
144
+ * @returns `a ** b` as an `Uint`
139
145
  */
140
146
  pow,
141
147
  /**
142
- * Adds two Uint values.
148
+ * Adds two non-negative integers, returning `a + b` as an `Uint`.
143
149
  *
144
150
  * @example
145
151
  *
@@ -149,13 +155,13 @@ const Uint = {
149
155
  * assert.isTrue(sum === 13);
150
156
  * ```
151
157
  *
152
- * @param a The first Uint.
153
- * @param b The second Uint.
154
- * @returns `a + b` clamped to [0, +∞) as a Uint.
158
+ * @param a - The first non-negative integer
159
+ * @param b - The second non-negative integer
160
+ * @returns The sum of `a` and `b` as an `Uint`
155
161
  */
156
162
  add,
157
163
  /**
158
- * Subtracts one Uint from another.
164
+ * Subtracts two non-negative integers, returning `a - b` as an `Uint`.
159
165
  *
160
166
  * @example
161
167
  *
@@ -165,13 +171,13 @@ const Uint = {
165
171
  * assert.isTrue(difference === 0);
166
172
  * ```
167
173
  *
168
- * @param a The minuend Uint.
169
- * @param b The subtrahend Uint.
170
- * @returns `a - b` clamped to [0, +∞) as a Uint (minimum 0).
174
+ * @param a - The first non-negative integer
175
+ * @param b - The second non-negative integer
176
+ * @returns The difference of `a` and `b` as an `Uint`
171
177
  */
172
178
  sub,
173
179
  /**
174
- * Multiplies two Uint values.
180
+ * Multiplies two non-negative integers, returning `a * b` as an `Uint`.
175
181
  *
176
182
  * @example
177
183
  *
@@ -181,13 +187,14 @@ const Uint = {
181
187
  * assert.isTrue(product === 42);
182
188
  * ```
183
189
  *
184
- * @param a The first Uint.
185
- * @param b The second Uint.
186
- * @returns `a * b` clamped to [0, +∞) as a Uint.
190
+ * @param a - The first non-negative integer
191
+ * @param b - The second non-negative integer
192
+ * @returns The product of `a` and `b` as an `Uint`
187
193
  */
188
194
  mul,
189
195
  /**
190
- * Divides one Uint by another using floor division.
196
+ * Divides two non-negative integers using floor division (`⌊a / b⌋`): the
197
+ * result is `a / b` rounded toward negative infinity, as an `Uint`.
191
198
  *
192
199
  * @example
193
200
  *
@@ -197,9 +204,9 @@ const Uint = {
197
204
  * assert.isTrue(quotient === 2);
198
205
  * ```
199
206
  *
200
- * @param a The dividend Uint.
201
- * @param b The divisor Uint.
202
- * @returns `⌊a / b⌋` clamped to [0, +∞) as a Uint.
207
+ * @param a - The dividend
208
+ * @param b - The divisor (must be non-zero)
209
+ * @returns The floored quotient as an `Uint`
203
210
  */
204
211
  div
205
212
  };
@@ -1 +1 @@
1
- {"version":3,"file":"uint.mjs","sources":["../../../src/number/branded-types/uint.mts"],"sourcesContent":["import { type Uint as TtfImported_Uint } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Uint = TtfImported_Uint;\n\ntype ElementType = Uint;\n\nconst typeNameInMessage = 'a non-negative integer';\n\nconst {\n MIN_VALUE,\n add,\n castType,\n clamp,\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 0,\n number\n>({\n integerOrSafeInteger: 'Integer',\n MIN_VALUE: 0,\n MAX_VALUE: Number.MAX_VALUE,\n typeNameInMessage,\n} as const);\n\n/**\n * Checks if a number is a Uint.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isUint(4));\n *\n * assert.isFalse(isUint(-1));\n *\n * assert.isTrue(Uint.is(0));\n * ```\n *\n * @param value The value to check.\n * @returns `true` if the value is a Uint, `false` otherwise.\n */\nexport const isUint = is;\n\n/**\n * Casts a number to a Uint type.\n *\n * @example\n *\n * ```ts\n * const branded = asUint(12);\n *\n * assert.isTrue(branded === 12);\n *\n * assert.isTrue(Uint.is(branded));\n * ```\n *\n * @param value The value to cast.\n * @returns The value as a Uint type.\n * @throws {TypeError} If the value is not a non-negative integer.\n */\nexport const asUint = castType;\n\n/**\n * Namespace providing type-safe arithmetic operations for unsigned integers.\n *\n * All operations maintain the non-negative constraint by clamping negative\n * results to 0. This ensures that all arithmetic preserves the unsigned integer\n * property.\n */\nexport const Uint = {\n /**\n * Type guard to check if a value is a Uint.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isUint(4));\n *\n * assert.isFalse(isUint(-1));\n *\n * assert.isTrue(Uint.is(0));\n * ```\n *\n * @param value The value to check.\n * @returns `true` if the value is a non-negative integer, `false` otherwise.\n * @see {@link isUint} for usage examples\n */\n is,\n\n /**\n * The minimum value for an unsigned integer.\n *\n * @readonly\n */\n MIN_VALUE,\n\n /**\n * Returns the smaller of two Uint values.\n *\n * @example\n *\n * ```ts\n * const smallest = Uint.min(asUint(7), asUint(3));\n *\n * assert.isTrue(smallest === 3);\n * ```\n *\n * @param a The first Uint.\n * @param b The second Uint.\n * @returns The minimum value as a Uint.\n */\n min: min_,\n\n /**\n * Returns the larger of two Uint values.\n *\n * @example\n *\n * ```ts\n * const largest = Uint.max(asUint(7), asUint(3));\n *\n * assert.isTrue(largest === 7);\n * ```\n *\n * @param a The first Uint.\n * @param b The second Uint.\n * @returns The maximum value as a Uint.\n */\n max: max_,\n\n /**\n * Clamps a number to the Uint range (non-negative).\n *\n * @example\n *\n * ```ts\n * const clampedNegative = Uint.clamp(-5);\n *\n * const clampedPositive = Uint.clamp(42);\n *\n * assert.isTrue(clampedNegative === 0);\n *\n * assert.isTrue(clampedPositive === 42);\n * ```\n *\n * @param value The number to clamp.\n * @returns The value clamped to [0, +∞) as a Uint.\n */\n clamp,\n\n /**\n * Generates a random Uint value.\n *\n * @example\n *\n * ```ts\n * const min = asUint(0);\n *\n * const max = asUint(3);\n *\n * const randomValue = Uint.random(min, max);\n *\n * assert.isTrue(Uint.is(randomValue));\n *\n * assert.isTrue(randomValue >= 0 && randomValue <= 3);\n * ```\n *\n * @returns A random non-negative integer as a Uint.\n */\n random,\n\n /**\n * Raises a Uint to the power of another Uint.\n *\n * @example\n *\n * ```ts\n * const base = asUint(2);\n *\n * const exponent = asUint(5);\n *\n * const power = Uint.pow(base, exponent);\n *\n * assert.isTrue(power === 32);\n * ```\n *\n * @param a The base Uint.\n * @param b The exponent Uint.\n * @returns `a ** b` clamped to [0, +∞) as a Uint.\n */\n pow,\n\n /**\n * Adds two Uint values.\n *\n * @example\n *\n * ```ts\n * const sum = Uint.add(asUint(5), asUint(8));\n *\n * assert.isTrue(sum === 13);\n * ```\n *\n * @param a The first Uint.\n * @param b The second Uint.\n * @returns `a + b` clamped to [0, +∞) as a Uint.\n */\n add,\n\n /**\n * Subtracts one Uint from another.\n *\n * @example\n *\n * ```ts\n * const difference = Uint.sub(asUint(5), asUint(8));\n *\n * assert.isTrue(difference === 0);\n * ```\n *\n * @param a The minuend Uint.\n * @param b The subtrahend Uint.\n * @returns `a - b` clamped to [0, +∞) as a Uint (minimum 0).\n */\n sub,\n\n /**\n * Multiplies two Uint values.\n *\n * @example\n *\n * ```ts\n * const product = Uint.mul(asUint(7), asUint(6));\n *\n * assert.isTrue(product === 42);\n * ```\n *\n * @param a The first Uint.\n * @param b The second Uint.\n * @returns `a * b` clamped to [0, +∞) as a Uint.\n */\n mul,\n\n /**\n * Divides one Uint by another using floor division.\n *\n * @example\n *\n * ```ts\n * const quotient = Uint.div(asUint(10), asUint(4));\n *\n * assert.isTrue(quotient === 2);\n * ```\n *\n * @param a The dividend Uint.\n * @param b The divisor Uint.\n * @returns `⌊a / b⌋` clamped to [0, +∞) as a Uint.\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof Uint,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'non-negative'\n >\n>('=');\n\nexpectType<\n typeof Uint,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'non-negative'\n >\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,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AA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBA,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,EAiBA;AACF;;;;"}
1
+ {"version":3,"file":"uint.mjs","sources":["../../../src/number/branded-types/uint.mts"],"sourcesContent":["import { type Uint as TtfImported_Uint } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Uint = TtfImported_Uint;\n\ntype ElementType = Uint;\n\nconst typeNameInMessage = 'a non-negative integer';\n\nconst {\n MIN_VALUE,\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 0,\n number\n>({\n integerOrSafeInteger: 'Integer',\n MIN_VALUE: 0,\n MAX_VALUE: Number.MAX_VALUE,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a non-negative integer.\n *\n * Returns `true` for a non-negative integer — a value with no fractional\n * component, including values outside the safe integer range (unlike\n * `SafeInt`).\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isUint(4));\n *\n * assert.isFalse(isUint(-1));\n *\n * assert.isTrue(Uint.is(0));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-negative integer, `false` otherwise\n */\nexport const isUint = is;\n\n/**\n * Casts a `number` to the `Uint` branded type.\n *\n * Validates that the value is a non-negative integer and returns it with the\n * `Uint` brand. Throws a `TypeError` otherwise.\n *\n * @example\n *\n * ```ts\n * const branded = asUint(12);\n *\n * assert.isTrue(branded === 12);\n *\n * assert.isTrue(Uint.is(branded));\n * ```\n *\n * @param value - The value to cast\n * @returns The value as an `Uint`\n * @throws {TypeError} If the value is not a non-negative integer\n */\nexport const asUint = castType;\n\n/**\n * Namespace providing type-safe operations for the `Uint` branded type.\n *\n * The `Uint` type represents a non-negative integer. Division (`div`) uses\n * floor division.\n *\n * Unlike `SafeInt`, `Uint` 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 Uint = {\n /**\n * Type guard that checks if a value is a non-negative integer.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isUint(4));\n *\n * assert.isFalse(isUint(-1));\n *\n * assert.isTrue(Uint.is(0));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-negative integer, `false` otherwise\n * @see {@link isUint} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `Uint` (the lower saturation target of\n * `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * Returns the smallest of the given non-negative integers.\n *\n * @example\n *\n * ```ts\n * const smallest = Uint.min(asUint(7), asUint(3));\n *\n * assert.isTrue(smallest === 3);\n * ```\n *\n * @param values - The non-negative integers to compare (at least one required)\n * @returns The smallest value as an `Uint`\n */\n min: min_,\n\n /**\n * Returns the largest of the given non-negative integers.\n *\n * @example\n *\n * ```ts\n * const largest = Uint.max(asUint(7), asUint(3));\n *\n * assert.isTrue(largest === 7);\n * ```\n *\n * @param values - The non-negative integers to compare (at least one required)\n * @returns The largest value as an `Uint`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into an `Uint`, rounding to the nearest\n * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asUint`, this is total: out-of-range inputs are clamped to the\n * nearest representable `Uint` instead of throwing.\n *\n * @example\n *\n * ```ts\n * const fromNegative = Uint.fromNumber(-5);\n *\n * const fromPositive = Uint.fromNumber(42);\n *\n * assert.isTrue(fromNegative === 0);\n *\n * assert.isTrue(fromPositive === 42);\n * ```\n *\n * @param value - The value to convert\n * @returns The value as an `Uint`\n */\n fromNumber,\n\n /**\n * Generates a random `Uint` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @example\n *\n * ```ts\n * const min = asUint(0);\n *\n * const max = asUint(3);\n *\n * const randomValue = Uint.random(min, max);\n *\n * assert.isTrue(Uint.is(randomValue));\n *\n * assert.isTrue(randomValue >= 0 && randomValue <= 3);\n * ```\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `Uint` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as an `Uint` (floored to an\n * integer).\n *\n * @example\n *\n * ```ts\n * const base = asUint(2);\n *\n * const exponent = asUint(5);\n *\n * const power = Uint.pow(base, exponent);\n *\n * assert.isTrue(power === 32);\n * ```\n *\n * @param a - The base non-negative integer\n * @param b - The exponent non-negative integer\n * @returns `a ** b` as an `Uint`\n */\n pow,\n\n /**\n * Adds two non-negative integers, returning `a + b` as an `Uint`.\n *\n * @example\n *\n * ```ts\n * const sum = Uint.add(asUint(5), asUint(8));\n *\n * assert.isTrue(sum === 13);\n * ```\n *\n * @param a - The first non-negative integer\n * @param b - The second non-negative integer\n * @returns The sum of `a` and `b` as an `Uint`\n */\n add,\n\n /**\n * Subtracts two non-negative integers, returning `a - b` as an `Uint`.\n *\n * @example\n *\n * ```ts\n * const difference = Uint.sub(asUint(5), asUint(8));\n *\n * assert.isTrue(difference === 0);\n * ```\n *\n * @param a - The first non-negative integer\n * @param b - The second non-negative integer\n * @returns The difference of `a` and `b` as an `Uint`\n */\n sub,\n\n /**\n * Multiplies two non-negative integers, returning `a * b` as an `Uint`.\n *\n * @example\n *\n * ```ts\n * const product = Uint.mul(asUint(7), asUint(6));\n *\n * assert.isTrue(product === 42);\n * ```\n *\n * @param a - The first non-negative integer\n * @param b - The second non-negative integer\n * @returns The product of `a` and `b` as an `Uint`\n */\n mul,\n\n /**\n * Divides two non-negative integers using floor division (`⌊a / b⌋`): the\n * result is `a / b` rounded toward negative infinity, as an `Uint`.\n *\n * @example\n *\n * ```ts\n * const quotient = Uint.div(asUint(10), asUint(4));\n *\n * assert.isTrue(quotient === 2);\n * ```\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as an `Uint`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof Uint,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'non-negative'\n >\n>('=');\n\nexpectType<\n typeof Uint,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'non-negative'\n >\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,wBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;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,SAAA;AAAA,EACtB,SAAA,EAAW,CAAA;AAAA,EACX,WAAW,MAAA,CAAO,SAAA;AAAA,EAClB;AACF,CAAU,CAAA;AAsBH,MAAM,MAAA,GAAS;AAsBf,MAAM,MAAA,GAAS;AAYf,MAAM,IAAA,GAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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