ts-data-forge 10.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 (249) hide show
  1. package/dist/array/impl/array-utils-creation.d.mts +3 -3
  2. package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
  3. package/dist/array/impl/array-utils-creation.mjs.map +1 -1
  4. package/dist/array/impl/array-utils-element-access.d.mts +4 -4
  5. package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
  6. package/dist/{guard/as-length-bounded-array.d.mts → array/impl/array-utils-length-bounded-array-cast.d.mts} +9 -9
  7. package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -0
  8. package/dist/{guard/as-length-bounded-array.mjs → array/impl/array-utils-length-bounded-array-cast.mjs} +2 -2
  9. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -0
  10. package/dist/{guard/is-length-bounded-array.d.mts → array/impl/array-utils-length-bounded-array-guard.d.mts} +13 -13
  11. package/dist/array/impl/array-utils-length-bounded-array-guard.d.mts.map +1 -0
  12. package/dist/{guard/is-length-bounded-array.mjs → array/impl/array-utils-length-bounded-array-guard.mjs} +1 -1
  13. package/dist/array/impl/array-utils-length-bounded-array-guard.mjs.map +1 -0
  14. package/dist/array/impl/array-utils-modification.d.mts +9 -9
  15. package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
  16. package/dist/array/impl/array-utils-modification.mjs.map +1 -1
  17. package/dist/array/impl/array-utils-reducing-value.d.mts +9 -9
  18. package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
  19. package/dist/array/impl/array-utils-size.d.mts +3 -3
  20. package/dist/array/impl/array-utils-size.mjs.map +1 -1
  21. package/dist/array/impl/array-utils-slicing.d.mts +9 -9
  22. package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
  23. package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
  24. package/dist/array/impl/array-utils-transformation.d.mts +16 -10
  25. package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
  26. package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
  27. package/dist/array/impl/index.d.mts +2 -0
  28. package/dist/array/impl/index.d.mts.map +1 -1
  29. package/dist/array/impl/index.mjs +2 -0
  30. package/dist/array/impl/index.mjs.map +1 -1
  31. package/dist/entry-point.mjs +1 -3
  32. package/dist/entry-point.mjs.map +1 -1
  33. package/dist/guard/index.d.mts +0 -3
  34. package/dist/guard/index.d.mts.map +1 -1
  35. package/dist/guard/index.mjs +0 -3
  36. package/dist/guard/index.mjs.map +1 -1
  37. package/dist/index.d.mts +1 -0
  38. package/dist/index.d.mts.map +1 -1
  39. package/dist/index.mjs +1 -3
  40. package/dist/index.mjs.map +1 -1
  41. package/dist/number/branded-types/finite-number.d.mts +47 -61
  42. package/dist/number/branded-types/finite-number.d.mts.map +1 -1
  43. package/dist/number/branded-types/finite-number.mjs +37 -41
  44. package/dist/number/branded-types/finite-number.mjs.map +1 -1
  45. package/dist/number/branded-types/int.d.mts +40 -46
  46. package/dist/number/branded-types/int.d.mts.map +1 -1
  47. package/dist/number/branded-types/int.mjs +29 -31
  48. package/dist/number/branded-types/int.mjs.map +1 -1
  49. package/dist/number/branded-types/int16.d.mts +65 -58
  50. package/dist/number/branded-types/int16.d.mts.map +1 -1
  51. package/dist/number/branded-types/int16.mjs +49 -45
  52. package/dist/number/branded-types/int16.mjs.map +1 -1
  53. package/dist/number/branded-types/int32.d.mts +65 -58
  54. package/dist/number/branded-types/int32.d.mts.map +1 -1
  55. package/dist/number/branded-types/int32.mjs +49 -45
  56. package/dist/number/branded-types/int32.mjs.map +1 -1
  57. package/dist/number/branded-types/negative-finite-number.d.mts +68 -59
  58. package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
  59. package/dist/number/branded-types/negative-finite-number.mjs +52 -46
  60. package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
  61. package/dist/number/branded-types/negative-int.d.mts +60 -48
  62. package/dist/number/branded-types/negative-int.d.mts.map +1 -1
  63. package/dist/number/branded-types/negative-int.mjs +40 -36
  64. package/dist/number/branded-types/negative-int.mjs.map +1 -1
  65. package/dist/number/branded-types/negative-safe-int.d.mts +57 -56
  66. package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
  67. package/dist/number/branded-types/negative-safe-int.mjs +40 -41
  68. package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
  69. package/dist/number/branded-types/non-negative-finite-number.d.mts +74 -64
  70. package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
  71. package/dist/number/branded-types/non-negative-finite-number.mjs +58 -51
  72. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
  73. package/dist/number/branded-types/non-negative-int16.d.mts +64 -57
  74. package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
  75. package/dist/number/branded-types/non-negative-int16.mjs +47 -43
  76. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
  77. package/dist/number/branded-types/non-negative-int32.d.mts +64 -58
  78. package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
  79. package/dist/number/branded-types/non-negative-int32.mjs +47 -44
  80. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
  81. package/dist/number/branded-types/non-positive-finite-number.d.mts +64 -54
  82. package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
  83. package/dist/number/branded-types/non-positive-finite-number.mjs +48 -41
  84. package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
  85. package/dist/number/branded-types/non-positive-int.d.mts +41 -146
  86. package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
  87. package/dist/number/branded-types/non-positive-int.mjs +27 -107
  88. package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
  89. package/dist/number/branded-types/non-positive-safe-int.d.mts +54 -53
  90. package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
  91. package/dist/number/branded-types/non-positive-safe-int.mjs +37 -39
  92. package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
  93. package/dist/number/branded-types/non-zero-finite-number.d.mts +62 -49
  94. package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
  95. package/dist/number/branded-types/non-zero-finite-number.mjs +46 -37
  96. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
  97. package/dist/number/branded-types/non-zero-int.d.mts +51 -38
  98. package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
  99. package/dist/number/branded-types/non-zero-int.mjs +31 -27
  100. package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
  101. package/dist/number/branded-types/non-zero-int16.d.mts +52 -53
  102. package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
  103. package/dist/number/branded-types/non-zero-int16.mjs +36 -39
  104. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
  105. package/dist/number/branded-types/non-zero-int32.d.mts +52 -54
  106. package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
  107. package/dist/number/branded-types/non-zero-int32.mjs +36 -40
  108. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
  109. package/dist/number/branded-types/non-zero-safe-int.d.mts +53 -54
  110. package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
  111. package/dist/number/branded-types/non-zero-safe-int.mjs +36 -40
  112. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
  113. package/dist/number/branded-types/non-zero-uint16.d.mts +52 -53
  114. package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
  115. package/dist/number/branded-types/non-zero-uint16.mjs +35 -39
  116. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
  117. package/dist/number/branded-types/non-zero-uint32.d.mts +52 -53
  118. package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
  119. package/dist/number/branded-types/non-zero-uint32.mjs +35 -39
  120. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
  121. package/dist/number/branded-types/positive-finite-number.d.mts +74 -63
  122. package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
  123. package/dist/number/branded-types/positive-finite-number.mjs +58 -50
  124. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
  125. package/dist/number/branded-types/positive-int.d.mts +46 -68
  126. package/dist/number/branded-types/positive-int.d.mts.map +1 -1
  127. package/dist/number/branded-types/positive-int.mjs +34 -49
  128. package/dist/number/branded-types/positive-int.mjs.map +1 -1
  129. package/dist/number/branded-types/positive-int16.d.mts +61 -57
  130. package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
  131. package/dist/number/branded-types/positive-int16.mjs +44 -43
  132. package/dist/number/branded-types/positive-int16.mjs.map +1 -1
  133. package/dist/number/branded-types/positive-int32.d.mts +61 -57
  134. package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
  135. package/dist/number/branded-types/positive-int32.mjs +44 -43
  136. package/dist/number/branded-types/positive-int32.mjs.map +1 -1
  137. package/dist/number/branded-types/positive-safe-int.d.mts +62 -57
  138. package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
  139. package/dist/number/branded-types/positive-safe-int.mjs +45 -43
  140. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
  141. package/dist/number/branded-types/positive-uint16.d.mts +61 -57
  142. package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
  143. package/dist/number/branded-types/positive-uint16.mjs +44 -43
  144. package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
  145. package/dist/number/branded-types/positive-uint32.d.mts +61 -58
  146. package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
  147. package/dist/number/branded-types/positive-uint32.mjs +44 -44
  148. package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
  149. package/dist/number/branded-types/safe-int.d.mts +43 -62
  150. package/dist/number/branded-types/safe-int.d.mts.map +1 -1
  151. package/dist/number/branded-types/safe-int.mjs +35 -42
  152. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  153. package/dist/number/branded-types/safe-uint.d.mts +62 -57
  154. package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
  155. package/dist/number/branded-types/safe-uint.mjs +46 -44
  156. package/dist/number/branded-types/safe-uint.mjs.map +1 -1
  157. package/dist/number/branded-types/uint.d.mts +63 -50
  158. package/dist/number/branded-types/uint.d.mts.map +1 -1
  159. package/dist/number/branded-types/uint.mjs +42 -39
  160. package/dist/number/branded-types/uint.mjs.map +1 -1
  161. package/dist/number/branded-types/uint16.d.mts +60 -58
  162. package/dist/number/branded-types/uint16.d.mts.map +1 -1
  163. package/dist/number/branded-types/uint16.mjs +44 -43
  164. package/dist/number/branded-types/uint16.mjs.map +1 -1
  165. package/dist/number/branded-types/uint32.d.mts +59 -55
  166. package/dist/number/branded-types/uint32.d.mts.map +1 -1
  167. package/dist/number/branded-types/uint32.mjs +42 -42
  168. package/dist/number/branded-types/uint32.mjs.map +1 -1
  169. package/dist/number/enum/int8.d.mts +56 -65
  170. package/dist/number/enum/int8.d.mts.map +1 -1
  171. package/dist/number/enum/int8.mjs +44 -43
  172. package/dist/number/enum/int8.mjs.map +1 -1
  173. package/dist/number/enum/uint8.d.mts +60 -58
  174. package/dist/number/enum/uint8.d.mts.map +1 -1
  175. package/dist/number/enum/uint8.mjs +44 -43
  176. package/dist/number/enum/uint8.mjs.map +1 -1
  177. package/dist/string/index.d.mts +2 -0
  178. package/dist/string/index.d.mts.map +1 -0
  179. package/dist/string/index.mjs +2 -0
  180. package/dist/string/index.mjs.map +1 -0
  181. package/dist/string/str.d.mts +273 -0
  182. package/dist/string/str.d.mts.map +1 -0
  183. package/dist/string/str.mjs +42 -0
  184. package/dist/string/str.mjs.map +1 -0
  185. package/package.json +31 -92
  186. package/src/array/impl/array-utils-creation.mts +2 -1
  187. package/src/array/impl/array-utils-element-access.mts +3 -3
  188. package/src/array/impl/array-utils-element-access.test.mts +3 -3
  189. package/src/{guard/as-length-bounded-array.mts → array/impl/array-utils-length-bounded-array-cast.mts} +9 -9
  190. package/src/{guard/as-length-bounded-array.test.mts → array/impl/array-utils-length-bounded-array-cast.test.mts} +2 -2
  191. package/src/{guard/is-length-bounded-array.mts → array/impl/array-utils-length-bounded-array-guard.mts} +12 -12
  192. package/src/{guard/is-length-bounded-array.test.mts → array/impl/array-utils-length-bounded-array-guard.test.mts} +2 -2
  193. package/src/array/impl/array-utils-modification.mts +9 -8
  194. package/src/array/impl/array-utils-modification.test.mts +6 -1
  195. package/src/array/impl/array-utils-reducing-value.mts +9 -9
  196. package/src/array/impl/array-utils-size.mts +2 -2
  197. package/src/array/impl/array-utils-slicing.mts +24 -13
  198. package/src/array/impl/array-utils-transformation.mts +18 -12
  199. package/src/array/impl/array-utils-transformation.test.mts +12 -12
  200. package/src/array/impl/index.mts +2 -0
  201. package/src/guard/index.mts +0 -3
  202. package/src/index.mts +1 -0
  203. package/src/number/branded-types/finite-number.mts +47 -61
  204. package/src/number/branded-types/int.mts +40 -46
  205. package/src/number/branded-types/int16.mts +65 -58
  206. package/src/number/branded-types/int32.mts +65 -58
  207. package/src/number/branded-types/negative-finite-number.mts +68 -68
  208. package/src/number/branded-types/negative-int.mts +60 -57
  209. package/src/number/branded-types/negative-safe-int.mts +57 -65
  210. package/src/number/branded-types/non-negative-finite-number.mts +74 -64
  211. package/src/number/branded-types/non-negative-int16.mts +64 -57
  212. package/src/number/branded-types/non-negative-int32.mts +64 -58
  213. package/src/number/branded-types/non-positive-finite-number.mts +64 -54
  214. package/src/number/branded-types/non-positive-int.mts +41 -146
  215. package/src/number/branded-types/non-positive-safe-int.mts +54 -53
  216. package/src/number/branded-types/non-zero-finite-number.mts +62 -51
  217. package/src/number/branded-types/non-zero-int.mts +51 -38
  218. package/src/number/branded-types/non-zero-int16.mts +52 -53
  219. package/src/number/branded-types/non-zero-int32.mts +52 -54
  220. package/src/number/branded-types/non-zero-safe-int.mts +53 -54
  221. package/src/number/branded-types/non-zero-uint16.mts +52 -53
  222. package/src/number/branded-types/non-zero-uint32.mts +52 -53
  223. package/src/number/branded-types/positive-finite-number.mts +74 -63
  224. package/src/number/branded-types/positive-int.mts +46 -68
  225. package/src/number/branded-types/positive-int16.mts +61 -57
  226. package/src/number/branded-types/positive-int32.mts +61 -57
  227. package/src/number/branded-types/positive-safe-int.mts +62 -57
  228. package/src/number/branded-types/positive-uint16.mts +61 -57
  229. package/src/number/branded-types/positive-uint32.mts +61 -58
  230. package/src/number/branded-types/safe-int.mts +43 -62
  231. package/src/number/branded-types/safe-uint.mts +62 -57
  232. package/src/number/branded-types/uint.mts +63 -50
  233. package/src/number/branded-types/uint16.mts +60 -58
  234. package/src/number/branded-types/uint32.mts +59 -55
  235. package/src/number/enum/int8.mts +56 -65
  236. package/src/number/enum/uint8.mts +60 -58
  237. package/src/string/index.mts +1 -0
  238. package/src/string/str.mts +371 -0
  239. package/src/string/str.test.mts +215 -0
  240. package/dist/guard/as-length-bounded-array.d.mts.map +0 -1
  241. package/dist/guard/as-length-bounded-array.mjs.map +0 -1
  242. package/dist/guard/is-length-bounded-array.d.mts.map +0 -1
  243. package/dist/guard/is-length-bounded-array.mjs.map +0 -1
  244. package/dist/guard/is-length-bounded-string.d.mts +0 -163
  245. package/dist/guard/is-length-bounded-string.d.mts.map +0 -1
  246. package/dist/guard/is-length-bounded-string.mjs +0 -7
  247. package/dist/guard/is-length-bounded-string.mjs.map +0 -1
  248. package/src/guard/is-length-bounded-string.mts +0 -199
  249. package/src/guard/is-length-bounded-string.test.mts +0 -170
