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
@@ -13,8 +13,8 @@ const {
13
13
  MIN_VALUE,
14
14
  add,
15
15
  castType,
16
- clamp,
17
16
  div,
17
+ fromNumber,
18
18
  is,
19
19
  max: max_,
20
20
  min: min_,
@@ -34,131 +34,141 @@ const {
34
34
  } as const);
35
35
 
36
36
  /**
37
- * Checks if a number is a PositiveUint16 (16-bit positive unsigned integer in
38
- * the range [1, 2^16)).
37
+ * Type guard that checks if a value is a positive integer in [1, 2^16).
39
38
  *
40
- * @param value The value to check.
41
- * @returns `true` if the value is a PositiveUint16, `false` otherwise.
39
+ * Returns `true` for a positive integer in [1, 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 positive integer in [1, 2^16), `false` otherwise
42
44
  */
43
45
  export const isPositiveUint16 = is;
44
46
 
45
47
  /**
46
- * Casts a number to a PositiveUint16 type.
48
+ * Casts a `number` to the `PositiveUint16` branded type.
49
+ *
50
+ * Validates that the value is a positive integer in [1, 2^16) and returns it
51
+ * with the `PositiveUint16` brand. Throws a `TypeError` otherwise.
47
52
  *
48
- * @param value The value to cast.
49
- * @returns The value as a PositiveUint16 type.
50
- * @throws {TypeError} If the value is not a positive integer in [1, 2^16).
53
+ * @param value - The value to cast
54
+ * @returns The value as a `PositiveUint16`
55
+ * @throws {TypeError} If the value is not a positive integer in [1, 2^16)
51
56
  */
52
57
  export const asPositiveUint16 = castType;
53
58
 
54
59
  /**
55
- * Namespace providing type-safe arithmetic operations for 16-bit positive
56
- * unsigned integers.
60
+ * Namespace providing type-safe operations for the `PositiveUint16` branded
61
+ * type.
57
62
  *
58
- * All operations automatically clamp results to the valid PositiveUint16 range
59
- * [1, 65535]. This ensures that all arithmetic maintains the 16-bit positive
60
- * unsigned integer constraint, with results below 1 clamped to MIN_VALUE and
61
- * overflow results clamped to MAX_VALUE.
63
+ * The `PositiveUint16` type represents a positive integer in [1, 2^16).
64
+ * Division (`div`) uses floor division.
62
65
  */
