ts-data-forge 9.0.0 → 9.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 (409) hide show
  1. package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
  2. package/dist/array/impl/array-utils-creation.mjs +17 -112
  3. package/dist/array/impl/array-utils-creation.mjs.map +1 -1
  4. package/dist/array/impl/array-utils-element-access.d.mts.map +1 -1
  5. package/dist/array/impl/array-utils-element-access.mjs +22 -61
  6. package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
  7. package/dist/array/impl/array-utils-iterators.d.mts.map +1 -1
  8. package/dist/array/impl/array-utils-iterators.mjs +9 -63
  9. package/dist/array/impl/array-utils-iterators.mjs.map +1 -1
  10. package/dist/array/impl/array-utils-modification.mjs +78 -78
  11. package/dist/array/impl/array-utils-modification.mjs.map +1 -1
  12. package/dist/array/impl/array-utils-reducing-value.mjs +95 -89
  13. package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
  14. package/dist/array/impl/array-utils-search.mjs +100 -92
  15. package/dist/array/impl/array-utils-search.mjs.map +1 -1
  16. package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
  17. package/dist/array/impl/array-utils-set-op.mjs +31 -141
  18. package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
  19. package/dist/array/impl/array-utils-size.d.mts.map +1 -1
  20. package/dist/array/impl/array-utils-size.mjs +4 -8
  21. package/dist/array/impl/array-utils-size.mjs.map +1 -1
  22. package/dist/array/impl/array-utils-slice-clamped.mjs +11 -12
  23. package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -1
  24. package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
  25. package/dist/array/impl/array-utils-slicing.mjs +44 -96
  26. package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
  27. package/dist/array/impl/array-utils-transformation.d.mts +1 -1
  28. package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
  29. package/dist/array/impl/array-utils-transformation.mjs +150 -292
  30. package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
  31. package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
  32. package/dist/array/impl/array-utils-validation.mjs +18 -169
  33. package/dist/array/impl/array-utils-validation.mjs.map +1 -1
  34. package/dist/collections/imap-mapped.d.mts.map +1 -1
  35. package/dist/collections/imap-mapped.mjs +243 -330
  36. package/dist/collections/imap-mapped.mjs.map +1 -1
  37. package/dist/collections/imap.d.mts.map +1 -1
  38. package/dist/collections/imap.mjs +190 -275
  39. package/dist/collections/imap.mjs.map +1 -1
  40. package/dist/collections/iset-mapped.d.mts +1 -1
  41. package/dist/collections/iset-mapped.d.mts.map +1 -1
  42. package/dist/collections/iset-mapped.mjs +222 -444
  43. package/dist/collections/iset-mapped.mjs.map +1 -1
  44. package/dist/collections/iset.d.mts +1 -1
  45. package/dist/collections/iset.d.mts.map +1 -1
  46. package/dist/collections/iset.mjs +158 -324
  47. package/dist/collections/iset.mjs.map +1 -1
  48. package/dist/collections/queue.d.mts.map +1 -1
  49. package/dist/collections/queue.mjs +106 -178
  50. package/dist/collections/queue.mjs.map +1 -1
  51. package/dist/collections/stack.d.mts.map +1 -1
  52. package/dist/collections/stack.mjs +95 -165
  53. package/dist/collections/stack.mjs.map +1 -1
  54. package/dist/expect-type.d.mts +1 -1
  55. package/dist/expect-type.d.mts.map +1 -1
  56. package/dist/expect-type.mjs +1 -69
  57. package/dist/expect-type.mjs.map +1 -1
  58. package/dist/functional/match.mjs +9 -9
  59. package/dist/functional/match.mjs.map +1 -1
  60. package/dist/functional/optional/impl/optional-expect-to-be.mjs +13 -14
  61. package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +1 -1
  62. package/dist/functional/optional/impl/optional-filter.mjs +14 -15
  63. package/dist/functional/optional/impl/optional-filter.mjs.map +1 -1
  64. package/dist/functional/optional/impl/optional-flat-map.mjs +10 -11
  65. package/dist/functional/optional/impl/optional-flat-map.mjs.map +1 -1
  66. package/dist/functional/optional/impl/optional-from-nullable.d.mts.map +1 -1
  67. package/dist/functional/optional/impl/optional-from-nullable.mjs +1 -25
  68. package/dist/functional/optional/impl/optional-from-nullable.mjs.map +1 -1
  69. package/dist/functional/optional/impl/optional-is-none.d.mts.map +1 -1
  70. package/dist/functional/optional/impl/optional-is-none.mjs +0 -19
  71. package/dist/functional/optional/impl/optional-is-none.mjs.map +1 -1
  72. package/dist/functional/optional/impl/optional-is-optional.d.mts.map +1 -1
  73. package/dist/functional/optional/impl/optional-is-optional.mjs +1 -23
  74. package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
  75. package/dist/functional/optional/impl/optional-is-some.d.mts.map +1 -1
  76. package/dist/functional/optional/impl/optional-is-some.mjs +0 -20
  77. package/dist/functional/optional/impl/optional-is-some.mjs.map +1 -1
  78. package/dist/functional/optional/impl/optional-map.mjs +13 -14
  79. package/dist/functional/optional/impl/optional-map.mjs.map +1 -1
  80. package/dist/functional/optional/impl/optional-none.mjs +0 -16
  81. package/dist/functional/optional/impl/optional-none.mjs.map +1 -1
  82. package/dist/functional/optional/impl/optional-or-else.mjs +10 -11
  83. package/dist/functional/optional/impl/optional-or-else.mjs.map +1 -1
  84. package/dist/functional/optional/impl/optional-some.d.mts.map +1 -1
  85. package/dist/functional/optional/impl/optional-some.mjs +2 -21
  86. package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
  87. package/dist/functional/optional/impl/optional-to-nullable.d.mts.map +1 -1
  88. package/dist/functional/optional/impl/optional-to-nullable.mjs +1 -27
  89. package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
  90. package/dist/functional/optional/impl/optional-unwrap-or.mjs +9 -10
  91. package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +1 -1
  92. package/dist/functional/optional/impl/optional-unwrap-throw.d.mts.map +1 -1
  93. package/dist/functional/optional/impl/optional-unwrap-throw.mjs +4 -32
  94. package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -1
  95. package/dist/functional/optional/impl/optional-unwrap.mjs +4 -4
  96. package/dist/functional/optional/impl/optional-unwrap.mjs.map +1 -1
  97. package/dist/functional/optional/impl/optional-zip.d.mts.map +1 -1
  98. package/dist/functional/optional/impl/optional-zip.mjs +1 -35
  99. package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
  100. package/dist/functional/optional/impl/tag.mjs +2 -3
  101. package/dist/functional/optional/impl/tag.mjs.map +1 -1
  102. package/dist/functional/pipe.d.mts.map +1 -1
  103. package/dist/functional/pipe.mjs +9 -34
  104. package/dist/functional/pipe.mjs.map +1 -1
  105. package/dist/functional/result/impl/result-err.d.mts.map +1 -1
  106. package/dist/functional/result/impl/result-err.mjs +2 -27
  107. package/dist/functional/result/impl/result-err.mjs.map +1 -1
  108. package/dist/functional/result/impl/result-expect-to-be.mjs +13 -15
  109. package/dist/functional/result/impl/result-expect-to-be.mjs.map +1 -1
  110. package/dist/functional/result/impl/result-flat-map.mjs +16 -16
  111. package/dist/functional/result/impl/result-flat-map.mjs.map +1 -1
  112. package/dist/functional/result/impl/result-fold.mjs +16 -16
  113. package/dist/functional/result/impl/result-fold.mjs.map +1 -1
  114. package/dist/functional/result/impl/result-from-promise.d.mts.map +1 -1
  115. package/dist/functional/result/impl/result-from-promise.mjs +4 -31
  116. package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
  117. package/dist/functional/result/impl/result-from-throwable.d.mts.map +1 -1
  118. package/dist/functional/result/impl/result-from-throwable.mjs +8 -38
  119. package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
  120. package/dist/functional/result/impl/result-is-err.d.mts.map +1 -1
  121. package/dist/functional/result/impl/result-is-err.mjs +0 -19
  122. package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
  123. package/dist/functional/result/impl/result-is-ok.d.mts.map +1 -1
  124. package/dist/functional/result/impl/result-is-ok.mjs +0 -19
  125. package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
  126. package/dist/functional/result/impl/result-is-result.d.mts.map +1 -1
  127. package/dist/functional/result/impl/result-is-result.mjs +1 -23
  128. package/dist/functional/result/impl/result-is-result.mjs.map +1 -1
  129. package/dist/functional/result/impl/result-map-err.mjs +16 -16
  130. package/dist/functional/result/impl/result-map-err.mjs.map +1 -1
  131. package/dist/functional/result/impl/result-map.mjs +16 -16
  132. package/dist/functional/result/impl/result-map.mjs.map +1 -1
  133. package/dist/functional/result/impl/result-ok.d.mts.map +1 -1
  134. package/dist/functional/result/impl/result-ok.mjs +2 -27
  135. package/dist/functional/result/impl/result-ok.mjs.map +1 -1
  136. package/dist/functional/result/impl/result-or-else.mjs +10 -12
  137. package/dist/functional/result/impl/result-or-else.mjs.map +1 -1
  138. package/dist/functional/result/impl/result-swap.d.mts.map +1 -1
  139. package/dist/functional/result/impl/result-swap.mjs +4 -22
  140. package/dist/functional/result/impl/result-swap.mjs.map +1 -1
  141. package/dist/functional/result/impl/result-to-optional.d.mts.map +1 -1
  142. package/dist/functional/result/impl/result-to-optional.mjs +0 -27
  143. package/dist/functional/result/impl/result-to-optional.mjs.map +1 -1
  144. package/dist/functional/result/impl/result-unwrap-err-or.mjs +9 -11
  145. package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +1 -1
  146. package/dist/functional/result/impl/result-unwrap-err-throw.d.mts.map +1 -1
  147. package/dist/functional/result/impl/result-unwrap-err-throw.mjs +13 -40
  148. package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
  149. package/dist/functional/result/impl/result-unwrap-err.d.mts.map +1 -1
  150. package/dist/functional/result/impl/result-unwrap-err.mjs +4 -32
  151. package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
  152. package/dist/functional/result/impl/result-unwrap-ok-or.mjs +9 -11
  153. package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +1 -1
  154. package/dist/functional/result/impl/result-unwrap-ok.mjs +4 -4
  155. package/dist/functional/result/impl/result-unwrap-ok.mjs.map +1 -1
  156. package/dist/functional/result/impl/result-unwrap-throw.d.mts.map +1 -1
  157. package/dist/functional/result/impl/result-unwrap-throw.mjs +4 -35
  158. package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
  159. package/dist/functional/result/impl/result-zip.d.mts.map +1 -1
  160. package/dist/functional/result/impl/result-zip.mjs +1 -34
  161. package/dist/functional/result/impl/result-zip.mjs.map +1 -1
  162. package/dist/functional/result/impl/tag.mjs +2 -3
  163. package/dist/functional/result/impl/tag.mjs.map +1 -1
  164. package/dist/functional/ternary-result/impl/tag.mjs +3 -5
  165. package/dist/functional/ternary-result/impl/tag.mjs.map +1 -1
  166. package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +1 -1
  167. package/dist/functional/ternary-result/impl/ternary-result-err.mjs +2 -15
  168. package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -1
  169. package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +13 -13
  170. package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +1 -1
  171. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +27 -26
  172. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -1
  173. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +21 -22
  174. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +1 -1
  175. package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts.map +1 -1
  176. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +4 -20
  177. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +1 -1
  178. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts.map +1 -1
  179. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +7 -25
  180. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -1
  181. package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts.map +1 -1
  182. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +0 -17
  183. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +1 -1
  184. package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts.map +1 -1
  185. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +0 -19
  186. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +1 -1
  187. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts.map +1 -1
  188. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +1 -25
  189. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +1 -1
  190. package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts.map +1 -1
  191. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +0 -18
  192. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +1 -1
  193. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +13 -15
  194. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +1 -1
  195. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +18 -18
  196. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -1
  197. package/dist/functional/ternary-result/impl/ternary-result-map.mjs +21 -22
  198. package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +1 -1
  199. package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +1 -1
  200. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +2 -16
  201. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -1
  202. package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +9 -9
  203. package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +1 -1
  204. package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts.map +1 -1
  205. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +4 -22
  206. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +1 -1
  207. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs +9 -9
  208. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +1 -1
  209. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts.map +1 -1
  210. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +12 -27
  211. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -1
  212. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts.map +1 -1
  213. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +4 -19
  214. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +1 -1
  215. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs +9 -9
  216. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +1 -1
  217. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +4 -5
  218. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +1 -1
  219. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts.map +1 -1
  220. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +15 -27
  221. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -1
  222. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs +9 -9
  223. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +1 -1
  224. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts.map +1 -1
  225. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +10 -24
  226. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -1
  227. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts.map +1 -1
  228. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +4 -19
  229. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +1 -1
  230. package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +1 -1
  231. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +3 -19
  232. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -1
  233. package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts.map +1 -1
  234. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +14 -45
  235. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -1
  236. package/dist/functional/ternary-result/impl/variant-name.d.mts +1 -1
  237. package/dist/functional/ternary-result/impl/variant-name.d.mts.map +1 -1
  238. package/dist/functional/ternary-result/impl/variant-name.mjs +8 -9
  239. package/dist/functional/ternary-result/impl/variant-name.mjs.map +1 -1
  240. package/dist/guard/has-key.d.mts.map +1 -1
  241. package/dist/guard/has-key.mjs +0 -41
  242. package/dist/guard/has-key.mjs.map +1 -1
  243. package/dist/guard/is-length-bounded-string.d.mts.map +1 -1
  244. package/dist/guard/is-length-bounded-string.mjs +0 -157
  245. package/dist/guard/is-length-bounded-string.mjs.map +1 -1
  246. package/dist/guard/is-non-empty-string.d.mts +1 -1
  247. package/dist/guard/is-non-empty-string.d.mts.map +1 -1
  248. package/dist/guard/is-non-empty-string.mjs +1 -38
  249. package/dist/guard/is-non-empty-string.mjs.map +1 -1
  250. package/dist/guard/is-non-null-object.d.mts.map +1 -1
  251. package/dist/guard/is-non-null-object.mjs +1 -35
  252. package/dist/guard/is-non-null-object.mjs.map +1 -1
  253. package/dist/guard/is-primitive.d.mts.map +1 -1
  254. package/dist/guard/is-primitive.mjs +12 -43
  255. package/dist/guard/is-primitive.mjs.map +1 -1
  256. package/dist/guard/is-record.d.mts.map +1 -1
  257. package/dist/guard/is-record.mjs +0 -86
  258. package/dist/guard/is-record.mjs.map +1 -1
  259. package/dist/guard/is-type.d.mts.map +1 -1
  260. package/dist/guard/is-type.mjs +12 -399
  261. package/dist/guard/is-type.mjs.map +1 -1
  262. package/dist/guard/key-is-in.d.mts.map +1 -1
  263. package/dist/guard/key-is-in.mjs +0 -40
  264. package/dist/guard/key-is-in.mjs.map +1 -1
  265. package/dist/iterator/range.mjs +16 -16
  266. package/dist/iterator/range.mjs.map +1 -1
  267. package/dist/json/json.d.mts.map +1 -1
  268. package/dist/json/json.mjs +52 -340
  269. package/dist/json/json.mjs.map +1 -1
  270. package/dist/number/branded-types/finite-number.d.mts +3 -3
  271. package/dist/number/branded-types/finite-number.mjs +135 -154
  272. package/dist/number/branded-types/finite-number.mjs.map +1 -1
  273. package/dist/number/branded-types/int.d.mts +4 -4
  274. package/dist/number/branded-types/int.mjs +205 -245
  275. package/dist/number/branded-types/int.mjs.map +1 -1
  276. package/dist/number/branded-types/int16.d.mts +15 -15
  277. package/dist/number/branded-types/int16.mjs +116 -123
  278. package/dist/number/branded-types/int16.mjs.map +1 -1
  279. package/dist/number/branded-types/int32.d.mts +11 -11
  280. package/dist/number/branded-types/int32.mjs +116 -123
  281. package/dist/number/branded-types/int32.mjs.map +1 -1
  282. package/dist/number/branded-types/negative-finite-number.d.mts +4 -4
  283. package/dist/number/branded-types/negative-finite-number.mjs +129 -144
  284. package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
  285. package/dist/number/branded-types/negative-int.d.mts +5 -5
  286. package/dist/number/branded-types/negative-int.mjs +94 -113
  287. package/dist/number/branded-types/negative-int.mjs.map +1 -1
  288. package/dist/number/branded-types/negative-safe-int.d.mts +5 -5
  289. package/dist/number/branded-types/negative-safe-int.mjs +103 -124
  290. package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
  291. package/dist/number/branded-types/non-negative-finite-number.d.mts +5 -5
  292. package/dist/number/branded-types/non-negative-finite-number.mjs +136 -142
  293. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
  294. package/dist/number/branded-types/non-negative-int16.d.mts +16 -16
  295. package/dist/number/branded-types/non-negative-int16.mjs +109 -118
  296. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
  297. package/dist/number/branded-types/non-negative-int32.d.mts +12 -12
  298. package/dist/number/branded-types/non-negative-int32.mjs +110 -119
  299. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
  300. package/dist/number/branded-types/non-positive-finite-number.d.mts +3 -3
  301. package/dist/number/branded-types/non-positive-finite-number.mjs +120 -124
  302. package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
  303. package/dist/number/branded-types/non-positive-int.d.mts +4 -4
  304. package/dist/number/branded-types/non-positive-int.mjs +167 -212
  305. package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
  306. package/dist/number/branded-types/non-positive-safe-int.d.mts +4 -4
  307. package/dist/number/branded-types/non-positive-safe-int.mjs +95 -106
  308. package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
  309. package/dist/number/branded-types/non-zero-finite-number.d.mts +4 -4
  310. package/dist/number/branded-types/non-zero-finite-number.mjs +114 -123
  311. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
  312. package/dist/number/branded-types/non-zero-int.d.mts +2 -2
  313. package/dist/number/branded-types/non-zero-int.mjs +72 -83
  314. package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
  315. package/dist/number/branded-types/non-zero-int16.d.mts +7 -7
  316. package/dist/number/branded-types/non-zero-int16.mjs +96 -107
  317. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
  318. package/dist/number/branded-types/non-zero-int32.d.mts +5 -5
  319. package/dist/number/branded-types/non-zero-int32.mjs +97 -108
  320. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
  321. package/dist/number/branded-types/non-zero-safe-int.d.mts +2 -2
  322. package/dist/number/branded-types/non-zero-safe-int.mjs +100 -111
  323. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
  324. package/dist/number/branded-types/non-zero-uint16.d.mts +8 -8
  325. package/dist/number/branded-types/non-zero-uint16.mjs +96 -107
  326. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
  327. package/dist/number/branded-types/non-zero-uint32.d.mts +6 -6
  328. package/dist/number/branded-types/non-zero-uint32.mjs +96 -107
  329. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
  330. package/dist/number/branded-types/positive-finite-number.d.mts +8 -8
  331. package/dist/number/branded-types/positive-finite-number.mjs +139 -141
  332. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
  333. package/dist/number/branded-types/positive-int.d.mts +11 -11
  334. package/dist/number/branded-types/positive-int.mjs +228 -271
  335. package/dist/number/branded-types/positive-int.mjs.map +1 -1
  336. package/dist/number/branded-types/positive-int16.d.mts +19 -19
  337. package/dist/number/branded-types/positive-int16.mjs +109 -118
  338. package/dist/number/branded-types/positive-int16.mjs.map +1 -1
  339. package/dist/number/branded-types/positive-int32.d.mts +15 -15
  340. package/dist/number/branded-types/positive-int32.mjs +109 -118
  341. package/dist/number/branded-types/positive-int32.mjs.map +1 -1
  342. package/dist/number/branded-types/positive-safe-int.d.mts +11 -11
  343. package/dist/number/branded-types/positive-safe-int.mjs +244 -275
  344. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
  345. package/dist/number/branded-types/positive-uint16.d.mts +17 -17
  346. package/dist/number/branded-types/positive-uint16.mjs +109 -118
  347. package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
  348. package/dist/number/branded-types/positive-uint32.d.mts +13 -13
  349. package/dist/number/branded-types/positive-uint32.mjs +110 -119
  350. package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
  351. package/dist/number/branded-types/safe-int.d.mts +4 -4
  352. package/dist/number/branded-types/safe-int.mjs +251 -292
  353. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  354. package/dist/number/branded-types/safe-uint.d.mts +8 -8
  355. package/dist/number/branded-types/safe-uint.mjs +111 -119
  356. package/dist/number/branded-types/safe-uint.mjs.map +1 -1
  357. package/dist/number/branded-types/uint.d.mts +8 -8
  358. package/dist/number/branded-types/uint.mjs +198 -225
  359. package/dist/number/branded-types/uint.mjs.map +1 -1
  360. package/dist/number/branded-types/uint16.d.mts +14 -14
  361. package/dist/number/branded-types/uint16.mjs +109 -119
  362. package/dist/number/branded-types/uint16.mjs.map +1 -1
  363. package/dist/number/branded-types/uint32.d.mts +10 -10
  364. package/dist/number/branded-types/uint32.mjs +110 -117
  365. package/dist/number/branded-types/uint32.mjs.map +1 -1
  366. package/dist/number/enum/int8.mjs +119 -145
  367. package/dist/number/enum/int8.mjs.map +1 -1
  368. package/dist/number/enum/uint8.mjs +107 -121
  369. package/dist/number/enum/uint8.mjs.map +1 -1
  370. package/dist/number/num.d.mts +2 -2
  371. package/dist/number/num.d.mts.map +1 -1
  372. package/dist/number/num.mjs +76 -537
  373. package/dist/number/num.mjs.map +1 -1
  374. package/dist/number/refined-number-utils.d.mts +1 -1
  375. package/dist/number/refined-number-utils.d.mts.map +1 -1
  376. package/dist/number/refined-number-utils.mjs +127 -263
  377. package/dist/number/refined-number-utils.mjs.map +1 -1
  378. package/dist/object/object.d.mts.map +1 -1
  379. package/dist/object/object.mjs +107 -222
  380. package/dist/object/object.mjs.map +1 -1
  381. package/dist/others/cast-mutable.d.mts.map +1 -1
  382. package/dist/others/cast-mutable.mjs +8 -37
  383. package/dist/others/cast-mutable.mjs.map +1 -1
  384. package/dist/others/cast-readonly.d.mts.map +1 -1
  385. package/dist/others/cast-readonly.mjs +8 -36
  386. package/dist/others/cast-readonly.mjs.map +1 -1
  387. package/dist/others/debounce-function.d.mts.map +1 -1
  388. package/dist/others/debounce-function.mjs +7 -16
  389. package/dist/others/debounce-function.mjs.map +1 -1
  390. package/dist/others/fast-deep-equal.d.mts.map +1 -1
  391. package/dist/others/fast-deep-equal.mjs +43 -59
  392. package/dist/others/fast-deep-equal.mjs.map +1 -1
  393. package/dist/others/if-then.d.mts.map +1 -1
  394. package/dist/others/if-then.mjs +0 -29
  395. package/dist/others/if-then.mjs.map +1 -1
  396. package/dist/others/map-nullable.mjs +9 -9
  397. package/dist/others/map-nullable.mjs.map +1 -1
  398. package/dist/others/memoize-function.mjs +12 -12
  399. package/dist/others/memoize-function.mjs.map +1 -1
  400. package/dist/others/tuple.d.mts.map +1 -1
  401. package/dist/others/tuple.mjs +0 -50
  402. package/dist/others/tuple.mjs.map +1 -1
  403. package/dist/others/unknown-to-string.d.mts.map +1 -1
  404. package/dist/others/unknown-to-string.mjs +41 -88
  405. package/dist/others/unknown-to-string.mjs.map +1 -1
  406. package/dist/promise/promise.d.mts.map +1 -1
  407. package/dist/promise/promise.mjs +4 -49
  408. package/dist/promise/promise.mjs.map +1 -1
  409. package/package.json +8 -7