@@ -35,8 +35,8 @@ const {
35
35
  /**
36
36
  * Type guard that checks if a value is a positive integer.
37
37
  *
38
- * A positive integer is any integer greater than zero (>= 1). This excludes
39
- * zero, negative numbers, and non-integers.
38
+ * Returns `true` for a positive integer — a value with no fractional component,
39
+ * including values outside the safe integer range (unlike `SafeInt`).
40
40
  *
41
41
  * @example
42
42
  *
@@ -54,11 +54,10 @@ const {
54
54
  export const isPositiveInt = is;
55
55
 
56
56
  /**
57
- * Casts a number to a PositiveInt branded type.
57
+ * Casts a `number` to the `PositiveInt` branded type.
58
58
  *
59
- * This function validates that the input is a positive integer (>= 1) and
60
- * returns it with the PositiveInt brand. This ensures type safety for
61
- * operations that require strictly positive integer values.
59
+ * Validates that the value is a positive integer and returns it with the
60
+ * `PositiveInt` brand. Throws a `TypeError` otherwise.
62
61
  *
63
62
  * @example
64
63
  *
@@ -71,26 +70,20 @@ export const isPositiveInt = is;
71
70
  * ```
72
71
  *
73
72
  * @param value - The value to cast
74
- * @returns The value as a PositiveInt branded type
73
+ * @returns The value as a `PositiveInt`
75
74
  * @throws {TypeError} If the value is not a positive integer
76
75
  */
77
76
  export const asPositiveInt = castType;
78
77
 
79
78
  /**
80
- * Namespace providing type-safe operations for PositiveInt branded types.
79
+ * Namespace providing type-safe operations for the `PositiveInt` branded type.
81
80
  *
82
- * PositiveInt represents integers that are strictly greater than zero (>= 1).
83
- * All operations automatically clamp results to maintain the positive
84
- * constraint, ensuring that arithmetic operations never produce zero or
85
- * negative values.
81
+ * The `PositiveInt` type represents a positive integer. Division (`div`) uses
82
+ * floor division.
86
83
  *
87
- * This type is essential for:
88
- *
89
- * - Array lengths and sizes (length >= 1)
90
- * - Counts and quantities that must be positive
91
- * - Denominators in division operations
92
- * - Loop counters and iteration counts
93
- * - Database primary keys and IDs
84
+ * Unlike `SafeInt`, `PositiveInt` allows values outside the safe integer range
85
+ * (±2^53 − 1), so very large magnitudes may lose precision in JavaScript's
86
+ * `number` type.
94
87
  */
95
88
  export const PositiveInt = {
96
89
  /**
@@ -113,17 +106,12 @@ export const PositiveInt = {
113
106
  is,
114
107
 
115
108
  /**
116
- * The minimum value for a PositiveInt.
117
- *
118
- * @readonly
109
+ * The smallest value representable as `PositiveInt`.
119
110
  */
120
111
  MIN_VALUE,
121
112
 
122
113
  /**
123
- * Returns the minimum value from a list of positive integers.
124
- *
125
- * Since all inputs are guaranteed to be >= 1, the result is also guaranteed
126
- * to be a positive integer.
114
+ * Returns the smallest of the given positive integers.
127
115
  *
128
116
  * @example
129
117
  *
@@ -138,12 +126,12 @@ export const PositiveInt = {
138
126
  * ```
139
127
  *
140
128
  * @param values - The positive integers to compare (at least one required)
141
- * @returns The smallest value as a PositiveInt
129
+ * @returns The smallest value as a `PositiveInt`
142
130
  */
143
131
  min: min_,
144
132
 
145
133
  /**
146
- * Returns the maximum value from a list of positive integers.
134
+ * Returns the largest of the given positive integers.
147
135
  *
148
136
  * @example
149
137
  *
@@ -158,15 +146,13 @@ export const PositiveInt = {
158
146
  * ```
159
147
  *
160
148
  * @param values - The positive integers to compare (at least one required)
161
- * @returns The largest value as a PositiveInt
149
+ * @returns The largest value as a `PositiveInt`
162
150
  */
163
151
  max: max_,
164
152
 
165
153
  /**
166
- * Clamps a number to the positive integer range.
167
- *
168
- * Since PositiveInt has a minimum value of 1, this function ensures that any
169
- * input less than 1 is clamped to 1.
154
+ * Clamps a `number` into the `PositiveInt` range, rounding to the nearest
155
+ * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
170
156
  *
171
157
  * @example
172
158
  *
@@ -180,16 +166,15 @@ export const PositiveInt = {
180
166
  * assert.isTrue(withinRange === 10);
181
167
  * ```
182
168
  *
183
- * @param value - The number to clamp
184
- * @returns The value clamped to >= 1 as a PositiveInt
169
+ * @param value - The value to clamp
170
+ * @returns The clamped value as a `PositiveInt`
185
171
  */
186
172
  clamp,
187
173
 
188
174
  /**
189
- * Generates a random positive integer within the specified range (inclusive).
175
+ * Generates a random `PositiveInt` within the given range.
190
176
  *
191
- * Both bounds are inclusive, and both min and max must be positive integers.
192
- * If min > max, they are automatically swapped.
177
+ * The range is inclusive on both ends.
193
178
  *
194
179
  * @example
195
180
  *
@@ -205,15 +190,15 @@ export const PositiveInt = {
205
190
  * assert.isTrue(randomValue >= 3 && randomValue <= 6);
206
191
  * ```
207
192
  *
208
- * @param min - The minimum value (inclusive, must be >= 1)
209
- * @param max - The maximum value (inclusive, must be >= min)
210
- * @returns A random PositiveInt in the range [min, max]
193
+ * @param min - The minimum value (inclusive)
194
+ * @param max - The maximum value (inclusive)
195
+ * @returns A random `PositiveInt` in `[min, max]`
211
196
  */
212
197
  random,
213
198
 
214
199
  /**
215
- * Raises a positive integer to a power, ensuring the result is never less
216
- * than 1.
200
+ * Raises `a` to the power `b`, returning `a ** b` as a `PositiveInt` (floored
201
+ * to an integer).
217
202
  *
218
203
  * @example
219
204
  *
@@ -229,12 +214,12 @@ export const PositiveInt = {
229
214
  *
230
215
  * @param a - The base positive integer
231
216
  * @param b - The exponent positive integer
232
- * @returns `a ** b` as a PositiveInt, but never less than 1
217
+ * @returns `a ** b` as a `PositiveInt`
233
218
  */
234
219
  pow,
235
220
 
236
221
  /**
237
- * Adds two positive integers, ensuring the result is never less than 1.
222
+ * Adds two positive integers, returning `a + b` as a `PositiveInt`.
238
223
  *
239
224
  * @example
240
225
  *
@@ -244,17 +229,14 @@ export const PositiveInt = {
244
229
  * assert.isTrue(sum === 9);
245
230
  * ```
246
231
  *
247
- * @param a - First positive integer
248
- * @param b - Second positive integer
249
- * @returns `a + b` as a PositiveInt, but never less than 1
232
+ * @param a - The first positive integer
233
+ * @param b - The second positive integer
234
+ * @returns The sum of `a` and `b` as a `PositiveInt`
250
235
  */
251
236
  add,
252
237
 
253
238
  /**
254
- * Subtracts two positive integers, clamping the result to remain positive.
255
- *
256
- * If the mathematical result would be <= 0, it is clamped to 1 to maintain
257
- * the positive integer constraint.
239
+ * Subtracts two positive integers, returning `a - b` as a `PositiveInt`.
258
240
  *
259
241
  * @example
260
242
  *
@@ -264,14 +246,14 @@ export const PositiveInt = {
264
246
  * assert.isTrue(difference === 1);
265
247
  * ```
266
248
  *
267
- * @param a - The minuend (positive integer)
268
- * @param b - The subtrahend (positive integer)
269
- * @returns `max(1, a - b)` as a PositiveInt
249
+ * @param a - The first positive integer
250
+ * @param b - The second positive integer
251
+ * @returns The difference of `a` and `b` as a `PositiveInt`
270
252
  */
271
253
  sub,
272
254
 
273
255
  /**
274
- * Multiplies two positive integers, ensuring the result is never less than 1.
256
+ * Multiplies two positive integers, returning `a * b` as a `PositiveInt`.
275
257
  *
276
258
  * @example
277
259
  *
@@ -281,19 +263,15 @@ export const PositiveInt = {
281
263
  * assert.isTrue(product === 21);
282
264
  * ```
283
265
  *
284
- * @param a - First positive integer
285
- * @param b - Second positive integer
286
- * @returns `a * b` as a PositiveInt, but never less than 1
266
+ * @param a - The first positive integer
267
+ * @param b - The second positive integer
268
+ * @returns The product of `a` and `b` as a `PositiveInt`
287
269
  */
288
270
  mul,
289
271
 
290
272
  /**
291
- * Divides two positive integers using floor division, clamping to remain
292
- * positive.
293
- *
294
- * Performs mathematical floor division: `⌊a / b⌋`. If the result would be 0
295
- * (when a < b), it is clamped to 1 to maintain the positive integer
296
- * constraint.
273
+ * Divides two positive integers using floor division (`⌊a / b⌋`): the result
274
+ * is `a / b` rounded toward negative infinity, as a `PositiveInt`.
297
275
  *
298
276
  * @example
299
277
  *
@@ -307,9 +285,9 @@ export const PositiveInt = {
307
285
  * assert.isTrue(clamped === 1);
308
286
  * ```
309
287
  *
310
- * @param a - The dividend (positive integer)
311
- * @param b - The divisor (positive integer, guaranteed non-zero)
312
- * @returns `max(1, ⌊a / b⌋)` as a PositiveInt
288
+ * @param a - The dividend
289
+ * @param b - The divisor (must be non-zero)
290
+ * @returns The floored quotient as a `PositiveInt`
313
291
  */
314
292
  div,
315
293
  } as const;
@@ -34,131 +34,135 @@ const {
34
34
  } as const);
