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
@@ -34,132 +34,138 @@ const {
34
34
  } as const);
35
35
 
36
36
  /**
37
- * Checks if a number is a NonNegativeInt32 (32-bit non-negative signed integer
38
- * in the range [0, 2^31)).
37
+ * Type guard that checks if a value is a non-negative integer in [0, 2^31).
39
38
  *
40
- * @param value The value to check.
41
- * @returns `true` if the value is a NonNegativeInt32, `false` otherwise.
39
+ * Returns `true` for a non-negative integer in [0, 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 non-negative integer in [0, 2^31), `false` otherwise
42
44
  */
43
45
  export const isNonNegativeInt32 = is;
44
46
 
45
47
  /**
46
- * Casts a number to a NonNegativeInt32 type.
48
+ * Casts a `number` to the `NonNegativeInt32` branded type.
49
+ *
50
+ * Validates that the value is a non-negative integer in [0, 2^31) and returns
51
+ * it with the `NonNegativeInt32` brand. Throws a `TypeError` otherwise.
47
52
  *
48
- * @param value The value to cast.
49
- * @returns The value as a NonNegativeInt32 type.
50
- * @throws {TypeError} If the value is not a non-negative integer in [0, 2^31).
53
+ * @param value - The value to cast
54
+ * @returns The value as a `NonNegativeInt32`
55
+ * @throws {TypeError} If the value is not a non-negative integer in [0, 2^31)
51
56
  */
52
57
  export const asNonNegativeInt32 = castType;
53
58
 
54
59
  /**
55
- * Namespace providing type-safe arithmetic operations for 32-bit non-negative
56
- * integers.
60
+ * Namespace providing type-safe operations for the `NonNegativeInt32` branded
61
+ * type.
57
62
  *
58
- * All operations automatically clamp results to the valid NonNegativeInt32
59
- * range [0, 2147483647]. This ensures that all arithmetic maintains the 32-bit
60
- * non-negative integer constraint, with negative results clamped to 0 and
61
- * overflow results clamped to MAX_VALUE.
63
+ * The `NonNegativeInt32` type represents a non-negative integer in [0, 2^31).
64
+ * Division (`div`) uses floor division.
62
65
  */
