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,137 +35,144 @@ const {
35
35
  } as const);
36
36
 
37
37
  /**
38
- * Checks if a number is an Int32 (32-bit signed integer in the range [-2^31,
39
- * 2^31)).
38
+ * Type guard that checks if a value is an integer in [-2^31, 2^31).
40
39
  *
41
- * @param value The value to check.
42
- * @returns `true` if the value is an Int32, `false` otherwise.
40
+ * Returns `true` for an integer in [-2^31, 2^31) — a value with no fractional
41
+ * component.
42
+ *
43
+ * @param value - The value to check
44
+ * @returns `true` if the value is an integer in [-2^31, 2^31), `false` otherwise
43
45
  */
44
46
  export const isInt32 = is;
45
47
 
46
48
  /**
47
- * Casts a number to an Int32 type.
49
+ * Casts a `number` to the `Int32` branded type.
50
+ *
51
+ * Validates that the value is an integer in [-2^31, 2^31) and returns it with
52
+ * the `Int32` brand. Throws a `TypeError` otherwise.
48
53
  *
49
- * @param value The value to cast.
50
- * @returns The value as an Int32 type.
51
- * @throws {TypeError} If the value is not an integer in [-2^31, 2^31).
54
+ * @param value - The value to cast
55
+ * @returns The value as an `Int32`
56
+ * @throws {TypeError} If the value is not an integer in [-2^31, 2^31)
52
57
  */
53
58
  export const asInt32 = castType;
54
59
 
55
60
  /**
56
- * Namespace providing type-safe arithmetic operations for 32-bit signed
57
- * integers.
61
+ * Namespace providing type-safe operations for the `Int32` branded type.
58
62
  *
59
- * All operations automatically clamp results to the valid Int32 range
60
- * [-2147483648, 2147483647]. This ensures that all arithmetic maintains the
61
- * 32-bit signed integer constraint, preventing overflow.
63
+ * The `Int32` type represents an integer in [-2^31, 2^31). Division (`div`)
64
+ * uses floor division.
62
65
  */