35
35
 
36
36
  /**
37
- * Checks if a number is a PositiveInt16 (16-bit positive signed integer in the
38
- * range [1, 2^15)).
37
+ * Type guard that checks if a value is a positive integer in [1, 2^15).
39
38
  *
40
- * @param value The value to check.
41
- * @returns `true` if the value is a PositiveInt16, `false` otherwise.
39
+ * Returns `true` for a positive integer in [1, 2^15) — 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^15), `false` otherwise
42
44
  */
43
45
  export const isPositiveInt16 = is;
44
46
 
45
47
  /**
46
- * Casts a number to a PositiveInt16 type.
48
+ * Casts a `number` to the `PositiveInt16` branded type.
49
+ *
50
+ * Validates that the value is a positive integer in [1, 2^15) and returns it
51
+ * with the `PositiveInt16` brand. Throws a `TypeError` otherwise.
47
52
  *
48
- * @param value The value to cast.
49
- * @returns The value as a PositiveInt16 type.
50
- * @throws {TypeError} If the value is not a positive integer in [1, 2^15).
53
+ * @param value - The value to cast
54
+ * @returns The value as a `PositiveInt16`
55
+ * @throws {TypeError} If the value is not a positive integer in [1, 2^15)
51
56
  */
52
57
  export const asPositiveInt16 = castType;