@@ -2,552 +2,91 @@ import { err } from '../functional/result/impl/result-err.mjs';
2
2
  import { ok } from '../functional/result/impl/result-ok.mjs';
3
3
  import '@sindresorhus/is';
4
4
 
5
- /**
6
- * Namespace providing utility functions for number manipulation and validation.
7
- *
8
- * This namespace offers a comprehensive set of type-safe number utilities
9
- * including:
10
- *
11
- * - Type conversion and validation
12
- * - Type guards for numeric constraints (non-zero, non-negative, positive)
13
- * - Range checking and clamping operations
14
- * - Mathematical operations with type safety
15
- * - Rounding utilities
16
- *
17
- * Many functions in this namespace leverage TypeScript's type system to provide
18
- * compile-time guarantees about numeric constraints.
19
- */
20
5
  var Num;
21
- (function (Num) {
22
- /**
23
- * Converts an unknown value to a number. Alias for the `Number` constructor.
24
- *
25
- * @example
26
- *
27
- * ```ts
28
- * const input = '123.45';
29
- *
30
- * const result = Num.from(input);
31
- *
32
- * assert.isTrue(result === 123.45);
33
- * ```
34
- *
35
- * @param n The value to convert.
36
- * @returns The numeric representation of `n`.
37
- */
38
- Num.from = Number;
39
- /**
40
- * Safely parses a base-10 integer from a string, returning a {@link Result}
41
- * that is `Ok<Int>` for valid input and `Err<Error>` otherwise.
42
- *
43
- * This is a stricter alternative to both `parseInt` and `Number`:
44
- *
45
- * - Unlike `parseInt('12abc', 10)` (which returns `12`), trailing
46
- * non-numeric characters make the whole input invalid and yield `Err`.
47
- * - Unlike `Number('')` / `Number(' ')` (which return `0`), empty or
48
- * whitespace-only input yields `Err`.
49
- *
50
- * The empty-string case is rejected by delegating to `parseInt` (which
51
- * returns `NaN` there) rather than hard-coding a check, while the trailing-
52
- * garbage case is rejected via `Number`. Valid input is truncated toward
53
- * zero, so `'12.9'` becomes `12` and `'-3.5'` becomes `-3`.
54
- *
55
- * Only base 10 is supported. Use `Result.unwrapOk` (optionally with a
56
- * `?? Number.NaN` fallback) or `Result.unwrapOkOr` to get a plain number
57
- * back.
58
- *
59
- * @example
60
- *
61
- * ```ts
62
- * assert.strictEqual(
63
- * Result.unwrapOkOr(Num.safeParseInt('123'), Number.NaN),
64
- * 123,
65
- * );
66
- *
67
- * assert.strictEqual(
68
- * Result.unwrapOkOr(Num.safeParseInt('12.9'), Number.NaN),
69
- * 12,
70
- * );
71
- *
72
- * assert.strictEqual(
73
- * Result.unwrapOkOr(Num.safeParseInt('-12.9'), Number.NaN),
74
- * -12,
75
- * );
76
- *
77
- * assert.strictEqual(Number.parseInt('-12.9', 10), -12);
78
- *
79
- * // Native `parseInt` ignores trailing non-numeric characters
80
- *
81
- * assert.strictEqual(Number.parseInt('123abc', 10), 123);
82
- *
83
- * assert.isTrue(Number.isNaN(Number('123abc')));
84
- *
85
- * assert.isTrue(Result.isErr(Num.safeParseInt('123abc')));
86
- *
87
- * // Whitespace is not a valid integer, so we return an error instead of coercing to 0.
88
- *
89
- * assert.isTrue(Number.isNaN(Number.parseInt(' ', 10)));
90
- *
91
- * assert.strictEqual(Number(' '), 0); // Native `Number` coerces whitespace to 0
92
- *
93
- * assert.isTrue(Result.isErr(Num.safeParseInt('')));
94
- *
95
- * assert.strictEqual(Result.unwrapOk(Num.safeParseInt(' ')), undefined);
96
- * ```
97
- *
98
- * @param s The string to parse.
99
- * @returns `Result.ok(parsedInt)` for valid input, otherwise `Result.err`
100
- * wrapping an `Error` describing the invalid input.
101
- */
102
- Num.safeParseInt = (s) => {
103
- const viaNumber = Number(s);
104
- // `Number('')` / `Number(' ')` は 0 を返すが、`parseInt` は NaN を返す。
105
- // 末尾不正文字 ('12abc' 等) は `Number` 側が NaN にするので、両者が共に
106
- // 有効な場合のみ採用することで空文字・空白のみ・末尾不正をまとめて弾く。
107
- return Number.isNaN(viaNumber) || Number.isNaN(Number.parseInt(s, 10))
108
- ? err(new Error(`safeParseInt: "${s}" is not a valid base-10 integer`))
109
- : // eslint-disable-next-line total-functions/no-unsafe-type-assertion
110
- ok(Math.trunc(viaNumber));
111
- };
112
- /**
113
- * Safely parses a finite floating-point number from a string, returning a
114
- * {@link Result} that is `Ok<FiniteNumber>` for valid input and `Err<Error>`
115
- * otherwise.
116
- *
117
- * This is a stricter alternative to both `parseFloat` and `Number`:
118
- *
119
- * - Unlike `parseFloat('12abc')` (which returns `12`), trailing non-numeric
120
- * characters make the whole input invalid and yield `Err`.
121
- * - Unlike `Number('')` / `Number(' ')` (which return `0`), empty or
122
- * whitespace-only input yields `Err`.
123
- * - Unlike `Number('Infinity')` (which returns `Infinity`), non-finite values
124
- * yield `Err`.
125
- *
126
- * The empty-string case is rejected by delegating to `parseFloat` (which
127
- * returns `NaN` there) rather than hard-coding a check, while the trailing-
128
- * garbage case is rejected via `Number`. Decimal values are preserved as-is,
129
- * so `'12.9'` stays `12.9`.
130
- *
131
- * Use `Result.unwrapOk` (optionally with a `?? Number.NaN` fallback) or
132
- * `Result.unwrapOkOr` to get a plain number back.
133
- *
134
- * @example
135
- *
136
- * ```ts
137
- * assert.strictEqual(
138
- * Result.unwrapOkOr(Num.safeParseFloat('12.9'), Number.NaN),
139
- * 12.9,
140
- * );
141
- *
142
- * assert.strictEqual(
143
- * Result.unwrapOkOr(Num.safeParseFloat('-3.5'), Number.NaN),
144
- * -3.5,
145
- * );
146
- *
147
- * assert.strictEqual(
148
- * Result.unwrapOkOr(Num.safeParseFloat('1e3'), Number.NaN),
149
- * 1000,
150
- * );
151
- *
152
- * // Native `parseFloat` ignores trailing non-numeric characters
153
- *
154
- * assert.strictEqual(Number.parseFloat('12px'), 12);
155
- *
156
- * assert.isTrue(Result.isErr(Num.safeParseFloat('12px')));
157
- *
158
- * // Whitespace is not a valid number, so we return an error instead of coercing to 0.
159
- *
160
- * assert.isTrue(Result.isErr(Num.safeParseFloat('')));
161
- *
162
- * assert.isTrue(Result.isErr(Num.safeParseFloat(' ')));
163
- *
164
- * // Infinity and NaN are not finite, so they are rejected.
165
- *
166
- * assert.isTrue(Result.isErr(Num.safeParseFloat('Infinity')));
167
- *
168
- * assert.isTrue(Result.isErr(Num.safeParseFloat('NaN')));
169
- * ```
170
- *
171
- * @param s The string to parse.
172
- * @returns `Result.ok(parsedFloat)` for valid finite input, otherwise
173
- * `Result.err` wrapping an `Error` describing the invalid input.
174
- */
175
- Num.safeParseFloat = (s) => {
176
- const viaNumber = Number(s);
177
- // `Number('')` / `Number(' ')` は 0 を返すが、`parseFloat` は NaN を返す。
178
- // 末尾不正文字 ('12abc' 等) は `Number` 側が NaN にするので、両者が共に
179
- // 非 NaN かつ有限の場合のみ採用することで空文字・空白のみ・末尾不正・
180
- // Infinity をまとめて弾く。
181
- return Number.isNaN(viaNumber) ||
182
- !Number.isFinite(viaNumber) ||
183
- Number.isNaN(Number.parseFloat(s))
184
- ? err(new Error(`safeParseFloat: "${s}" is not a valid finite number`))
185
- : // eslint-disable-next-line total-functions/no-unsafe-type-assertion
186
- ok(viaNumber);
187
- };
188
- /**
189
- * Type guard that checks if a number is non-zero.
190
- *
191
- * When this function returns `true`, TypeScript narrows the type to exclude
192
- * zero, providing compile-time safety for division operations and other
193
- * calculations that require non-zero values.
194
- *
195
- * @example
196
- *
197
- * ```ts
198
- * const value: number = 5;
199
- *
200
- * if (Num.isNonZero(value)) {
201
- * // Safe to divide now that we know value is non-zero
202
- * // eslint-disable-next-line total-functions/no-partial-division
203
- * const inverted = 1 / value;
204
- *
205
- * assert.isTrue(inverted === 0.2);
206
- * }
207
- *
208
- * assert.isFalse(Num.isNonZero(0));
209
- * ```
210
- *
211
- * @template N - The numeric literal type or number type to check
212
- * @param num - The number to check
213
- * @returns `true` if the number is not zero, `false` otherwise
214
- */
215
- Num.isNonZero = (num) => num !== 0;
216
- /**
217
- * Type guard that checks if a number is non-negative (greater than or equal
218
- * to zero).
219
- *
220
- * When this function returns `true`, TypeScript narrows the type to exclude
221
- * negative values, which is useful for operations that require non-negative
222
- * inputs like array indices or measurements.
223
- *
224
- * @example
225
- *
226
- * ```ts
227
- * const candidate = 10;
228
- *
229
- * if (Num.isNonNegative(candidate)) {
230
- * const index: number = candidate;
231
- *
232
- * assert.isTrue(index === 10);
233
- * }
234
- *
235
- * assert.isFalse(Num.isNonNegative(-1));
236
- * ```
237
- *
238
- * @template N - The numeric literal type or number type to check
239
- * @param num - The number to check
240
- * @returns `true` if the number is >= 0, `false` otherwise
241
- */
242
- Num.isNonNegative = (num) => num >= 0;
243
- /**
244
- * Type guard that checks if a number is positive (greater than zero).
245
- *
246
- * When this function returns `true`, TypeScript narrows the type to exclude
247
- * zero and negative values. This is particularly useful for validating inputs
248
- * that must be strictly positive, such as dimensions, counts, or rates.
249
- *
250
- * @example
251
- *
252
- * ```ts
253
- * const amount = 42;
254
- *
255
- * if (Num.isPositive(amount)) {
256
- * assert.isTrue(amount > 0);
257
- * }
258
- *
259
- * assert.isFalse(Num.isPositive(0));
260
- * ```
261
- *
262
- * @template N - The numeric literal type or number type to check
263
- * @param num - The number to check
264
- * @returns `true` if the number is > 0, `false` otherwise
265
- */
266
- Num.isPositive = (num) => num > 0;
267
- /**
268
- * Creates a function that checks if a number `x` is within the range
269
- * `lowerBound <= x < upperBound`.
270
- *
271
- * @example
272
- *
273
- * ```ts
274
- * const isGrade = Num.isInRange(0, 100);
275
- *
276
- * assert.isTrue(isGrade(50));
277
- *
278
- * assert.isFalse(isGrade(100));
279
- * ```
280
- *
281
- * @param lowerBound The lower bound (inclusive).
282
- * @param upperBound The upper bound (exclusive).
283
- * @returns A function that takes a number `x` and returns `true` if `x` is in
284
- * the range, `false` otherwise.
285
- */
286
- Num.isInRange = (lowerBound, upperBound) => (x) => lowerBound <= x && x < upperBound;
287
- /**
288
- * Creates a function that checks if a number `x` is within the range
289
- * `lowerBound <= x <= upperBound`.
290
- *
291
- * @example
292
- *
293
- * ```ts
294
- * const isPercentage = Num.isInRangeInclusive(0, 100);
295
- *
296
- * assert.isTrue(isPercentage(100));
297
- *
298
- * assert.isFalse(isPercentage(-1));
299
- * ```
300
- *
301
- * @param lowerBound The lower bound (inclusive).
302
- * @param upperBound The upper bound (inclusive).
303
- * @returns A function that takes a number `x` and returns `true` if `x` is in
304
- * the range, `false` otherwise.
305
- */
306
- Num.isInRangeInclusive = (lowerBound, upperBound) => (x) => lowerBound <= x && x <= upperBound;
307
- /**
308
- * Creates a type guard that checks if a number is an unsigned integer within
309
- * a specified range.
310
- *
311
- * This function returns a predicate that validates whether a number is:
312
- *
313
- * - A safe integer (no floating point)
314
- * - Within the range [lowerBound, upperBound)
315
- *
316
- * The returned type guard provides precise type narrowing when the bounds are
317
- * SmallUint literals, making it ideal for array index validation.
318
- *
319
- * @example
320
- *
321
- * ```ts
322
- * const indexGuard = Num.isUintInRange(0, 5);
323
- *
324
- * assert.isTrue(indexGuard(3));
325
- *
326
- * assert.isFalse(indexGuard(5));
327
- *
328
- * assert.isFalse(indexGuard(-1));
329
- * ```
330
- *
331
- * @template L - The lower bound as a SmallUint literal type
332
- * @template U - The upper bound as a SmallUint literal type
333
- * @param lowerBound - The minimum value (inclusive)
334
- * @param upperBound - The maximum value (exclusive)
335
- * @returns A type guard function that validates and narrows number types
336
- */
337
- Num.isUintInRange = (lowerBound, upperBound) => (x) => Number.isSafeInteger(x) && lowerBound <= x && x < upperBound;
338
- /**
339
- * Creates a type guard that checks if a number is an unsigned integer within
340
- * a specified inclusive range.
341
- *
342
- * This function returns a predicate that validates whether a number is:
343
- *
344
- * - A safe integer (no floating point)
345
- * - Within the range [lowerBound, upperBound] (both bounds inclusive)
346
- *
347
- * The returned type guard provides precise type narrowing when the bounds are
348
- * SmallUint literals, useful for validating scores, percentages, or other
349
- * bounded values.
350
- *
351
- * @example
352
- *
353
- * ```ts
354
- * const inclusiveGuard = Num.isUintInRangeInclusive(0, 5);
355
- *
356
- * assert.isTrue(inclusiveGuard(5));
357
- *
358
- * assert.isFalse(inclusiveGuard(6));
359
- * ```
360
- *
361
- * @template L - The lower bound as a SmallUint literal type
362
- * @template U - The upper bound as a SmallUint literal type
363
- * @param lowerBound - The minimum value (inclusive)
364
- * @param upperBound - The maximum value (inclusive)
365
- * @returns A type guard function that validates and narrows number types
366
- */
367
- Num.isUintInRangeInclusive = (lowerBound, upperBound) => (x) => Number.isSafeInteger(x) && lowerBound <= x && x <= upperBound;
368
- function clamp(...args) {
369
- switch (args.length) {
370
- case 3: {
371
- const [target, lowerBound, upperBound] = args;
372
- return !Number.isFinite(target)
373
- ? lowerBound
374
- : Math.max(lowerBound, Math.min(upperBound, target));
375
- }
376
- case 2: {
377
- const [lowerBound, upperBound] = args;
378
- return (target) => clamp(target, lowerBound, upperBound);
379
- }
380
- }
6
+ ((Num2) => {
7
+ Num2.from = Number;
8
+ Num2.safeParseInt = (s) => {
9
+ const viaNumber = Number(s);
10
+ return Number.isNaN(viaNumber) || Number.isNaN(Number.parseInt(s, 10)) ? err(
11
+ new Error(`safeParseInt: "${s}" is not a valid base-10 integer`)
12
+ ) : (
13
+ // eslint-disable-next-line total-functions/no-unsafe-type-assertion
14
+ ok(Math.trunc(viaNumber))
15
+ );
16
+ };
17
+ Num2.safeParseFloat = (s) => {
18
+ const viaNumber = Number(s);
19
+ return Number.isNaN(viaNumber) || !Number.isFinite(viaNumber) || Number.isNaN(Number.parseFloat(s)) ? err(
20
+ new Error(`safeParseFloat: "${s}" is not a valid finite number`)
21
+ ) : (
22
+ // eslint-disable-next-line total-functions/no-unsafe-type-assertion
23
+ ok(viaNumber)
24
+ );
25
+ };
26
+ Num2.isNonZero = (num) => num !== 0;
27
+ Num2.isNonNegative = (num) => num >= 0;
28
+ Num2.isPositive = (num) => num > 0;
29
+ Num2.isInRange = (lowerBound, upperBound) => (x) => lowerBound <= x && x < upperBound;
30
+ Num2.isInRangeInclusive = (lowerBound, upperBound) => (x) => lowerBound <= x && x <= upperBound;
31
+ Num2.isUintInRange = (lowerBound, upperBound) => (x) => Number.isSafeInteger(x) && lowerBound <= x && x < upperBound;
32
+ Num2.isUintInRangeInclusive = (lowerBound, upperBound) => (x) => Number.isSafeInteger(x) && lowerBound <= x && x <= upperBound;
33
+ function clamp(...args) {
34
+ switch (args.length) {
35
+ case 3: {
36
+ const [target, lowerBound, upperBound] = args;
37
+ return !Number.isFinite(target) ? lowerBound : Math.max(lowerBound, Math.min(upperBound, target));
38
+ }
39
+ case 2: {
40
+ const [lowerBound, upperBound] = args;
41
+ return (target) => clamp(target, lowerBound, upperBound);
42
+ }
381
43
  }
382
- Num.clamp = clamp;
383
- /**
384
- * Adds two numbers, returning the tightest sound branded result type.
385
- *
386
- * The sign of the result is computed exactly (e.g. a non-negative plus a
387
- * non-negative is non-negative); the integer/finite level is preserved, with
388
- * `SafeInt` operands widening to `Int` because the sum may exceed the safe
389
- * range. No clamping is performed — for a result that stays inside a bounded
390
- * type, use that type's branded `add` instead.
391
- *
392
- * @param a - The first addend.
393
- * @param b - The second addend.
394
- * @returns `a + b`, typed as the tightest branded type guaranteed to contain
395
- * it.
396
- */
397
- Num.add = (a, b) =>
44
+ }
45
+ Num2.clamp = clamp;
46
+ Num2.add = (a, b) => (
398
47
  // eslint-disable-next-line total-functions/no-unsafe-type-assertion
399
- (a + b);
400
- /**
401
- * Subtracts `b` from `a`, returning the tightest sound branded result type.
402
- *
403
- * The sign is computed exactly; the level is preserved (with `SafeInt`
404
- * widening to `Int`). No clamping — for saturating subtraction that stays in a
405
- * bounded type (e.g. `Uint.sub` clamping at `0`), use that type's branded
406
- * `sub`.
407
- *
408
- * @param a - The minuend.
409
- * @param b - The subtrahend.
410
- * @returns `a - b`, typed as the tightest branded type guaranteed to contain
411
- * it.
412
- */
413
- Num.sub = (a, b) =>
48
+ a + b
49
+ );
50
+ Num2.sub = (a, b) => (
414
51
  // eslint-disable-next-line total-functions/no-unsafe-type-assertion
415
- (a - b);
416
- /**
417
- * Multiplies two numbers, returning the tightest sound branded result type.
418
- *
419
- * The sign follows the usual product rule (e.g. negative times negative is
420
- * positive); the level is preserved (with `SafeInt` widening to `Int`). No
421
- * clamping.
422
- *
423
- * @param a - The first factor.
424
- * @param b - The second factor.
425
- * @returns `a * b`, typed as the tightest branded type guaranteed to contain
426
- * it.
427
- */
428
- Num.mul = (a, b) =>
52
+ a - b
53
+ );
54
+ Num2.mul = (a, b) => (
429
55
  // eslint-disable-next-line total-functions/no-unsafe-type-assertion
430
- (a * b);
431
- /**
432
- * Performs type-safe exact division with a compile-time zero-check.
433
- *
434
- * The divisor must be typed as `NonZeroNumber` or a non-zero numeric literal.
435
- * The result sign follows the quotient rule; because exact division can be
436
- * fractional, the level is `finite` (or `number`).
437
- *
438
- * @param a - The dividend.
439
- * @param b - The divisor (must be non-zero, enforced by types).
440
- * @returns `a / b`, typed as the tightest branded type guaranteed to contain
441
- * it.
442
- */
443
- Num.div = (a, b) =>
56
+ a * b
57
+ );
58
+ Num2.div = (a, b) => (
444
59
  // eslint-disable-next-line total-functions/no-partial-division, total-functions/no-unsafe-type-assertion
445
- (a / b);
446
- /**
447
- * Performs integer division using floor division.
448
- *
449
- * Computes `⌊a / b⌋` by flooring both operands before division and then
450
- * flooring the result. This ensures integer arithmetic semantics.
451
- *
452
- * Note: Unlike `div`, this function does not enforce non-zero divisor at
453
- * compile time. Division by zero returns `NaN`.
454
- *
455
- * @param a - The dividend
456
- * @param b - The divisor
457
- * @returns The integer quotient, or `NaN` if b is zero
458
- */
459
- Num.divInt = (a, b) => {
460
- // eslint-disable-next-line total-functions/no-partial-division
461
- const quotient = Math.floor(Math.floor(a) / Math.floor(b));
462
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
463
- return quotient;
464
- };
465
- /**
466
- * Rounds a number to a specified number of decimal places.
467
- *
468
- * Uses the standard rounding algorithm (round half up) to round the number to
469
- * the given precision. The precision must be a positive safe integer.
470
- *
471
- * @param num - The number to round
472
- * @param precision - The number of decimal places (must be positive)
473
- * @returns The rounded number
474
- */
475
- Num.roundAt = (num, precision) => {
476
- const digit = 10 ** precision;
477
- // eslint-disable-next-line total-functions/no-partial-division
478
- return Math.round(num * digit) / digit;
479
- };
480
- /**
481
- * Rounds a number to the nearest integer using bitwise operations.
482
- *
483
- * This function uses a bitwise OR trick for potentially faster rounding.
484
- * Note: This implementation rounds half up for positive numbers but may
485
- * behave differently for negative numbers compared to Math.round.
486
- *
487
- * @param num - The number to round
488
- * @returns The rounded integer as an Int branded type
489
- */
60
+ a / b
61
+ );
62
+ Num2.divInt = (a, b) => {
63
+ const quotient = Math.floor(Math.floor(a) / Math.floor(b));
64
+ return quotient;
65
+ };
66
+ Num2.roundAt = (num, precision) => {
67
+ const digit = 10 ** precision;
68
+ return Math.round(num * digit) / digit;
69
+ };
70
+ Num2.roundToInt = (num) => Math.trunc(num + 0.5);
71
+ Num2.round = (digit) => {
72
+ const powAmount = 10 ** digit;
73
+ return (target) => (
74
+ // eslint-disable-next-line total-functions/no-partial-division
75
+ (0, Num2.roundToInt)(powAmount * target) / powAmount
76
+ );
77
+ };
78
+ Num2.mapNaN2Undefined = (num) => Number.isNaN(num) ? void 0 : (
490
79
  // eslint-disable-next-line total-functions/no-unsafe-type-assertion
491
- Num.roundToInt = (num) => Math.trunc(num + 0.5);
492
- /**
493
- * Creates a reusable rounding function with a fixed precision.
494
- *
495
- * This is a curried version of roundAt that returns a function configured to
496
- * always round to the specified number of decimal places. Useful for creating
497
- * consistent rounding behavior across multiple values.
498
- *
499
- * @param digit - The number of decimal places for rounding
500
- * @returns A function that rounds numbers to the specified precision
501
- */
502
- Num.round = (digit) => {
503
- const powAmount = 10 ** digit;
504
- return (target) =>
505
- // eslint-disable-next-line total-functions/no-partial-division
506
- Num.roundToInt(powAmount * target) / powAmount;
507
- };
508
- /**
509
- * Converts NaN values to undefined while preserving all other numbers.
510
- *
511
- * This function is useful for handling potentially invalid numeric operations
512
- * in a type-safe way, converting NaN results to undefined for easier handling
513
- * with optional chaining or nullish coalescing.
514
- *
515
- * @template N - The numeric type (literal or number)
516
- * @param num - The number to check
517
- * @returns The original number if not NaN, otherwise undefined
518
- */
519
- Num.mapNaN2Undefined = (num) => Number.isNaN(num)
520
- ? undefined
521
- : // eslint-disable-next-line total-functions/no-unsafe-type-assertion
522
- num;
523
- /**
524
- * Type-safe increment operation for SmallUint values.
525
- *
526
- * Increments a SmallUint (0-40) by 1 with the result type computed at compile
527
- * time. This provides type-level arithmetic for small unsigned integers,
528
- * useful for type-safe counter operations.
529
- *
530
- * @template N - A SmallUint literal type (0-40)
531
- * @param n - The SmallUint value to increment
532
- * @returns The incremented value with type Increment<N>
533
- */
534
- Num.increment = (n) =>
80
+ num
81
+ );
82
+ Num2.increment = (n) => (
535
83
  // eslint-disable-next-line total-functions/no-unsafe-type-assertion
536
- (n + 1);
537
- /**
538
- * Type-safe decrement operation for positive SmallInt values.
539
- *
540
- * Decrements a positive SmallInt (1-40) by 1 with the result type computed at
541
- * compile time. This provides type-level arithmetic for small positive
542
- * integers, useful for type-safe countdown operations.
543
- *
544
- * @template N - A positive SmallInt literal type (1-40)
545
- * @param n - The positive SmallInt value to decrement
546
- * @returns The decremented value with type Decrement<N>
547
- */
548
- Num.decrement = (n) =>
84
+ n + 1
85
+ );
86
+ Num2.decrement = (n) => (
549
87
  // eslint-disable-next-line total-functions/no-unsafe-type-assertion
550
- (n - 1);
88
+ n - 1
89
+ );
551
90
  })(Num || (Num = {}));
552
91
 
553
92
  export { Num };