63
66
  export const NonNegativeInt32 = {
64
67
  /**
65
- * Type guard to check if a value is a NonNegativeInt32.
68
+ * Type guard that checks if a value is a non-negative integer in [0, 2^31).
66
69
  *
67
- * @param value The value to check.
68
- * @returns `true` if the value is a 32-bit non-negative integer, `false`
69
- * otherwise.
70
+ * @param value - The value to check
71
+ * @returns `true` if the value is a non-negative integer in [0, 2^31), `false` otherwise
72
+ * @see {@link isNonNegativeInt32} for usage examples
70
73
  */
71
74
  is,
72
75
 
73
76
  /**
74
- * The minimum value for a 32-bit non-negative integer.
75
- *
76
- * @readonly
77
+ * The smallest value representable as `NonNegativeInt32`.
77
78
  */
78
79
  MIN_VALUE,
79
80
 
80
81
  /**
81
- * The maximum value for a 32-bit non-negative integer.
82
- *
83
- * @readonly
82
+ * The largest value representable as `NonNegativeInt32`.
84
83
  */
85
84
  MAX_VALUE,
86
85
 
87
86
  /**
88
- * Returns the smaller of two NonNegativeInt32 values.
87
+ * Returns the smallest of the given non-negative integers.
89
88
  *
90
- * @param a The first NonNegativeInt32.
91
- * @param b The second NonNegativeInt32.
92
- * @returns The minimum value as a NonNegativeInt32.
89
+ * @param values - The non-negative integers to compare (at least one required)
90
+ * @returns The smallest value as a `NonNegativeInt32`
93
91
  */
94
92
  min: min_,
95
93
 
96
94
  /**
97
- * Returns the larger of two NonNegativeInt32 values.
95
+ * Returns the largest of the given non-negative integers.
98
96
  *
99
- * @param a The first NonNegativeInt32.
100
- * @param b The second NonNegativeInt32.
101
- * @returns The maximum value as a NonNegativeInt32.
97
+ * @param values - The non-negative integers to compare (at least one required)
98
+ * @returns The largest value as a `NonNegativeInt32`
102
99
  */
103
100
  max: max_,
104
101
 
105
102
  /**
106
- * Clamps a number to the NonNegativeInt32 range.
103
+ * Clamps a `number` into the `NonNegativeInt32` range, rounding to the
104
+ * nearest 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, 2147483647] as a NonNegativeInt32.
106
+ * @param value - The value to clamp
107
+ * @returns The clamped value as a `NonNegativeInt32`
110
108
  */
111
109
  clamp,
112
110
 
113
111
  /**
114
- * Generates a random NonNegativeInt32 value within the valid range.
112
+ * Generates a random `NonNegativeInt32` within the given range.
113
+ *
114
+ * The range is inclusive on both ends.
115
115
  *
116
- * @returns A random NonNegativeInt32 between 0 and 2147483647.
116
+ * @param min - The minimum value (inclusive)
117
+ * @param max - The maximum value (inclusive)
118
+ * @returns A random `NonNegativeInt32` in `[min, max]`
117
119
  */
118
120
  random,
119
121
 
120
122
  /**
121
- * Raises a NonNegativeInt32 to the power of another NonNegativeInt32.
123
+ * Raises `a` to the power `b`, returning `a ** b` as a `NonNegativeInt32`
124
+ * (floored to an integer).
122
125
  *
123
- * @param a The base NonNegativeInt32.
124
- * @param b The exponent NonNegativeInt32.
125
- * @returns `a ** b` clamped to [0, 2147483647] as a NonNegativeInt32.
126
+ * @param a - The base non-negative integer
127
+ * @param b - The exponent non-negative integer
128
+ * @returns `a ** b` as a `NonNegativeInt32`
126
129
  */
127
130
  pow,
128
131
 
129
132
  /**
130
- * Adds two NonNegativeInt32 values.
133
+ * Adds two non-negative integers, returning `a + b` as a `NonNegativeInt32`.
131
134
  *
132
- * @param a The first NonNegativeInt32.
133
- * @param b The second NonNegativeInt32.
134
- * @returns `a + b` clamped to [0, 2147483647] as a NonNegativeInt32.
135
+ * @param a - The first non-negative integer
136
+ * @param b - The second non-negative integer
137
+ * @returns The sum of `a` and `b` as a `NonNegativeInt32`
135
138
  */
136
139
  add,
137
140
 
138
141
  /**
139
- * Subtracts one NonNegativeInt32 from another.
142
+ * Subtracts two non-negative integers, returning `a - b` as a
143
+ * `NonNegativeInt32`.
140
144
  *
141
- * @param a The minuend NonNegativeInt32.
142
- * @param b The subtrahend NonNegativeInt32.
143
- * @returns `a - b` clamped to [0, 2147483647] as a NonNegativeInt32 (minimum
144
- * 0).
145
+ * @param a - The first non-negative integer
146
+ * @param b - The second non-negative integer
147
+ * @returns The difference of `a` and `b` as a `NonNegativeInt32`
145
148
  */
146
149
  sub,
147
150
 
148
151
  /**
149
- * Multiplies two NonNegativeInt32 values.
152
+ * Multiplies two non-negative integers, returning `a * b` as a
153
+ * `NonNegativeInt32`.
150
154
  *
151
- * @param a The first NonNegativeInt32.
152
- * @param b The second NonNegativeInt32.
153
- * @returns `a * b` clamped to [0, 2147483647] as a NonNegativeInt32.
155
+ * @param a - The first non-negative integer
156
+ * @param b - The second non-negative integer
157
+ * @returns The product of `a` and `b` as a `NonNegativeInt32`
154
158
  */
155
159
  mul,
156
160
 
157
161
  /**
158
- * Divides one NonNegativeInt32 by another using floor division.
162
+ * Divides two non-negative integers using floor division (`⌊a / b⌋`): the
163
+ * result is `a / b` rounded toward negative infinity, as a
164
+ * `NonNegativeInt32`.
159
165
  *
160
- * @param a The dividend NonNegativeInt32.
161
- * @param b The divisor NonNegativeInt32.
162
- * @returns `⌊a / b⌋` clamped to [0, 2147483647] as a NonNegativeInt32.
166
+ * @param a - The dividend
167
+ * @param b - The divisor (must be non-zero)
168
+ * @returns The floored quotient as a `NonNegativeInt32`
163
169
  */
164
170
  div,
165
171
  } as const;