63
66
  export const Int32 = {
64
67
  /**
65
- * Type guard to check if a value is an Int32.
68
+ * Type guard that checks if a value is an integer in [-2^31, 2^31).
66
69
  *
67
- * @param value The value to check.
68
- * @returns `true` if the value is a 32-bit signed integer, `false` otherwise.
70
+ * @param value - The value to check
71
+ * @returns `true` if the value is an integer in [-2^31, 2^31), `false` otherwise
72
+ * @see {@link isInt32} for usage examples
69
73
  */
70
74
  is,
71
75
 
72
76
  /**
73
- * The minimum value for a 32-bit signed integer.
74
- *
75
- * @readonly
77
+ * The smallest value representable as `Int32`.
76
78
  */
77
79
  MIN_VALUE,
78
80
 
79
81
  /**
80
- * The maximum value for a 32-bit signed integer.
81
- *
82
- * @readonly
82
+ * The largest value representable as `Int32`.
83
83
  */
84
84
  MAX_VALUE,
85
85
 
86
86
  /**
87
- * Returns the absolute value of a 32-bit signed integer.
87
+ * Returns the absolute value of an integer in [-2^31, 2^31).
88
+ *
89
+ * The result is non-negative and keeps the `Int32` brand.
88
90
  *
89
- * @param a The Int32 value.
90
- * @returns The absolute value as an Int32, clamped to valid range.
91
+ * @param a - The integer value
92
+ * @returns The absolute value as a non-negative `Int32`
91
93
  */
92
94
  abs,
93
95
 
94
96
  /**
95
- * Returns the smaller of two Int32 values.
97
+ * Returns the smallest of the given integers.
96
98
  *
97
- * @param a The first Int32.
98
- * @param b The second Int32.
99
- * @returns The minimum value as an Int32.
99
+ * @param values - The integers to compare (at least one required)
100
+ * @returns The smallest value as an `Int32`
100
101
  */
101
102
  min: min_,
102
103
 
103
104
  /**
104
- * Returns the larger of two Int32 values.
105
+ * Returns the largest of the given integers.
105
106
  *
106
- * @param a The first Int32.
107
- * @param b The second Int32.
108
- * @returns The maximum value as an Int32.
107
+ * @param values - The integers to compare (at least one required)
108
+ * @returns The largest value as an `Int32`
109
109
  */
110
110
  max: max_,
111
111
 
112
112
  /**
113
- * Clamps a number to the Int32 range.
113
+ * Clamps a `number` into the `Int32` range, rounding to the nearest integer
114
+ * and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
114
115
  *
115
- * @param value The number to clamp.
116
- * @returns The value clamped to [-2147483648, 2147483647] as an Int32.
116
+ * @param value - The value to clamp
117
+ * @returns The clamped value as an `Int32`
117
118
  */
118
119
  clamp,
119
120
 
120
121
  /**
121
- * Generates a random Int32 value within the valid range.
122
+ * Generates a random `Int32` within the given range.
123
+ *
124
+ * The range is inclusive on both ends.
122
125
  *
123
- * @returns A random Int32 between MIN_VALUE and MAX_VALUE.
126
+ * @param min - The minimum value (inclusive)
127
+ * @param max - The maximum value (inclusive)
128
+ * @returns A random `Int32` in `[min, max]`
124
129
  */
125
130
  random,
126
131
 
127
132
  /**
128
- * Raises an Int32 to the power of another Int32.
133
+ * Raises `a` to the power `b`, returning `a ** b` as an `Int32` (floored to
134
+ * an integer).
129
135
  *
130
- * @param a The base Int32.
131
- * @param b The exponent Int32.
132
- * @returns `a ** b` clamped to [-2147483648, 2147483647] as an Int32.
136
+ * @param a - The base integer
137
+ * @param b - The exponent integer
138
+ * @returns `a ** b` as an `Int32`
133
139
  */
134
140
  pow,
135
141
 
136
142
  /**
137
- * Adds two Int32 values.
143
+ * Adds two integers, returning `a + b` as an `Int32`.
138
144
  *
139
- * @param a The first Int32.
140
- * @param b The second Int32.
141
- * @returns `a + b` clamped to [-2147483648, 2147483647] as an Int32.
145
+ * @param a - The first integer
146
+ * @param b - The second integer
147
+ * @returns The sum of `a` and `b` as an `Int32`
142
148
  */
143
149
  add,
144
150
 
145
151
  /**
146
- * Subtracts one Int32 from another.
152
+ * Subtracts two integers, returning `a - b` as an `Int32`.
147
153
  *
148
- * @param a The minuend Int32.
149
- * @param b The subtrahend Int32.
150
- * @returns `a - b` clamped to [-2147483648, 2147483647] as an Int32.
154
+ * @param a - The first integer
155
+ * @param b - The second integer
156
+ * @returns The difference of `a` and `b` as an `Int32`
151
157
  */
152
158
  sub,
153
159
 
154
160
  /**
155
- * Multiplies two Int32 values.
161
+ * Multiplies two integers, returning `a * b` as an `Int32`.
156
162
  *
157
- * @param a The first Int32.
158
- * @param b The second Int32.
159
- * @returns `a * b` clamped to [-2147483648, 2147483647] as an Int32.
163
+ * @param a - The first integer
164
+ * @param b - The second integer
165
+ * @returns The product of `a` and `b` as an `Int32`
160
166
  */
161
167
  mul,
162
168
 
163
169
  /**
164
- * Divides one Int32 by another using floor division.
170
+ * Divides two integers using floor division (`⌊a / b⌋`): the result is `a /
171
+ * b` rounded toward negative infinity, as an `Int32`.
165
172
  *
166
- * @param a The dividend Int32.
167
- * @param b The divisor Int32.
168
- * @returns `⌊a / b⌋` clamped to [-2147483648, 2147483647] as an Int32.
173
+ * @param a - The dividend
174
+ * @param b - The divisor (must be non-zero)
175
+ * @returns The floored quotient as an `Int32`
169
176
  */
170
177
  div,
171
178
  } as const;
@@ -30,15 +30,6 @@ const {
30
30
  typeNameInMessage,
31
31
  } as const);
32
32
 
33
- /**
34
- * Returns the absolute value of a negative finite number.
35
- *
36
- * The absolute value of a negative finite number is always a positive finite
37
- * number, so the result is typed as a {@link PositiveFiniteNumber}.
38
- *
39
- * @param x - The negative finite number.
40
- * @returns `|x|` as a PositiveFiniteNumber.
41
- */
42
33
  const abs = (x: ElementType): PositiveFiniteNumber =>