53
58
 
54
59
  /**
55
- * Namespace providing type-safe arithmetic operations for 16-bit positive
56
- * integers.
60
+ * Namespace providing type-safe operations for the `PositiveInt16` branded
61
+ * type.
57
62
  *
58
- * All operations automatically clamp results to the valid PositiveInt16 range
59
- * [1, 32767]. This ensures that all arithmetic maintains the 16-bit positive
60
- * integer constraint, with results below 1 clamped to MIN_VALUE and overflow
61
- * results clamped to MAX_VALUE.
63
+ * The `PositiveInt16` type represents a positive integer in [1, 2^15). Division
64
+ * (`div`) uses floor division.
62
65
  */
63
66
  export const PositiveInt16 = {
64
67
  /**
65
- * Type guard to check if a value is a PositiveInt16.
68
+ * Type guard that checks if a value is a positive integer in [1, 2^15).
66
69
  *
67
- * @param value The value to check.
68
- * @returns `true` if the value is a 16-bit positive integer, `false`
69
- * otherwise.
70
+ * @param value - The value to check
71
+ * @returns `true` if the value is a positive integer in [1, 2^15), `false` otherwise
72
+ * @see {@link isPositiveInt16} for usage examples
70
73
  */
71
74
  is,
72
75
 
73
76
  /**
74
- * The minimum value for a 16-bit positive integer.
75
- *
76
- * @readonly
77
+ * The smallest value representable as `PositiveInt16`.
77
78
  */
78
79
  MIN_VALUE,
79
80
 
80
81
  /**
81
- * The maximum value for a 16-bit positive integer.
82
- *
83
- * @readonly
82
+ * The largest value representable as `PositiveInt16`.
84
83
  */
85
84
  MAX_VALUE,
86
85
 
87
86
  /**
88
- * Returns the smaller of two PositiveInt16 values.
87
+ * Returns the smallest of the given positive integers.
89
88
  *
90
- * @param a The first PositiveInt16.
91
- * @param b The second PositiveInt16.
92
- * @returns The minimum value as a PositiveInt16.
89
+ * @param values - The positive integers to compare (at least one required)
90
+ * @returns The smallest value as a `PositiveInt16`
93
91
  */
94
92
  min: min_,
95
93
 
96
94
  /**
97
- * Returns the larger of two PositiveInt16 values.
95
+ * Returns the largest of the given positive integers.
98
96
  *
99
- * @param a The first PositiveInt16.
100
- * @param b The second PositiveInt16.
101
- * @returns The maximum value as a PositiveInt16.
97
+ * @param values - The positive integers to compare (at least one required)
98
+ * @returns The largest value as a `PositiveInt16`
102
99
  */
103
100
  max: max_,
104
101
 
105
102
  /**
106
- * Clamps a number to the PositiveInt16 range.
103
+ * Clamps a `number` into the `PositiveInt16` 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 [1, 32767] as a PositiveInt16.
106
+ * @param value - The value to clamp
107
+ * @returns The clamped value as a `PositiveInt16`
110
108
  */
111
109
  clamp,
112
110
 
113
111
  /**
114
- * Generates a random PositiveInt16 value within the valid range.
112
+ * Generates a random `PositiveInt16` within the given range.
113
+ *
114
+ * The range is inclusive on both ends.
115
115
  *
116
- * @returns A random PositiveInt16 between 1 and 32767.
116
+ * @param min - The minimum value (inclusive)
117
+ * @param max - The maximum value (inclusive)
118
+ * @returns A random `PositiveInt16` in `[min, max]`
117
119
  */
118
120
  random,
119
121
 
120
122
  /**
121
- * Raises a PositiveInt16 to the power of another PositiveInt16.
123
+ * Raises `a` to the power `b`, returning `a ** b` as a `PositiveInt16`
124
+ * (floored to an integer).
122
125
  *
123
- * @param a The base PositiveInt16.
124
- * @param b The exponent PositiveInt16.
125
- * @returns `a ** b` clamped to [1, 32767] as a PositiveInt16.
126
+ * @param a - The base positive integer
127
+ * @param b - The exponent positive integer
128
+ * @returns `a ** b` as a `PositiveInt16`
126
129
  */
127
130
  pow,
128
131
 
129
132
  /**
130
- * Adds two PositiveInt16 values.
133
+ * Adds two positive integers, returning `a + b` as a `PositiveInt16`.
131
134
  *
132
- * @param a The first PositiveInt16.
133
- * @param b The second PositiveInt16.
134
- * @returns `a + b` clamped to [1, 32767] as a PositiveInt16.
135
+ * @param a - The first positive integer
136
+ * @param b - The second positive integer
137
+ * @returns The sum of `a` and `b` as a `PositiveInt16`
135
138
  */
136
139
  add,
137
140
 
138
141
  /**
139
- * Subtracts one PositiveInt16 from another.
142
+ * Subtracts two positive integers, returning `a - b` as a `PositiveInt16`.
140
143
  *
141
- * @param a The minuend PositiveInt16.
142
- * @param b The subtrahend PositiveInt16.
143
- * @returns `a - b` clamped to [1, 32767] as a PositiveInt16 (minimum 1).
144
+ * @param a - The first positive integer
145
+ * @param b - The second positive integer
146
+ * @returns The difference of `a` and `b` as a `PositiveInt16`
144
147
  */
145
148
  sub,
146
149
 
147
150
  /**
148
- * Multiplies two PositiveInt16 values.
151
+ * Multiplies two positive integers, returning `a * b` as a `PositiveInt16`.
149
152
  *
150
- * @param a The first PositiveInt16.
151
- * @param b The second PositiveInt16.
152
- * @returns `a * b` clamped to [1, 32767] as a PositiveInt16.
153
+ * @param a - The first positive integer
154
+ * @param b - The second positive integer
155
+ * @returns The product of `a` and `b` as a `PositiveInt16`
153
156
  */
154
157
  mul,
155
158
 
156
159
  /**
157
- * Divides one PositiveInt16 by another using floor division.
160
+ * Divides two positive integers using floor division (`⌊a / b⌋`): the result
161
+ * is `a / b` rounded toward negative infinity, as a `PositiveInt16`.
158
162
  *
159
- * @param a The dividend PositiveInt16.
160
- * @param b The divisor PositiveInt16.
161
- * @returns `⌊a / b⌋` clamped to [1, 32767] as a PositiveInt16.
163
+ * @param a - The dividend
164
+ * @param b - The divisor (must be non-zero)
165
+ * @returns The floored quotient as a `PositiveInt16`
162
166
  */
163
167
  div,
164
168
  } as const;