63
66
  export const PositiveUint16 = {
64
67
  /**
65
- * Type guard to check if a value is a PositiveUint16.
68
+ * Type guard that checks if a value is a positive integer in [1, 2^16).
66
69
  *
67
- * @param value The value to check.
68
- * @returns `true` if the value is a 16-bit positive unsigned integer, `false`
69
- * otherwise.
70
+ * @param value - The value to check
71
+ * @returns `true` if the value is a positive integer in [1, 2^16), `false` otherwise
72
+ * @see {@link isPositiveUint16} for usage examples
70
73
  */
71
74
  is,
72
75
 
73
76
  /**
74
- * The minimum value for a 16-bit positive unsigned integer.
75
- *
76
- * @readonly
77
+ * The smallest value representable as `PositiveUint16` (the lower saturation
78
+ * target of `fromNumber`).
77
79
  */
78
80
  MIN_VALUE,
79
81
 
80
82
  /**
81
- * The maximum value for a 16-bit positive unsigned integer.
82
- *
83
- * @readonly
83
+ * The largest value representable as `PositiveUint16` (the upper saturation
84
+ * target of `fromNumber`).
84
85
  */
85
86
  MAX_VALUE,
86
87
 
87
88
  /**
88
- * Returns the smaller of two PositiveUint16 values.
89
+ * Returns the smallest of the given positive integers.
89
90
  *
90
- * @param a The first PositiveUint16.
91
- * @param b The second PositiveUint16.
92
- * @returns The minimum value as a PositiveUint16.
91
+ * @param values - The positive integers to compare (at least one required)
92
+ * @returns The smallest value as a `PositiveUint16`
93
93
  */
94
94
  min: min_,
95
95
 
96
96
  /**
97
- * Returns the larger of two PositiveUint16 values.
97
+ * Returns the largest of the given positive integers.
98
98
  *
99
- * @param a The first PositiveUint16.
100
- * @param b The second PositiveUint16.
101
- * @returns The maximum value as a PositiveUint16.
99
+ * @param values - The positive integers to compare (at least one required)
100
+ * @returns The largest value as a `PositiveUint16`
102
101
  */
103
102
  max: max_,
104
103
 
105
104
  /**
106
- * Clamps a number to the PositiveUint16 range.
105
+ * Converts an arbitrary `number` into a `PositiveUint16`, rounding to the
106
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
107
+ * MAX_VALUE]`.
108
+ *
109
+ * Unlike `asPositiveUint16`, this is total: out-of-range inputs are clamped
110
+ * to the nearest representable `PositiveUint16` instead of throwing.
107
111
  *
108
- * @param value The number to clamp.
109
- * @returns The value clamped to [1, 65535] as a PositiveUint16.
112
+ * @param value - The value to convert
113
+ * @returns The value as a `PositiveUint16`
110
114
  */
111
- clamp,
115
+ fromNumber,
112
116
 
113
117
  /**
114
- * Generates a random PositiveUint16 value within the valid range.
118
+ * Generates a random `PositiveUint16` within the given range.
119
+ *
120
+ * The range is inclusive on both ends.
115
121
  *
116
- * @returns A random PositiveUint16 between 1 and 65535.
122
+ * @param min - The minimum value (inclusive)
123
+ * @param max - The maximum value (inclusive)
124
+ * @returns A random `PositiveUint16` in `[min, max]`
117
125
  */
118
126
  random,
119
127
 
120
128
  /**
121
- * Raises a PositiveUint16 to the power of another PositiveUint16.
129
+ * Raises `a` to the power `b`, returning `a ** b` as a `PositiveUint16`
130
+ * (floored to an integer).
122
131
  *
123
- * @param a The base PositiveUint16.
124
- * @param b The exponent PositiveUint16.
125
- * @returns `a ** b` clamped to [1, 65535] as a PositiveUint16.
132
+ * @param a - The base positive integer
133
+ * @param b - The exponent positive integer
134
+ * @returns `a ** b` as a `PositiveUint16`
126
135
  */
127
136
  pow,
128
137
 
129
138
  /**
130
- * Adds two PositiveUint16 values.
139
+ * Adds two positive integers, returning `a + b` as a `PositiveUint16`.
131
140
  *
132
- * @param a The first PositiveUint16.
133
- * @param b The second PositiveUint16.
134
- * @returns `a + b` clamped to [1, 65535] as a PositiveUint16.
141
+ * @param a - The first positive integer
142
+ * @param b - The second positive integer
143
+ * @returns The sum of `a` and `b` as a `PositiveUint16`
135
144
  */
136
145
  add,
137
146
 
138
147
  /**
139
- * Subtracts one PositiveUint16 from another.
148
+ * Subtracts two positive integers, returning `a - b` as a `PositiveUint16`.
140
149
  *
141
- * @param a The minuend PositiveUint16.
142
- * @param b The subtrahend PositiveUint16.
143
- * @returns `a - b` clamped to [1, 65535] as a PositiveUint16 (minimum 1).
150
+ * @param a - The first positive integer
151
+ * @param b - The second positive integer
152
+ * @returns The difference of `a` and `b` as a `PositiveUint16`
144
153
  */
145
154
  sub,
146
155
 
147
156
  /**
148
- * Multiplies two PositiveUint16 values.
157
+ * Multiplies two positive integers, returning `a * b` as a `PositiveUint16`.
149
158
  *
150
- * @param a The first PositiveUint16.
151
- * @param b The second PositiveUint16.
152
- * @returns `a * b` clamped to [1, 65535] as a PositiveUint16.
159
+ * @param a - The first positive integer
160
+ * @param b - The second positive integer
161
+ * @returns The product of `a` and `b` as a `PositiveUint16`
153
162
  */
154
163
  mul,
155
164
 
156
165
  /**
157
- * Divides one PositiveUint16 by another using floor division.
166
+ * Divides two positive integers using floor division (`⌊a / b⌋`): the result
167
+ * is `a / b` rounded toward negative infinity, as a `PositiveUint16`.
158
168
  *
159
- * @param a The dividend PositiveUint16.
160
- * @param b The divisor PositiveUint16.
161
- * @returns `⌊a / b⌋` clamped to [1, 65535] as a PositiveUint16.
169
+ * @param a - The dividend
170
+ * @param b - The divisor (must be non-zero)
171
+ * @returns The floored quotient as a `PositiveUint16`
162
172
  */
163
173
  div,
164
174
  } as const;