43
34
  PositiveFiniteNumber.clamp(Math.abs(x));
44
35
 
@@ -71,140 +62,149 @@ const round = (
71
62
  >;
72
63
 
73
64
  /**
74
- * Checks if a number is a NegativeFiniteNumber (a finite number `< 0`).
65
+ * Type guard that checks if a value is a negative finite number.
66
+ *
67
+ * Returns `true` only for a finite value — never `NaN`, `Infinity`, or
68
+ * `-Infinity`.
75
69
  *
76
- * @param value The value to check.
77
- * @returns `true` if the value is a NegativeFiniteNumber, `false` otherwise.
70
+ * @param value - The value to check
71
+ * @returns `true` if the value is a negative finite number, `false` otherwise
78
72
  */
79
73
  export const isNegativeFiniteNumber = is;
80
74
 
81
75
  /**
82
- * Casts a number to a NegativeFiniteNumber type.
76
+ * Casts a `number` to the `NegativeFiniteNumber` branded type.
83
77
  *
84
- * @param value The value to cast.
85
- * @returns The value as a NegativeFiniteNumber type.
86
- * @throws {TypeError} If the value is not a negative finite number.
78
+ * Validates that the value is a negative finite number and returns it with the
79
+ * `NegativeFiniteNumber` brand. Throws a `TypeError` otherwise.
80
+ *
81
+ * @param value - The value to cast
82
+ * @returns The value as a `NegativeFiniteNumber`
83
+ * @throws {TypeError} If the value is not a negative finite number
87
84
  */
88
85
  export const asNegativeFiniteNumber = castType;
89
86
 
90
87
  /**
91
- * Namespace providing type-safe arithmetic operations for negative finite
92
- * numbers.
88
+ * Namespace providing type-safe operations for the `NegativeFiniteNumber`
89
+ * branded type.
93
90
  *
94
- * All operations keep results finite (excluding NaN and Infinity). Operations
95
- * that stay within the negative finite numbers clamp their results to the valid
96
- * range, while operations whose result leaves the set (`mul`, `div`, `abs`) are
97
- * typed to reflect the actual sign of the result.
91
+ * The `NegativeFiniteNumber` type represents a negative finite number.
98
92
  */
99
93
  export const NegativeFiniteNumber = {
100
94
  /**
101
- * Type guard to check if a value is a NegativeFiniteNumber.
95
+ * Type guard that checks if a value is a negative finite number.
102
96
  *
103
- * @param value The value to check.
104
- * @returns `true` if the value is a negative finite number, `false`
105
- * otherwise.
97
+ * @param value - The value to check
98
+ * @returns `true` if the value is a negative finite number, `false` otherwise
99
+ * @see {@link isNegativeFiniteNumber} for usage examples
106
100
  */
107
101
  is,
108
102
 
109
103
  /**
110
- * The maximum value for a negative finite number.
111
- *
112
- * @readonly
104
+ * The largest value representable as `NegativeFiniteNumber`.
113
105
  */
114
106
  MAX_VALUE,
115
107
 
116
108
  /**
117
109
  * Returns the absolute value of a negative finite number.
118
110
  *
119
- * @param a The negative finite number.
120
- * @returns The absolute value as a PositiveFiniteNumber.
111
+ * The result is non-negative and keeps the `NegativeFiniteNumber` brand.
112
+ *
113
+ * @param a - The negative finite number value
114
+ * @returns The absolute value as a non-negative `NegativeFiniteNumber`
121
115
  */
122
116
  abs,
123
117
 
124
118
  /**
125
- * Returns the smaller of two NegativeFiniteNumber values.
119
+ * Returns the smallest of the given negative finite numbers.
126
120
  *
127
- * @param a The first NegativeFiniteNumber.
128
- * @param b The second NegativeFiniteNumber.
129
- * @returns The minimum value as a NegativeFiniteNumber.
121
+ * @param values - The negative finite numbers to compare (at least one required)
122
+ * @returns The smallest value as a `NegativeFiniteNumber`
130
123
  */
131
124
  min: min_,
132
125
 
133
126
  /**
134
- * Returns the larger of two NegativeFiniteNumber values.
127
+ * Returns the largest of the given negative finite numbers.
135
128
  *
136
- * @param a The first NegativeFiniteNumber.
137
- * @param b The second NegativeFiniteNumber.
138
- * @returns The maximum value as a NegativeFiniteNumber.
129
+ * @param values - The negative finite numbers to compare (at least one required)
130
+ * @returns The largest value as a `NegativeFiniteNumber`
139
131
  */
140
132
  max: max_,
141
133
 
142
134
  /**
143
- * Clamps a number to the negative finite range.
135
+ * Clamps a `number` into the `NegativeFiniteNumber` range `[MIN_VALUE,
136
+ * MAX_VALUE]`.
144
137
  *
145
- * @param value The number to clamp.
146
- * @returns The value clamped to `(-∞, 0)` as a NegativeFiniteNumber.
138
+ * @param value - The value to clamp
139
+ * @returns The clamped value as a `NegativeFiniteNumber`
147
140
  */
148
141
  clamp,
149
142
 
150
143
  /**
151
- * Rounds down a NegativeFiniteNumber to the nearest integer.
144
+ * Returns the greatest integer less than or equal to a negative finite
145
+ * number.
152
146
  *
153
- * @param x The NegativeFiniteNumber to round down.
154
- * @returns The floor value as a NegativeInt (always `<= -1`).
147
+ * @param a - The negative finite number value
148
+ * @returns The floored value as an integer
155
149
  */
156
150
  floor,
157
151
 
158
152
  /**
159
- * Rounds up a NegativeFiniteNumber to the nearest integer.
153
+ * Returns the smallest integer greater than or equal to a negative finite
154
+ * number.
160
155
  *
161
- * @param x The NegativeFiniteNumber to round up.
162
- * @returns The ceiling value as a NonPositiveInt (can be 0).
156
+ * @param a - The negative finite number value
157
+ * @returns The ceiled value as an integer
163
158
  */
164
159
  ceil,
165
160
 
166
161
  /**
167
- * Rounds a NegativeFiniteNumber to the nearest integer.
162
+ * Returns the value of a negative finite number rounded to the nearest
163
+ * integer.
168
164
  *
169
- * @param x The NegativeFiniteNumber to round.
170
- * @returns The rounded value as a NonPositiveInt (can be 0 if x > -0.5).
165
+ * @param a - The negative finite number value
166
+ * @returns The rounded value as an integer
171
167
  */
172
168
  round,
173
169
 
174
170
  /**
175
- * Generates a random NegativeFiniteNumber value.
171
+ * Generates a random `NegativeFiniteNumber` within the given range.
176
172
  *
177
- * @returns A random negative finite number.
173
+ * The range is inclusive on both ends.
174
+ *
175
+ * @param min - The minimum value (inclusive)
176
+ * @param max - The maximum value (inclusive)
177
+ * @returns A random `NegativeFiniteNumber` in `[min, max]`
178
178
  */
179
179
  random,
180
180
 
181
181
  /**
182
- * Raises a NegativeFiniteNumber to the power of another NegativeFiniteNumber.
182
+ * Raises `a` to the power `b`, returning `a ** b` as a
183
+ * `NegativeFiniteNumber`.
183
184
  *
184
- * @param a The base NegativeFiniteNumber.
185
- * @param b The exponent NegativeFiniteNumber.
186
- * @returns `a ** b` clamped to `(-∞, 0)` as a NegativeFiniteNumber.
185
+ * @param a - The base negative finite number
186
+ * @param b - The exponent negative finite number
187
+ * @returns `a ** b` as a `NegativeFiniteNumber`
187
188
  */
188
189
  pow,
189
190
 
190
191
  /**
191
- * Adds two NegativeFiniteNumber values.
192
+ * Adds two negative finite numbers, returning `a + b` as a
193
+ * `NegativeFiniteNumber`.
192
194
  *
193
- * @param a The first NegativeFiniteNumber.
194
- * @param b The second NegativeFiniteNumber.
195
- * @returns `a + b` as a NegativeFiniteNumber.
195
+ * @param a - The first negative finite number
196
+ * @param b - The second negative finite number
197
+ * @returns The sum of `a` and `b` as a `NegativeFiniteNumber`
196
198
  */
197
199
  add,
198
200
 
199
201
  /**
200
- * Subtracts one NegativeFiniteNumber from another.
201
- *
202
- * The mathematical result can be positive, so it is clamped to the negative
203
- * finite range (maximum `-Number.MIN_VALUE`).
202
+ * Subtracts two negative finite numbers, returning `a - b` as a
203
+ * `NegativeFiniteNumber`.
204
204
  *
205
- * @param a The minuend NegativeFiniteNumber.
206
- * @param b The subtrahend NegativeFiniteNumber.
207
- * @returns `a - b` clamped to `(-∞, 0)` as a NegativeFiniteNumber.
205
+ * @param a - The first negative finite number
206
+ * @param b - The second negative finite number
207
+ * @returns The difference of `a` and `b` as a `NegativeFiniteNumber`
208
208
  */
209
209
  sub,
210
210
  } as const;
@@ -34,127 +34,130 @@ const {
34
34
  typeNameInMessage,
35
35
  } as const);