@@ -34,131 +34,135 @@ const {
34
34
  } as const);
35
35
 
36
36
  /**
37
- * Checks if a number is a PositiveInt32 (32-bit positive signed integer in the
38
- * range [1, 2^31)).
37
+ * Type guard that checks if a value is a positive integer in [1, 2^31).
39
38
  *
40
- * @param value The value to check.
41
- * @returns `true` if the value is a PositiveInt32, `false` otherwise.
39
+ * Returns `true` for a positive integer in [1, 2^31) — 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^31), `false` otherwise
42
44
  */
43
45
  export const isPositiveInt32 = is;
44
46
 
45
47
  /**
46
- * Casts a number to a PositiveInt32 type.
48
+ * Casts a `number` to the `PositiveInt32` branded type.
49
+ *
50
+ * Validates that the value is a positive integer in [1, 2^31) and returns it
51
+ * with the `PositiveInt32` brand. Throws a `TypeError` otherwise.
47
52
  *
48
- * @param value The value to cast.
49
- * @returns The value as a PositiveInt32 type.
50
- * @throws {TypeError} If the value is not a positive integer in [1, 2^31).
53
+ * @param value - The value to cast
54
+ * @returns The value as a `PositiveInt32`
55
+ * @throws {TypeError} If the value is not a positive integer in [1, 2^31)
51
56
  */