@@ -13,8 +13,8 @@ const {
13
13
  MIN_VALUE,
14
14
  add,
15
15
  castType,
16
- clamp,
17
16
  div,
17
+ fromNumber,
18
18
  is,
19
19
  max: max_,
20
20
  min: min_,
@@ -34,132 +34,141 @@ const {
34
34
  } as const);
35
35
 
36
36
  /**
37
- * Checks if a number is a PositiveUint32 (32-bit positive unsigned integer in
38
- * the range [1, 2^32)).
37
+ * Type guard that checks if a value is a positive integer in [1, 2^32).
39
38
  *
40
- * @param value The value to check.
41
- * @returns `true` if the value is a PositiveUint32, `false` otherwise.
39
+ * Returns `true` for a positive integer in [1, 2^32) — a value with no
40
+ * fractional component.
41
+ *
42
+ * @param value - The value to check
43
+ * @returns `true` if the value is a positive integer in [1, 2^32), `false` otherwise
42
44
  */
43
45
  export const isPositiveUint32 = is;
44
46
 
45
47
  /**
46
- * Casts a number to a PositiveUint32 type.
48
+ * Casts a `number` to the `PositiveUint32` branded type.
49
+ *
50
+ * Validates that the value is a positive integer in [1, 2^32) and returns it
51
+ * with the `PositiveUint32` brand. Throws a `TypeError` otherwise.
47
52
  *
48
- * @param value The value to cast.
49
- * @returns The value as a PositiveUint32 type.
50
- * @throws {TypeError} If the value is not a positive integer in [1, 2^32).
53
+ * @param value - The value to cast
54
+ * @returns The value as a `PositiveUint32`
55
+ * @throws {TypeError} If the value is not a positive integer in [1, 2^32)
51
56
  */
52
57
  export const asPositiveUint32 = castType;
53
58
 
54
59
  /**
55
- * Namespace providing type-safe arithmetic operations for 32-bit positive
56
- * unsigned integers.
60
+ * Namespace providing type-safe operations for the `PositiveUint32` branded
61
+ * type.
57
62
  *
58
- * All operations automatically clamp results to the valid PositiveUint32 range
59
- * [1, 4294967295]. This ensures that all arithmetic maintains the 32-bit
60
- * positive unsigned integer constraint, with results below 1 clamped to
61
- * MIN_VALUE and overflow results clamped to MAX_VALUE.
63
+ * The `PositiveUint32` type represents a positive integer in [1, 2^32).
64
+ * Division (`div`) uses floor division.
62
65
  */