36
36
 
37
- /**
38
- * Returns the absolute value of a negative integer.
39
- *
40
- * The absolute value of a negative integer is always a positive integer
41
- * (`>= 1`), so the result is typed as a {@link PositiveInt}.
42
- *
43
- * @param x - The negative integer.
44
- * @returns `|x|` as a PositiveInt.
45
- */
46
37
  const abs = (x: WithSmallInt<ElementType>): PositiveInt =>
47
38
  PositiveInt.clamp(Math.abs(x));
48
39
 
49
40
  /**
50
- * Checks if a number is a NegativeInt (a negative integer `<= -1`).
41
+ * Type guard that checks if a value is a negative integer.
42
+ *
43
+ * Returns `true` for a negative integer — a value with no fractional component,
44
+ * including values outside the safe integer range (unlike `SafeInt`).
51
45
  *
52
- * @param value The value to check.
53
- * @returns `true` if the value is a NegativeInt, `false` otherwise.
46
+ * @param value - The value to check
47
+ * @returns `true` if the value is a negative integer, `false` otherwise
54
48
  */
55
49
  export const isNegativeInt = is;
56
50
 
57
51
  /**
58
- * Casts a number to a NegativeInt type.
52
+ * Casts a `number` to the `NegativeInt` branded type.
53
+ *
54
+ * Validates that the value is a negative integer and returns it with the
55
+ * `NegativeInt` brand. Throws a `TypeError` otherwise.
59
56
  *
60
- * @param value The value to cast.
61
- * @returns The value as a NegativeInt type.
62
- * @throws {TypeError} If the value is not a negative integer.
57
+ * @param value - The value to cast
58
+ * @returns The value as a `NegativeInt`
59
+ * @throws {TypeError} If the value is not a negative integer
63
60
  */