@@ -63,129 +63,139 @@ const round = (
63
63
  >;
64
64
 
65
65
  /**
66
- * Checks if a number is a NonPositiveFiniteNumber (a finite number <= 0).
66
+ * Type guard that checks if a value is a non-positive finite number.
67
67
  *
68
- * @param value The value to check.
69
- * @returns `true` if the value is a NonPositiveFiniteNumber, `false` otherwise.
68
+ * Returns `true` only for a finite value — never `NaN`, `Infinity`, or
69
+ * `-Infinity`.
70
+ *
71
+ * @param value - The value to check
72
+ * @returns `true` if the value is a non-positive finite number, `false` otherwise
70
73
  */
71
74
  export const isNonPositiveFiniteNumber = is;
72
75
 
73
76
  /**
74
- * Casts a number to a NonPositiveFiniteNumber type.
77
+ * Casts a `number` to the `NonPositiveFiniteNumber` branded type.
78
+ *
79
+ * Validates that the value is a non-positive finite number and returns it with
80
+ * the `NonPositiveFiniteNumber` brand. Throws a `TypeError` otherwise.
75
81
  *
76
- * @param value The value to cast.
77
- * @returns The value as a NonPositiveFiniteNumber type.
78
- * @throws {TypeError} If the value is not a non-positive finite number.
82
+ * @param value - The value to cast
83
+ * @returns The value as a `NonPositiveFiniteNumber`
84
+ * @throws {TypeError} If the value is not a non-positive finite number
79
85
  */
80
86
  export const asNonPositiveFiniteNumber = castType;
81
87
 
82
88
  /**
83
- * Namespace providing type-safe arithmetic operations for non-positive finite
84
- * numbers.
89
+ * Namespace providing type-safe operations for the `NonPositiveFiniteNumber`
90
+ * branded type.
85
91
  *
86
- * All operations maintain the non-positive constraint by clamping positive
87
- * results to MAX_VALUE (0), while ensuring results remain finite (excluding NaN
88
- * and Infinity). This type is useful for representing quantities that must
89
- * always be non-positive, such as debts, penalties, and negative offsets.
92
+ * The `NonPositiveFiniteNumber` type represents a non-positive finite number.
90
93
  */
91
94
  export const NonPositiveFiniteNumber = {
92
95
  /**
93
- * Type guard to check if a value is a NonPositiveFiniteNumber.
96
+ * Type guard that checks if a value is a non-positive finite number.
94
97
  *
95
- * @param value The value to check.
96
- * @returns `true` if the value is a non-positive finite number, `false`
97
- * otherwise.
98
+ * @param value - The value to check
99
+ * @returns `true` if the value is a non-positive finite number, `false` otherwise
100
+ * @see {@link isNonPositiveFiniteNumber} for usage examples
98
101
  */
99
102
  is,
100
103
 
101
104
  /**
102
- * The maximum value for a non-positive finite number.
103
- *
104
- * @readonly
105
+ * The largest value representable as `NonPositiveFiniteNumber`.
105
106
  */
106
107
  MAX_VALUE,
107
108
 
108
109
  /**
109
- * Returns the smaller of two NonPositiveFiniteNumber values.
110
+ * Returns the smallest of the given non-positive finite numbers.
110
111
  *
111
- * @param a The first NonPositiveFiniteNumber.
112
- * @param b The second NonPositiveFiniteNumber.
113
- * @returns The minimum value as a NonPositiveFiniteNumber.
112
+ * @param values - The non-positive finite numbers to compare (at least one required)
113
+ * @returns The smallest value as a `NonPositiveFiniteNumber`
114
114
  */
115
115
  min: min_,
116
116
 
117
117
  /**
118
- * Returns the larger of two NonPositiveFiniteNumber values.
118
+ * Returns the largest of the given non-positive finite numbers.
119
119
  *
120
- * @param a The first NonPositiveFiniteNumber.
121
- * @param b The second NonPositiveFiniteNumber.
122
- * @returns The maximum value as a NonPositiveFiniteNumber.
120
+ * @param values - The non-positive finite numbers to compare (at least one required)
121
+ * @returns The largest value as a `NonPositiveFiniteNumber`
123
122
  */
124
123
  max: max_,
125
124
 
126
125
  /**
127
- * Clamps a number to the non-positive finite range.
126
+ * Clamps a `number` into the `NonPositiveFiniteNumber` range `[MIN_VALUE,
127
+ * MAX_VALUE]`.
128
128
  *
129
- * @param value The number to clamp.
130
- * @returns The value clamped to (-∞, 0] as a NonPositiveFiniteNumber.
129
+ * @param value - The value to clamp
130
+ * @returns The clamped value as a `NonPositiveFiniteNumber`
131
131
  */
132
132
  clamp,
133
133
 
134
134
  /**
135
- * Rounds down a NonPositiveFiniteNumber to the nearest integer.
135
+ * Returns the greatest integer less than or equal to a non-positive finite
136
+ * number.
136
137
  *
137
- * @param x The NonPositiveFiniteNumber to round down.
138
- * @returns The floor value as a NonPositiveInt (can be 0).
138
+ * @param a - The non-positive finite number value
139
+ * @returns The floored value as an integer
139
140
  */
140
141
  floor,
141
142
 
142
143
  /**
143
- * Rounds up a NonPositiveFiniteNumber to the nearest integer.
144
+ * Returns the smallest integer greater than or equal to a non-positive finite
145
+ * number.
144
146
  *
145
- * @param x The NonPositiveFiniteNumber to round up.
146
- * @returns The ceiling value as a NegativeInt (always <= -1) or 0.
147
+ * @param a - The non-positive finite number value
148
+ * @returns The ceiled value as an integer
147
149
  */
148
150
  ceil,
149
151
 
150
152
  /**
151
- * Rounds a NonPositiveFiniteNumber to the nearest integer.
153
+ * Returns the value of a non-positive finite number rounded to the nearest
154
+ * integer.
152
155
  *
153
- * @param x The NonPositiveFiniteNumber to round.
154
- * @returns The rounded value as a NonPositiveInt (can be 0 if x > -0.5).
156
+ * @param a - The non-positive finite number value
157
+ * @returns The rounded value as an integer
155
158
  */
156
159
  round,
157
160
 
158
161
  /**
159
- * Generates a random NonPositiveFiniteNumber value.
162
+ * Generates a random `NonPositiveFiniteNumber` within the given range.
163
+ *
164
+ * The range is inclusive on both ends.
160
165
  *
161
- * @returns A random non-positive finite number.
166
+ * @param min - The minimum value (inclusive)
167
+ * @param max - The maximum value (inclusive)
168
+ * @returns A random `NonPositiveFiniteNumber` in `[min, max]`
162
169
  */
163
170
  random,
164
171
 
165
172
  /**
166
- * Raises a NonPositiveFiniteNumber to the power of another NonPositiveFiniteNumber.
173
+ * Raises `a` to the power `b`, returning `a ** b` as a
174
+ * `NonPositiveFiniteNumber`.
167
175
  *
168
- * @param a The base NonPositiveFiniteNumber.
169
- * @param b The exponent NonPositiveFiniteNumber.
170
- * @returns `a ** b` clamped to (-∞, 0] as a NonPositiveFiniteNumber.
176
+ * @param a - The base non-positive finite number
177
+ * @param b - The exponent non-positive finite number
178
+ * @returns `a ** b` as a `NonPositiveFiniteNumber`
171
179
  */
172
180
  pow,
173
181
 
174
182
  /**
175
- * Adds two NonPositiveFiniteNumber values.
183
+ * Adds two non-positive finite numbers, returning `a + b` as a
184
+ * `NonPositiveFiniteNumber`.
176
185
  *
177
- * @param a The first NonPositiveFiniteNumber.
178
- * @param b The second NonPositiveFiniteNumber.
179
- * @returns `a + b` clamped to (-∞, 0] as a NonPositiveFiniteNumber.
186
+ * @param a - The first non-positive finite number
187
+ * @param b - The second non-positive finite number
188
+ * @returns The sum of `a` and `b` as a `NonPositiveFiniteNumber`
180
189
  */
181
190
  add,
182
191
 
183
192
  /**
184
- * Subtracts one NonPositiveFiniteNumber from another.
193
+ * Subtracts two non-positive finite numbers, returning `a - b` as a
194
+ * `NonPositiveFiniteNumber`.
185
195
  *
186
- * @param a The minuend NonPositiveFiniteNumber.
187
- * @param b The subtrahend NonPositiveFiniteNumber.
188
- * @returns `a - b` clamped to (-∞, 0] as a NonPositiveFiniteNumber (maximum 0).
196
+ * @param a - The first non-positive finite number
197
+ * @param b - The second non-positive finite number
198
+ * @returns The difference of `a` and `b` as a `NonPositiveFiniteNumber`
189
199
  */
190
200
  sub,
191
201
  } as const;
@@ -32,19 +32,9 @@ const {
32
32
  /**
33
33
  * Type guard that checks if a value is a non-positive integer.
34
34
  *
35
- * A non-positive integer is any integer less than or equal to zero (<= 0).
36
- * This includes zero and all negative integers, but excludes positive numbers
37
- * and non-integers.
38
- *
39
- * @example
40
- *
41
- * ```ts
42
- * assert.isTrue(isNonPositiveInt(0));
43
- *
44
- * assert.isTrue(isNonPositiveInt(-5));
45
- *
46
- * assert.isFalse(isNonPositiveInt(1));
47
- * ```
35
+ * Returns `true` for a non-positive integer — a value with no fractional
36
+ * component, including values outside the safe integer range (unlike
37
+ * `SafeInt`).
48
38
  *
49
39
  * @param value - The value to check
50
40
  * @returns `true` if the value is a non-positive integer, `false` otherwise
@@ -52,200 +42,105 @@ const {
52
42
  export const isNonPositiveInt = is;
53
43
 
54
44
  /**
55
- * Casts a number to a NonPositiveInt branded type.
56
- *
57
- * This function validates that the input is a non-positive integer (<= 0) and
58
- * returns it with the NonPositiveInt brand. This ensures type safety for
59
- * operations that require non-positive integer values.
60
- *
61
- * @example
45
+ * Casts a `number` to the `NonPositiveInt` branded type.
62
46
  *
63
- * ```ts
64
- * const branded = asNonPositiveInt(-7);
65
- *
66
- * assert.isTrue(branded === -7);
67
- *
68
- * assert.isTrue(NonPositiveInt.is(branded));
69
- * ```
47
+ * Validates that the value is a non-positive integer and returns it with the
48
+ * `NonPositiveInt` brand. Throws a `TypeError` otherwise.
70
49
  *
71
50
  * @param value - The value to cast
72
- * @returns The value as a NonPositiveInt branded type
51
+ * @returns The value as a `NonPositiveInt`
73
52
  * @throws {TypeError} If the value is not a non-positive integer
74
53
  */
75
54
  export const asNonPositiveInt = castType;
76
55
 
77
56
  /**
78
- * Namespace providing type-safe operations for NonPositiveInt branded types.
79
- *
80
- * NonPositiveInt represents integers that are less than or equal to zero (<= 0).
81
- * All operations automatically clamp results to maintain the non-positive
82
- * constraint, ensuring that arithmetic operations never produce positive values.
57
+ * Namespace providing type-safe operations for the `NonPositiveInt` branded
58
+ * type.
83
59
  *
84
- * This type is essential for:
60
+ * The `NonPositiveInt` type represents a non-positive integer. Division (`div`)
61
+ * uses floor division.
85
62
  *
86
- * - Debts and negative balances
87
- * - Penalties and reductions
88
- * - Offsets and adjustments (downward)
89
- * - Negative counts or differences
90
- * - Depth or altitude below a reference point
63
+ * Unlike `SafeInt`, `NonPositiveInt` allows values outside the safe integer
64
+ * range (±2^53 − 1), so very large magnitudes may lose precision in
65
+ * JavaScript's `number` type.
91
66
  */
92
67
  export const NonPositiveInt = {
93
68
  /**
94
69
  * Type guard that checks if a value is a non-positive integer.
95
70
  *
96
- * @example
97
- *
98
- * ```ts
99
- * const value: number = -42;
100
- *
101
- * if (NonPositiveInt.is(value)) {
102
- * // value is now typed as NonPositiveInt
103
- * const debt = value;
104
- * }
105
- * ```
106
- *
107
71
  * @param value - The value to check
108
72
  * @returns `true` if the value is a non-positive integer, `false` otherwise
73
+ * @see {@link isNonPositiveInt} for usage examples
109
74
  */
110
75
  is,
111
76
 
112
77
  /**
113
- * The maximum value for a non-positive integer.
114
- *
115
- * @readonly
78
+ * The largest value representable as `NonPositiveInt`.
116
79
  */
117
80
  MAX_VALUE,
118
81
 
119
82
  /**
120
- * Returns the smaller of two non-positive integers.
121
- *
122
- * Since non-positive integers range from negative infinity to 0, the smaller
123
- * value is the one further from zero (more negative).
124
- *
125
- * @example
83
+ * Returns the smallest of the given non-positive integers.
126
84
  *
127
- * ```ts
128
- * const result = NonPositiveInt.min(-5, -10);
129
- *
130
- * assert.strictEqual(result, -10);
131
- * ```
132
- *
133
- * @param a - The first non-positive integer
134
- * @param b - The second non-positive integer
135
- * @returns The minimum value as a non-positive integer
85
+ * @param values - The non-positive integers to compare (at least one required)
86
+ * @returns The smallest value as a `NonPositiveInt`
136
87
  */
137
88
  min: min_,
138
89
 
139
90
  /**
140
- * Returns the larger of two non-positive integers.
141
- *
142
- * Since non-positive integers range from negative infinity to 0, the larger
143
- * value is the one closer to zero (less negative).
144
- *
145
- * @example
146
- *
147
- * ```ts
148
- * const result = NonPositiveInt.max(-5, -10);
149
- *
150
- * assert.strictEqual(result, -5);
151
- * ```
91
+ * Returns the largest of the given non-positive integers.
152
92
  *
153
- * @param a - The first non-positive integer
154
- * @param b - The second non-positive integer
155
- * @returns The maximum value as a non-positive integer
93
+ * @param values - The non-positive integers to compare (at least one required)
94
+ * @returns The largest value as a `NonPositiveInt`
156
95
  */
157
96
  max: max_,
158
97
 
159
98
  /**
160
- * Clamps a number to the non-positive integer range.
161
- *
162
- * Any positive value is clamped to 0 (the maximum non-positive integer).
163
- * Negative values are preserved as long as they are valid integers.
164
- *
165
- * @example
166
- *
167
- * ```ts
168
- * assert.strictEqual(NonPositiveInt.clamp(5), 0);
169
- *
170
- * assert.strictEqual(NonPositiveInt.clamp(-5), -5);
99
+ * Clamps a `number` into the `NonPositiveInt` range, rounding to the nearest
100
+ * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
171
101
  *
172
- * assert.strictEqual(NonPositiveInt.clamp(0), 0);
173
- * ```
174
- *
175
- * @param value - The number to clamp
176
- * @returns The value clamped to the non-positive integer range
102
+ * @param value - The value to clamp
103
+ * @returns The clamped value as a `NonPositiveInt`
177
104
  */
178
105
  clamp,
179
106
 
180
107
  /**
181
- * Generates a random non-positive integer value.
182
- *
183
- * @example
184
- *
185
- * ```ts
186
- * const randomValue = NonPositiveInt.random();
108
+ * Generates a random `NonPositiveInt` within the given range.
187
109
  *
188
- * assert.isTrue(NonPositiveInt.is(randomValue));
189
- * ```
110
+ * The range is inclusive on both ends.
190
111
  *
191
- * @returns A random non-positive integer
112
+ * @param min - The minimum value (inclusive)
113
+ * @param max - The maximum value (inclusive)
114
+ * @returns A random `NonPositiveInt` in `[min, max]`
192
115
  */
193
116
  random,
194
117
 
195
118
  /**
196
- * Raises a non-positive integer to the power of another non-positive integer.
197
- *
198
- * The result is clamped to the non-positive integer range.
199
- *
200
- * @example
201
- *
202
- * ```ts
203
- * const result = NonPositiveInt.pow(-2, -1);
204
- * ```
119
+ * Raises `a` to the power `b`, returning `a ** b` as a `NonPositiveInt`
120
+ * (floored to an integer).
205
121
  *
206
122
  * @param a - The base non-positive integer
207
123
  * @param b - The exponent non-positive integer
208
- * @returns `a ** b` clamped to the non-positive integer range
124
+ * @returns `a ** b` as a `NonPositiveInt`
209
125
  */
210
126
  pow,
211
127
 
212
128
  /**
213
- * Adds two non-positive integers.
214
- *
215
- * The result is clamped to the non-positive integer range. If the sum is
216
- * positive, it is clamped to 0.
217
- *
218
- * @example
219
- *
220
- * ```ts
221
- * assert.strictEqual(NonPositiveInt.add(-5, -3), -8);
222
- *
223
- * assert.strictEqual(NonPositiveInt.add(-5, 10), 0);
224
- * ```
129
+ * Adds two non-positive integers, returning `a + b` as a `NonPositiveInt`.
225
130
  *
226
131
  * @param a - The first non-positive integer
227
132
  * @param b - The second non-positive integer
228
- * @returns `a + b` clamped to the non-positive integer range
133
+ * @returns The sum of `a` and `b` as a `NonPositiveInt`
229
134
  */
230
135
  add,
231
136
 
232
137
  /**
233
- * Subtracts one non-positive integer from another.
234
- *
235
- * The result is clamped to the non-positive integer range. If the result is
236
- * positive, it is clamped to 0.
138
+ * Subtracts two non-positive integers, returning `a - b` as a
139
+ * `NonPositiveInt`.
237
140
  *
238
- * @example
239
- *
240
- * ```ts
241
- * assert.strictEqual(NonPositiveInt.sub(-10, -3), -7);
242
- *
243
- * assert.strictEqual(NonPositiveInt.sub(-10, 5), 0);
244
- * ```
245
- *
246
- * @param a - The minuend non-positive integer
247
- * @param b - The subtrahend non-positive integer
248
- * @returns `a - b` clamped to the non-positive integer range
141
+ * @param a - The first non-positive integer
142
+ * @param b - The second non-positive integer
143
+ * @returns The difference of `a` and `b` as a `NonPositiveInt`
249
144
  */
250
145
  sub,
251
146
  } as const;