52
57
  export const asPositiveInt32 = castType;
53
58
 
54
59
  /**
55
- * Namespace providing type-safe arithmetic operations for 32-bit positive
56
- * integers.
60
+ * Namespace providing type-safe operations for the `PositiveInt32` branded
61
+ * type.
57
62
  *
58
- * All operations automatically clamp results to the valid PositiveInt32 range
59
- * [1, 2147483647]. This ensures that all arithmetic maintains the 32-bit
60
- * positive integer constraint, with results below 1 clamped to MIN_VALUE and
61
- * overflow results clamped to MAX_VALUE.
63
+ * The `PositiveInt32` type represents a positive integer in [1, 2^31). Division
64
+ * (`div`) uses floor division.
62
65
  */
63
66
  export const PositiveInt32 = {
64
67
  /**
65
- * Type guard to check if a value is a PositiveInt32.
68
+ * Type guard that checks if a value is a positive integer in [1, 2^31).
66
69
  *
67
- * @param value The value to check.
68
- * @returns `true` if the value is a 32-bit positive integer, `false`
69
- * otherwise.
70
+ * @param value - The value to check
71
+ * @returns `true` if the value is a positive integer in [1, 2^31), `false` otherwise
72
+ * @see {@link isPositiveInt32} for usage examples
70
73
  */
71
74
  is,
72
75
 
73
76
  /**
74
- * The minimum value for a 32-bit positive integer.
75
- *
76
- * @readonly
77
+ * The smallest value representable as `PositiveInt32`.
77
78
  */
78
79
  MIN_VALUE,
79
80
 
80
81
  /**
81
- * The maximum value for a 32-bit positive integer.
82
- *
83
- * @readonly
82
+ * The largest value representable as `PositiveInt32`.
84
83
  */
85
84
  MAX_VALUE,
86
85
 
87
86
  /**
88
- * Returns the smaller of two PositiveInt32 values.
87
+ * Returns the smallest of the given positive integers.
89
88
  *
90
- * @param a The first PositiveInt32.
91
- * @param b The second PositiveInt32.
92
- * @returns The minimum value as a PositiveInt32.
89
+ * @param values - The positive integers to compare (at least one required)
90
+ * @returns The smallest value as a `PositiveInt32`
93
91
  */
94
92
  min: min_,
95
93
 
96
94
  /**
97
- * Returns the larger of two PositiveInt32 values.
95
+ * Returns the largest of the given positive integers.
98
96
  *
99
- * @param a The first PositiveInt32.
100
- * @param b The second PositiveInt32.
101
- * @returns The maximum value as a PositiveInt32.
97
+ * @param values - The positive integers to compare (at least one required)
98
+ * @returns The largest value as a `PositiveInt32`
102
99
  */
103
100
  max: max_,
104
101
 
105
102
  /**
106
- * Clamps a number to the PositiveInt32 range.
103
+ * Clamps a `number` into the `PositiveInt32` 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 [1, 2147483647] as a PositiveInt32.
106
+ * @param value - The value to clamp
107
+ * @returns The clamped value as a `PositiveInt32`
110
108
  */
111
109
  clamp,
112
110
 
113
111
  /**
114
- * Generates a random PositiveInt32 value within the valid range.
112
+ * Generates a random `PositiveInt32` within the given range.
113
+ *
114
+ * The range is inclusive on both ends.
115
115
  *
116
- * @returns A random PositiveInt32 between 1 and 2147483647.
116
+ * @param min - The minimum value (inclusive)
117
+ * @param max - The maximum value (inclusive)
118
+ * @returns A random `PositiveInt32` in `[min, max]`
117
119
  */
118
120
  random,
119
121
 
120
122
  /**
121
- * Raises a PositiveInt32 to the power of another PositiveInt32.
123
+ * Raises `a` to the power `b`, returning `a ** b` as a `PositiveInt32`
124
+ * (floored to an integer).
122
125
  *
123
- * @param a The base PositiveInt32.
124
- * @param b The exponent PositiveInt32.
125
- * @returns `a ** b` clamped to [1, 2147483647] as a PositiveInt32.
126
+ * @param a - The base positive integer
127
+ * @param b - The exponent positive integer
128
+ * @returns `a ** b` as a `PositiveInt32`
126
129
  */
127
130
  pow,
128
131
 
129
132
  /**
130
- * Adds two PositiveInt32 values.
133
+ * Adds two positive integers, returning `a + b` as a `PositiveInt32`.
131
134
  *
132
- * @param a The first PositiveInt32.
133
- * @param b The second PositiveInt32.
134
- * @returns `a + b` clamped to [1, 2147483647] as a PositiveInt32.
135
+ * @param a - The first positive integer
136
+ * @param b - The second positive integer
137
+ * @returns The sum of `a` and `b` as a `PositiveInt32`
135
138
  */
136
139
  add,
137
140
 
138
141
  /**
139
- * Subtracts one PositiveInt32 from another.
142
+ * Subtracts two positive integers, returning `a - b` as a `PositiveInt32`.
140
143
  *
141
- * @param a The minuend PositiveInt32.
142
- * @param b The subtrahend PositiveInt32.
143
- * @returns `a - b` clamped to [1, 2147483647] as a PositiveInt32 (minimum 1).
144
+ * @param a - The first positive integer
145
+ * @param b - The second positive integer
146
+ * @returns The difference of `a` and `b` as a `PositiveInt32`
144
147
  */
145
148
  sub,
146
149
 
147
150
  /**
148
- * Multiplies two PositiveInt32 values.
151
+ * Multiplies two positive integers, returning `a * b` as a `PositiveInt32`.
149
152
  *
150
- * @param a The first PositiveInt32.
151
- * @param b The second PositiveInt32.
152
- * @returns `a * b` clamped to [1, 2147483647] as a PositiveInt32.
153
+ * @param a - The first positive integer
154
+ * @param b - The second positive integer
155
+ * @returns The product of `a` and `b` as a `PositiveInt32`
153
156
  */
154
157
  mul,
155
158
 
156
159
  /**
157
- * Divides one PositiveInt32 by another using floor division.
160
+ * Divides two positive integers using floor division (`⌊a / b⌋`): the result
161
+ * is `a / b` rounded toward negative infinity, as a `PositiveInt32`.
158
162
  *
159
- * @param a The dividend PositiveInt32.
160
- * @param b The divisor PositiveInt32.
161
- * @returns `⌊a / b⌋` clamped to [1, 2147483647] as a PositiveInt32.
163
+ * @param a - The dividend
164
+ * @param b - The divisor (must be non-zero)
165
+ * @returns The floored quotient as a `PositiveInt32`
162
166
  */
163
167
  div,
164
168
  } as const;