64
61
  export const asNegativeInt = castType;
65
62
 
66
63
  /**
67
- * Namespace providing type-safe arithmetic operations for negative integers.
64
+ * Namespace providing type-safe operations for the `NegativeInt` branded type.
68
65
  *
69
- * NegativeInt represents integers that are strictly less than zero (`<= -1`).
70
- * Operations that stay within the negative integers (such as `add`) clamp their
71
- * results to the valid range, while operations whose result leaves the set
72
- * (`mul`, `div`, `abs`) are typed to reflect the actual sign of the result.
66
+ * The `NegativeInt` type represents a negative integer. Division (`div`) uses
67
+ * floor division.
68
+ *
69
+ * Unlike `SafeInt`, `NegativeInt` allows values outside the safe integer range
70
+ * (±2^53 − 1), so very large magnitudes may lose precision in JavaScript's
71
+ * `number` type.
73
72
  */
74
73
  export const NegativeInt = {
75
74
  /**
76
- * Type guard to check if a value is a NegativeInt.
75
+ * Type guard that checks if a value is a negative integer.
77
76
  *
78
- * @param value The value to check.
79
- * @returns `true` if the value is a negative integer, `false` otherwise.
77
+ * @param value - The value to check
78
+ * @returns `true` if the value is a negative integer, `false` otherwise
79
+ * @see {@link isNegativeInt} for usage examples
80
80
  */
81
81
  is,
82
82
 
83
83
  /**
84
- * The maximum value for a negative integer.
85
- *
86
- * @readonly
84
+ * The largest value representable as `NegativeInt`.
87
85
  */
88
86
  MAX_VALUE,
89
87
 
90
88
  /**
91
89
  * Returns the absolute value of a negative integer.
92
90
  *
93
- * @param a The negative integer.
94
- * @returns The absolute value as a PositiveInt.
91
+ * The result is non-negative and keeps the `NegativeInt` brand. Note that
92
+ * `Math.abs(Number.MIN_SAFE_INTEGER)` exceeds `Number.MAX_SAFE_INTEGER`, so
93
+ * use `SafeInt` for guaranteed precision.
94
+ *
95
+ * @param a - The negative integer value
96
+ * @returns The absolute value as a non-negative `NegativeInt`
95
97
  */
96
98
  abs,
97
99
 
98
100
  /**
99
- * Returns the smaller of two negative integers.
101
+ * Returns the smallest of the given negative integers.
100
102
  *
101
- * @param a The first negative integer.
102
- * @param b The second negative integer.
103
- * @returns The minimum value as a NegativeInt.
103
+ * @param values - The negative integers to compare (at least one required)
104
+ * @returns The smallest value as a `NegativeInt`
104
105
  */
105
106
  min: min_,
106
107
 
107
108
  /**
108
- * Returns the larger of two negative integers.
109
+ * Returns the largest of the given negative integers.
109
110
  *
110
- * @param a The first negative integer.
111
- * @param b The second negative integer.
112
- * @returns The maximum value as a NegativeInt.
111
+ * @param values - The negative integers to compare (at least one required)
112
+ * @returns The largest value as a `NegativeInt`
113
113
  */
114
114
  max: max_,
115
115
 
116
116
  /**
117
- * Clamps a number to the negative integer range.
117
+ * Clamps a `number` into the `NegativeInt` range, rounding to the nearest
118
+ * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
118
119
  *
119
- * @param value The number to clamp.
120
- * @returns The value clamped to `[-∞, -1]` as a NegativeInt.
120
+ * @param value - The value to clamp
121
+ * @returns The clamped value as a `NegativeInt`
121
122
  */
122
123
  clamp,
123
124
 
124
125
  /**
125
- * Generates a random NegativeInt value within the valid range.
126
+ * Generates a random `NegativeInt` within the given range.
126
127
  *
127
- * @returns A random negative integer.
128
+ * The range is inclusive on both ends.
129
+ *
130
+ * @param min - The minimum value (inclusive)
131
+ * @param max - The maximum value (inclusive)
132
+ * @returns A random `NegativeInt` in `[min, max]`
128
133
  */
129
134
  random,
130
135
 
131
136
  /**
132
- * Raises a negative integer to the power of another negative integer.
137
+ * Raises `a` to the power `b`, returning `a ** b` as a `NegativeInt` (floored
138
+ * to an integer).
133
139
  *
134
- * @param a The base negative integer.
135
- * @param b The exponent negative integer.
136
- * @returns `a ** b` clamped to the negative integer range.
140
+ * @param a - The base negative integer
141
+ * @param b - The exponent negative integer
142
+ * @returns `a ** b` as a `NegativeInt`
137
143
  */
138
144
  pow,
139
145
 
140
146
  /**
141
- * Adds two negative integers.
147
+ * Adds two negative integers, returning `a + b` as a `NegativeInt`.
142
148
  *
143
- * @param a The first negative integer.
144
- * @param b The second negative integer.
145
- * @returns `a + b` as a NegativeInt.
149
+ * @param a - The first negative integer
150
+ * @param b - The second negative integer
151
+ * @returns The sum of `a` and `b` as a `NegativeInt`
146
152
  */
147
153
  add,
148
154
 
149
155
  /**
150
- * Subtracts one negative integer from another.
151
- *
152
- * The mathematical result can be positive, so it is clamped to the negative
153
- * integer range (maximum `-1`).
156
+ * Subtracts two negative integers, returning `a - b` as a `NegativeInt`.
154
157
  *
155
- * @param a The minuend negative integer.
156
- * @param b The subtrahend negative integer.
157
- * @returns `a - b` clamped to the negative integer range.
158
+ * @param a - The first negative integer
159
+ * @param b - The second negative integer
160
+ * @returns The difference of `a` and `b` as a `NegativeInt`
158
161
  */
159
162
  sub,
160
163
  } as const;