ts-data-forge 11.0.0 → 11.0.1

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