63
66
  export const PositiveUint32 = {
64
67
  /**
65
- * Type guard to check if a value is a PositiveUint32.
68
+ * Type guard that checks if a value is a positive integer in [1, 2^32).
66
69
  *
67
- * @param value The value to check.
68
- * @returns `true` if the value is a 32-bit positive unsigned integer, `false`
69
- * otherwise.
70
+ * @param value - The value to check
71
+ * @returns `true` if the value is a positive integer in [1, 2^32), `false` otherwise
72
+ * @see {@link isPositiveUint32} for usage examples
70
73
  */
71
74
  is,
72
75
 
73
76
  /**
74
- * The minimum value for a 32-bit positive unsigned integer.
75
- *
76
- * @readonly
77
+ * The smallest value representable as `PositiveUint32` (the lower saturation
78
+ * target of `fromNumber`).
77
79
  */
78
80
  MIN_VALUE,
79
81
 
80
82
  /**
81
- * The maximum value for a 32-bit positive unsigned integer.
82
- *
83
- * @readonly
83
+ * The largest value representable as `PositiveUint32` (the upper saturation
84
+ * target of `fromNumber`).
84
85
  */
85
86
  MAX_VALUE,
86
87
 
87
88
  /**
88
- * Returns the smaller of two PositiveUint32 values.
89
+ * Returns the smallest of the given positive integers.
89
90
  *
90
- * @param a The first PositiveUint32.
91
- * @param b The second PositiveUint32.
92
- * @returns The minimum value as a PositiveUint32.
91
+ * @param values - The positive integers to compare (at least one required)
92
+ * @returns The smallest value as a `PositiveUint32`
93
93
  */
94
94
  min: min_,
95
95
 
96
96
  /**
97
- * Returns the larger of two PositiveUint32 values.
97
+ * Returns the largest of the given positive integers.
98
98
  *
99
- * @param a The first PositiveUint32.
100
- * @param b The second PositiveUint32.
101
- * @returns The maximum value as a PositiveUint32.
99
+ * @param values - The positive integers to compare (at least one required)
100
+ * @returns The largest value as a `PositiveUint32`
102
101
  */
103
102
  max: max_,
104
103
 
105
104
  /**
106
- * Clamps a number to the PositiveUint32 range.
105
+ * Converts an arbitrary `number` into a `PositiveUint32`, rounding to the
106
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
107
+ * MAX_VALUE]`.
108
+ *
109
+ * Unlike `asPositiveUint32`, this is total: out-of-range inputs are clamped
110
+ * to the nearest representable `PositiveUint32` instead of throwing.
107
111
  *
108
- * @param value The number to clamp.
109
- * @returns The value clamped to [1, 4294967295] as a PositiveUint32.
112
+ * @param value - The value to convert
113
+ * @returns The value as a `PositiveUint32`
110
114
  */
111
- clamp,
115
+ fromNumber,
112
116
 
113
117
  /**
114
- * Generates a random PositiveUint32 value within the valid range.
118
+ * Generates a random `PositiveUint32` within the given range.
119
+ *
120
+ * The range is inclusive on both ends.
115
121
  *
116
- * @returns A random PositiveUint32 between 1 and 4294967295.
122
+ * @param min - The minimum value (inclusive)
123
+ * @param max - The maximum value (inclusive)
124
+ * @returns A random `PositiveUint32` in `[min, max]`
117
125
  */
118
126
  random,
119
127
 
120
128
  /**
121
- * Raises a PositiveUint32 to the power of another PositiveUint32.
129
+ * Raises `a` to the power `b`, returning `a ** b` as a `PositiveUint32`
130
+ * (floored to an integer).
122
131
  *
123
- * @param a The base PositiveUint32.
124
- * @param b The exponent PositiveUint32.
125
- * @returns `a ** b` clamped to [1, 4294967295] as a PositiveUint32.
132
+ * @param a - The base positive integer
133
+ * @param b - The exponent positive integer
134
+ * @returns `a ** b` as a `PositiveUint32`
126
135
  */
127
136
  pow,
128
137
 
129
138
  /**
130
- * Adds two PositiveUint32 values.
139
+ * Adds two positive integers, returning `a + b` as a `PositiveUint32`.
131
140
  *
132
- * @param a The first PositiveUint32.
133
- * @param b The second PositiveUint32.
134
- * @returns `a + b` clamped to [1, 4294967295] as a PositiveUint32.
141
+ * @param a - The first positive integer
142
+ * @param b - The second positive integer
143
+ * @returns The sum of `a` and `b` as a `PositiveUint32`
135
144
  */
136
145
  add,
137
146
 
138
147
  /**
139
- * Subtracts one PositiveUint32 from another.
148
+ * Subtracts two positive integers, returning `a - b` as a `PositiveUint32`.
140
149
  *
141
- * @param a The minuend PositiveUint32.
142
- * @param b The subtrahend PositiveUint32.
143
- * @returns `a - b` clamped to [1, 4294967295] as a PositiveUint32 (minimum
144
- * 1).
150
+ * @param a - The first positive integer
151
+ * @param b - The second positive integer
152
+ * @returns The difference of `a` and `b` as a `PositiveUint32`
145
153
  */
146
154
  sub,
147
155
 
148
156
  /**
149
- * Multiplies two PositiveUint32 values.
157
+ * Multiplies two positive integers, returning `a * b` as a `PositiveUint32`.
150
158
  *
151
- * @param a The first PositiveUint32.
152
- * @param b The second PositiveUint32.
153
- * @returns `a * b` clamped to [1, 4294967295] as a PositiveUint32.
159
+ * @param a - The first positive integer
160
+ * @param b - The second positive integer
161
+ * @returns The product of `a` and `b` as a `PositiveUint32`
154
162
  */
155
163
  mul,
156
164
 
157
165
  /**
158
- * Divides one PositiveUint32 by another using floor division.
166
+ * Divides two positive integers using floor division (`⌊a / b⌋`): the result
167
+ * is `a / b` rounded toward negative infinity, as a `PositiveUint32`.
159
168
  *
160
- * @param a The dividend PositiveUint32.
161
- * @param b The divisor PositiveUint32.
162
- * @returns `⌊a / b⌋` clamped to [1, 4294967295] as a PositiveUint32.
169
+ * @param a - The dividend
170
+ * @param b - The divisor (must be non-zero)
171
+ * @returns The floored quotient as a `PositiveUint32`
163
172
  */
164
173
  div,
165
174
  } as const;