ts-data-forge 14.6.1 → 14.6.3

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 (420) hide show
  1. package/dist/array/impl/array-utils-creation.mjs +126 -26
  2. package/dist/array/impl/array-utils-creation.mjs.map +1 -1
  3. package/dist/array/impl/array-utils-element-access.mjs +63 -30
  4. package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
  5. package/dist/array/impl/array-utils-iterators.mjs +68 -52
  6. package/dist/array/impl/array-utils-iterators.mjs.map +1 -1
  7. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +109 -73
  8. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
  9. package/dist/array/impl/array-utils-length-bounded-array-guard.mjs +70 -32
  10. package/dist/array/impl/array-utils-length-bounded-array-guard.mjs.map +1 -1
  11. package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs +102 -73
  12. package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs.map +1 -1
  13. package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs +77 -33
  14. package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs.map +1 -1
  15. package/dist/array/impl/array-utils-modification.mjs +75 -122
  16. package/dist/array/impl/array-utils-modification.mjs.map +1 -1
  17. package/dist/array/impl/array-utils-reducing-value.mjs +99 -149
  18. package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
  19. package/dist/array/impl/array-utils-search.mjs +112 -136
  20. package/dist/array/impl/array-utils-search.mjs.map +1 -1
  21. package/dist/array/impl/array-utils-set-op.mjs +146 -38
  22. package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
  23. package/dist/array/impl/array-utils-size.mjs +10 -8
  24. package/dist/array/impl/array-utils-size.mjs.map +1 -1
  25. package/dist/array/impl/array-utils-slice-clamped.mjs +13 -50
  26. package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -1
  27. package/dist/array/impl/array-utils-slicing.mjs +92 -76
  28. package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
  29. package/dist/array/impl/array-utils-transformation.mjs +291 -199
  30. package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
  31. package/dist/array/impl/array-utils-validation.mjs +53 -55
  32. package/dist/array/impl/array-utils-validation.mjs.map +1 -1
  33. package/dist/array/impl/index.mjs +17 -17
  34. package/dist/array/impl/index.mjs.map +1 -1
  35. package/dist/array/index.mjs +2 -3
  36. package/dist/array/index.mjs.map +1 -1
  37. package/dist/collections/imap-mapped.mjs +335 -292
  38. package/dist/collections/imap-mapped.mjs.map +1 -1
  39. package/dist/collections/imap.mjs +280 -239
  40. package/dist/collections/imap.mjs.map +1 -1
  41. package/dist/collections/index.mjs +7 -7
  42. package/dist/collections/index.mjs.map +1 -1
  43. package/dist/collections/iset-mapped.mjs +448 -265
  44. package/dist/collections/iset-mapped.mjs.map +1 -1
  45. package/dist/collections/iset.mjs +328 -201
  46. package/dist/collections/iset.mjs.map +1 -1
  47. package/dist/collections/queue.mjs +181 -149
  48. package/dist/collections/queue.mjs.map +1 -1
  49. package/dist/collections/stack.mjs +167 -138
  50. package/dist/collections/stack.mjs.map +1 -1
  51. package/dist/entry-point.mjs +4 -77
  52. package/dist/entry-point.mjs.map +1 -1
  53. package/dist/expect-type.mjs +69 -3
  54. package/dist/expect-type.mjs.map +1 -1
  55. package/dist/functional/async-result/async-result.mjs +2 -3
  56. package/dist/functional/async-result/async-result.mjs.map +1 -1
  57. package/dist/functional/async-result/impl/async-result-flat-map.mjs +18 -20
  58. package/dist/functional/async-result/impl/async-result-flat-map.mjs.map +1 -1
  59. package/dist/functional/async-result/impl/async-result-from-promise.mjs +9 -10
  60. package/dist/functional/async-result/impl/async-result-from-promise.mjs.map +1 -1
  61. package/dist/functional/async-result/impl/async-result-from-throwable.mjs +12 -14
  62. package/dist/functional/async-result/impl/async-result-from-throwable.mjs.map +1 -1
  63. package/dist/functional/async-result/impl/async-result-map-err.mjs +15 -18
  64. package/dist/functional/async-result/impl/async-result-map-err.mjs.map +1 -1
  65. package/dist/functional/async-result/impl/async-result-map.mjs +15 -18
  66. package/dist/functional/async-result/impl/async-result-map.mjs.map +1 -1
  67. package/dist/functional/async-result/impl/async-result-unwrap-or.mjs +35 -8
  68. package/dist/functional/async-result/impl/async-result-unwrap-or.mjs.map +1 -1
  69. package/dist/functional/async-result/impl/index.mjs +8 -7
  70. package/dist/functional/async-result/impl/index.mjs.map +1 -1
  71. package/dist/functional/async-result/impl/types.mjs +2 -2
  72. package/dist/functional/async-result/impl/types.mjs.map +1 -1
  73. package/dist/functional/async-result/index.mjs +2 -3
  74. package/dist/functional/async-result/index.mjs.map +1 -1
  75. package/dist/functional/index.mjs +7 -11
  76. package/dist/functional/index.mjs.map +1 -1
  77. package/dist/functional/match.mjs +27 -13
  78. package/dist/functional/match.mjs.map +1 -1
  79. package/dist/functional/optional/impl/index.mjs +19 -18
  80. package/dist/functional/optional/impl/index.mjs.map +1 -1
  81. package/dist/functional/optional/impl/optional-expect-to-be.mjs +15 -17
  82. package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +1 -1
  83. package/dist/functional/optional/impl/optional-filter.mjs +16 -18
  84. package/dist/functional/optional/impl/optional-filter.mjs.map +1 -1
  85. package/dist/functional/optional/impl/optional-flat-map.mjs +12 -14
  86. package/dist/functional/optional/impl/optional-flat-map.mjs.map +1 -1
  87. package/dist/functional/optional/impl/optional-from-nullable.mjs +24 -3
  88. package/dist/functional/optional/impl/optional-from-nullable.mjs.map +1 -1
  89. package/dist/functional/optional/impl/optional-is-none.mjs +19 -3
  90. package/dist/functional/optional/impl/optional-is-none.mjs.map +1 -1
  91. package/dist/functional/optional/impl/optional-is-optional.mjs +24 -6
  92. package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
  93. package/dist/functional/optional/impl/optional-is-some.mjs +20 -3
  94. package/dist/functional/optional/impl/optional-is-some.mjs.map +1 -1
  95. package/dist/functional/optional/impl/optional-map.mjs +15 -17
  96. package/dist/functional/optional/impl/optional-map.mjs.map +1 -1
  97. package/dist/functional/optional/impl/optional-match.mjs +15 -17
  98. package/dist/functional/optional/impl/optional-match.mjs.map +1 -1
  99. package/dist/functional/optional/impl/optional-none.mjs +16 -3
  100. package/dist/functional/optional/impl/optional-none.mjs.map +1 -1
  101. package/dist/functional/optional/impl/optional-or-else.mjs +12 -14
  102. package/dist/functional/optional/impl/optional-or-else.mjs.map +1 -1
  103. package/dist/functional/optional/impl/optional-some.mjs +22 -6
  104. package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
  105. package/dist/functional/optional/impl/optional-to-nullable.mjs +26 -3
  106. package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
  107. package/dist/functional/optional/impl/optional-unwrap-or.mjs +11 -13
  108. package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +1 -1
  109. package/dist/functional/optional/impl/optional-unwrap-throw.mjs +33 -8
  110. package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -1
  111. package/dist/functional/optional/impl/optional-unwrap.mjs +6 -9
  112. package/dist/functional/optional/impl/optional-unwrap.mjs.map +1 -1
  113. package/dist/functional/optional/impl/optional-zip.mjs +34 -3
  114. package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
  115. package/dist/functional/optional/impl/tag.mjs +3 -4
  116. package/dist/functional/optional/impl/tag.mjs.map +1 -1
  117. package/dist/functional/optional/impl/types.mjs +2 -2
  118. package/dist/functional/optional/impl/types.mjs.map +1 -1
  119. package/dist/functional/optional/index.mjs +2 -3
  120. package/dist/functional/optional/index.mjs.map +1 -1
  121. package/dist/functional/optional/optional.mjs +2 -3
  122. package/dist/functional/optional/optional.mjs.map +1 -1
  123. package/dist/functional/pipe.mjs +42 -14
  124. package/dist/functional/pipe.mjs.map +1 -1
  125. package/dist/functional/result/impl/index.mjs +28 -27
  126. package/dist/functional/result/impl/index.mjs.map +1 -1
  127. package/dist/functional/result/impl/result-err.mjs +28 -6
  128. package/dist/functional/result/impl/result-err.mjs.map +1 -1
  129. package/dist/functional/result/impl/result-expect-to-be.mjs +16 -17
  130. package/dist/functional/result/impl/result-expect-to-be.mjs.map +1 -1
  131. package/dist/functional/result/impl/result-flat-map.mjs +17 -20
  132. package/dist/functional/result/impl/result-flat-map.mjs.map +1 -1
  133. package/dist/functional/result/impl/result-fold.mjs +17 -20
  134. package/dist/functional/result/impl/result-fold.mjs.map +1 -1
  135. package/dist/functional/result/impl/result-from-optional.mjs +16 -19
  136. package/dist/functional/result/impl/result-from-optional.mjs.map +1 -1
  137. package/dist/functional/result/impl/result-from-promise.mjs +35 -6
  138. package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
  139. package/dist/functional/result/impl/result-from-throwable.mjs +40 -13
  140. package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
  141. package/dist/functional/result/impl/result-is-err.mjs +19 -3
  142. package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
  143. package/dist/functional/result/impl/result-is-ok.mjs +19 -3
  144. package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
  145. package/dist/functional/result/impl/result-is-result.mjs +23 -5
  146. package/dist/functional/result/impl/result-is-result.mjs.map +1 -1
  147. package/dist/functional/result/impl/result-map-err.mjs +17 -20
  148. package/dist/functional/result/impl/result-map-err.mjs.map +1 -1
  149. package/dist/functional/result/impl/result-map.mjs +17 -20
  150. package/dist/functional/result/impl/result-map.mjs.map +1 -1
  151. package/dist/functional/result/impl/result-match.mjs +16 -20
  152. package/dist/functional/result/impl/result-match.mjs.map +1 -1
  153. package/dist/functional/result/impl/result-ok.mjs +28 -6
  154. package/dist/functional/result/impl/result-ok.mjs.map +1 -1
  155. package/dist/functional/result/impl/result-or-else.mjs +13 -14
  156. package/dist/functional/result/impl/result-or-else.mjs.map +1 -1
  157. package/dist/functional/result/impl/result-safe-try.mjs +32 -21
  158. package/dist/functional/result/impl/result-safe-try.mjs.map +1 -1
  159. package/dist/functional/result/impl/result-safe-unwrap.mjs +39 -11
  160. package/dist/functional/result/impl/result-safe-unwrap.mjs.map +1 -1
  161. package/dist/functional/result/impl/result-swap.mjs +21 -6
  162. package/dist/functional/result/impl/result-swap.mjs.map +1 -1
  163. package/dist/functional/result/impl/result-to-optional.mjs +28 -5
  164. package/dist/functional/result/impl/result-to-optional.mjs.map +1 -1
  165. package/dist/functional/result/impl/result-unwrap-err-or.mjs +12 -13
  166. package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +1 -1
  167. package/dist/functional/result/impl/result-unwrap-err-throw.mjs +42 -19
  168. package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
  169. package/dist/functional/result/impl/result-unwrap-err.mjs +31 -6
  170. package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
  171. package/dist/functional/result/impl/result-unwrap-ok-or.mjs +12 -13
  172. package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +1 -1
  173. package/dist/functional/result/impl/result-unwrap-ok.mjs +6 -9
  174. package/dist/functional/result/impl/result-unwrap-ok.mjs.map +1 -1
  175. package/dist/functional/result/impl/result-unwrap-throw.mjs +37 -10
  176. package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
  177. package/dist/functional/result/impl/result-zip.mjs +33 -3
  178. package/dist/functional/result/impl/result-zip.mjs.map +1 -1
  179. package/dist/functional/result/impl/tag.mjs +3 -4
  180. package/dist/functional/result/impl/tag.mjs.map +1 -1
  181. package/dist/functional/result/impl/types.mjs +2 -2
  182. package/dist/functional/result/impl/types.mjs.map +1 -1
  183. package/dist/functional/result/index.mjs +2 -3
  184. package/dist/functional/result/index.mjs.map +1 -1
  185. package/dist/functional/result/result.mjs +2 -3
  186. package/dist/functional/result/result.mjs.map +1 -1
  187. package/dist/functional/ternary-result/impl/index.mjs +29 -28
  188. package/dist/functional/ternary-result/impl/index.mjs.map +1 -1
  189. package/dist/functional/ternary-result/impl/tag.mjs +5 -5
  190. package/dist/functional/ternary-result/impl/tag.mjs.map +1 -1
  191. package/dist/functional/ternary-result/impl/ternary-result-err.mjs +16 -6
  192. package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -1
  193. package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +15 -18
  194. package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +1 -1
  195. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +29 -33
  196. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -1
  197. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +24 -26
  198. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +1 -1
  199. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +19 -6
  200. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +1 -1
  201. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +27 -12
  202. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -1
  203. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +17 -3
  204. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +1 -1
  205. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +19 -3
  206. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +1 -1
  207. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +26 -6
  208. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +1 -1
  209. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +18 -3
  210. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +1 -1
  211. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +17 -18
  212. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +1 -1
  213. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +20 -23
  214. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -1
  215. package/dist/functional/ternary-result/impl/ternary-result-map.mjs +24 -26
  216. package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +1 -1
  217. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +17 -6
  218. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -1
  219. package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +11 -14
  220. package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +1 -1
  221. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +22 -8
  222. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +1 -1
  223. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs +11 -14
  224. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +1 -1
  225. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +29 -18
  226. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -1
  227. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +18 -6
  228. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +1 -1
  229. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs +11 -14
  230. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +1 -1
  231. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +6 -8
  232. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +1 -1
  233. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +31 -23
  234. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -1
  235. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs +11 -14
  236. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +1 -1
  237. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +26 -16
  238. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -1
  239. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +18 -6
  240. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +1 -1
  241. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +20 -7
  242. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -1
  243. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +46 -18
  244. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -1
  245. package/dist/functional/ternary-result/impl/types.mjs +2 -2
  246. package/dist/functional/ternary-result/impl/types.mjs.map +1 -1
  247. package/dist/functional/ternary-result/impl/variant-name.mjs +11 -13
  248. package/dist/functional/ternary-result/impl/variant-name.mjs.map +1 -1
  249. package/dist/functional/ternary-result/index.mjs +2 -3
  250. package/dist/functional/ternary-result/index.mjs.map +1 -1
  251. package/dist/functional/ternary-result/ternary-result.mjs +2 -3
  252. package/dist/functional/ternary-result/ternary-result.mjs.map +1 -1
  253. package/dist/guard/has-key.mjs +42 -3
  254. package/dist/guard/has-key.mjs.map +1 -1
  255. package/dist/guard/index.mjs +8 -8
  256. package/dist/guard/index.mjs.map +1 -1
  257. package/dist/guard/is-non-empty-string.mjs +38 -3
  258. package/dist/guard/is-non-empty-string.mjs.map +1 -1
  259. package/dist/guard/is-non-null-object.mjs +35 -3
  260. package/dist/guard/is-non-null-object.mjs.map +1 -1
  261. package/dist/guard/is-primitive.mjs +46 -15
  262. package/dist/guard/is-primitive.mjs.map +1 -1
  263. package/dist/guard/is-record.mjs +87 -4
  264. package/dist/guard/is-record.mjs.map +1 -1
  265. package/dist/guard/is-type.mjs +404 -19
  266. package/dist/guard/is-type.mjs.map +1 -1
  267. package/dist/guard/key-is-in.mjs +41 -3
  268. package/dist/guard/key-is-in.mjs.map +1 -1
  269. package/dist/index.mjs +12 -65
  270. package/dist/index.mjs.map +1 -1
  271. package/dist/iterator/index.mjs +2 -2
  272. package/dist/iterator/index.mjs.map +1 -1
  273. package/dist/iterator/range.mjs +18 -56
  274. package/dist/iterator/range.mjs.map +1 -1
  275. package/dist/json/index.mjs +2 -2
  276. package/dist/json/index.mjs.map +1 -1
  277. package/dist/json/json.mjs +346 -105
  278. package/dist/json/json.mjs.map +1 -1
  279. package/dist/number/branded-types/finite-number.mjs +148 -137
  280. package/dist/number/branded-types/finite-number.mjs.map +1 -1
  281. package/dist/number/branded-types/index.mjs +33 -33
  282. package/dist/number/branded-types/index.mjs.map +1 -1
  283. package/dist/number/branded-types/int.mjs +245 -209
  284. package/dist/number/branded-types/int.mjs.map +1 -1
  285. package/dist/number/branded-types/int16.mjs +141 -131
  286. package/dist/number/branded-types/int16.mjs.map +1 -1
  287. package/dist/number/branded-types/int32.mjs +141 -131
  288. package/dist/number/branded-types/int32.mjs.map +1 -1
  289. package/dist/number/branded-types/negative-finite-number.mjs +155 -149
  290. package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
  291. package/dist/number/branded-types/negative-int.mjs +125 -110
  292. package/dist/number/branded-types/negative-int.mjs.map +1 -1
  293. package/dist/number/branded-types/negative-safe-int.mjs +126 -115
  294. package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
  295. package/dist/number/branded-types/non-negative-finite-number.mjs +164 -154
  296. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
  297. package/dist/number/branded-types/non-negative-int16.mjs +137 -125
  298. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
  299. package/dist/number/branded-types/non-negative-int32.mjs +137 -125
  300. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
  301. package/dist/number/branded-types/non-positive-finite-number.mjs +143 -139
  302. package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
  303. package/dist/number/branded-types/non-positive-int.mjs +116 -99
  304. package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
  305. package/dist/number/branded-types/non-positive-safe-int.mjs +118 -107
  306. package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
  307. package/dist/number/branded-types/non-zero-finite-number.mjs +144 -129
  308. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
  309. package/dist/number/branded-types/non-zero-int.mjs +102 -82
  310. package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
  311. package/dist/number/branded-types/non-zero-int16.mjs +118 -105
  312. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
  313. package/dist/number/branded-types/non-zero-int32.mjs +118 -105
  314. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
  315. package/dist/number/branded-types/non-zero-safe-int.mjs +121 -107
  316. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
  317. package/dist/number/branded-types/non-zero-uint16.mjs +118 -104
  318. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
  319. package/dist/number/branded-types/non-zero-uint32.mjs +118 -104
  320. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
  321. package/dist/number/branded-types/positive-finite-number.mjs +167 -160
  322. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
  323. package/dist/number/branded-types/positive-int.mjs +260 -224
  324. package/dist/number/branded-types/positive-int.mjs.map +1 -1
  325. package/dist/number/branded-types/positive-int16.mjs +134 -122
  326. package/dist/number/branded-types/positive-int16.mjs.map +1 -1
  327. package/dist/number/branded-types/positive-int32.mjs +134 -122
  328. package/dist/number/branded-types/positive-int32.mjs.map +1 -1
  329. package/dist/number/branded-types/positive-safe-int.mjs +291 -257
  330. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
  331. package/dist/number/branded-types/positive-uint16.mjs +134 -122
  332. package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
  333. package/dist/number/branded-types/positive-uint32.mjs +134 -122
  334. package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
  335. package/dist/number/branded-types/safe-int.mjs +283 -254
  336. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  337. package/dist/number/branded-types/safe-uint.mjs +134 -123
  338. package/dist/number/branded-types/safe-uint.mjs.map +1 -1
  339. package/dist/number/branded-types/uint.mjs +248 -211
  340. package/dist/number/branded-types/uint.mjs.map +1 -1
  341. package/dist/number/branded-types/uint16.mjs +132 -121
  342. package/dist/number/branded-types/uint16.mjs.map +1 -1
  343. package/dist/number/branded-types/uint32.mjs +132 -121
  344. package/dist/number/branded-types/uint32.mjs.map +1 -1
  345. package/dist/number/enum/index.mjs +3 -3
  346. package/dist/number/enum/index.mjs.map +1 -1
  347. package/dist/number/enum/int8.mjs +146 -131
  348. package/dist/number/enum/int8.mjs.map +1 -1
  349. package/dist/number/enum/uint8.mjs +133 -119
  350. package/dist/number/enum/uint8.mjs.map +1 -1
  351. package/dist/number/index.mjs +6 -37
  352. package/dist/number/index.mjs.map +1 -1
  353. package/dist/number/num-arithmetic-types.mjs +42 -1
  354. package/dist/number/num-arithmetic-types.mjs.map +1 -1
  355. package/dist/number/num.mjs +549 -91
  356. package/dist/number/num.mjs.map +1 -1
  357. package/dist/number/refined-number-utils.mjs +294 -133
  358. package/dist/number/refined-number-utils.mjs.map +1 -1
  359. package/dist/object/index.mjs +2 -2
  360. package/dist/object/index.mjs.map +1 -1
  361. package/dist/object/object.mjs +356 -203
  362. package/dist/object/object.mjs.map +1 -1
  363. package/dist/others/cast-mutable.mjs +38 -11
  364. package/dist/others/cast-mutable.mjs.map +1 -1
  365. package/dist/others/cast-readonly.mjs +37 -11
  366. package/dist/others/cast-readonly.mjs.map +1 -1
  367. package/dist/others/debounce-function.mjs +22 -11
  368. package/dist/others/debounce-function.mjs.map +1 -1
  369. package/dist/others/fast-deep-equal.mjs +70 -51
  370. package/dist/others/fast-deep-equal.mjs.map +1 -1
  371. package/dist/others/if-then.mjs +31 -4
  372. package/dist/others/if-then.mjs.map +1 -1
  373. package/dist/others/index.mjs +10 -10
  374. package/dist/others/index.mjs.map +1 -1
  375. package/dist/others/map-nullable.mjs +11 -13
  376. package/dist/others/map-nullable.mjs.map +1 -1
  377. package/dist/others/memoize-function.mjs +14 -16
  378. package/dist/others/memoize-function.mjs.map +1 -1
  379. package/dist/others/tuple.mjs +51 -3
  380. package/dist/others/tuple.mjs.map +1 -1
  381. package/dist/others/unknown-to-string.mjs +91 -47
  382. package/dist/others/unknown-to-string.mjs.map +1 -1
  383. package/dist/promise/index.mjs +2 -2
  384. package/dist/promise/index.mjs.map +1 -1
  385. package/dist/promise/promise.mjs +49 -8
  386. package/dist/promise/promise.mjs.map +1 -1
  387. package/dist/string/index.mjs +2 -2
  388. package/dist/string/index.mjs.map +1 -1
  389. package/dist/string/str.mjs +250 -83
  390. package/dist/string/str.mjs.map +1 -1
  391. package/dist/types.mjs +2 -1
  392. package/dist/types.mjs.map +1 -1
  393. package/package.json +6 -7
  394. package/src/guard/is-type.test.mts +2 -2
  395. package/src/number/branded-types/finite-number.test.mts +1 -1
  396. package/src/number/branded-types/int.test.mts +1 -1
  397. package/src/number/branded-types/int16.test.mts +1 -1
  398. package/src/number/branded-types/int32.test.mts +1 -1
  399. package/src/number/branded-types/non-negative-finite-number.test.mts +1 -1
  400. package/src/number/branded-types/non-negative-int16.test.mts +1 -1
  401. package/src/number/branded-types/non-negative-int32.test.mts +1 -1
  402. package/src/number/branded-types/non-zero-finite-number.test.mts +1 -1
  403. package/src/number/branded-types/non-zero-int.test.mts +1 -1
  404. package/src/number/branded-types/non-zero-int16.test.mts +1 -1
  405. package/src/number/branded-types/non-zero-int32.test.mts +1 -1
  406. package/src/number/branded-types/non-zero-safe-int.test.mts +1 -1
  407. package/src/number/branded-types/non-zero-uint16.test.mts +1 -1
  408. package/src/number/branded-types/non-zero-uint32.test.mts +1 -1
  409. package/src/number/branded-types/positive-finite-number.test.mts +1 -1
  410. package/src/number/branded-types/positive-int.test.mts +1 -1
  411. package/src/number/branded-types/positive-int16.test.mts +1 -1
  412. package/src/number/branded-types/positive-int32.test.mts +1 -1
  413. package/src/number/branded-types/positive-safe-int.test.mts +1 -1
  414. package/src/number/branded-types/positive-uint16.test.mts +1 -1
  415. package/src/number/branded-types/positive-uint32.test.mts +1 -1
  416. package/src/number/branded-types/safe-int.test.mts +1 -1
  417. package/src/number/branded-types/safe-uint.test.mts +1 -1
  418. package/src/number/branded-types/uint.test.mts +1 -1
  419. package/src/number/branded-types/uint16.test.mts +1 -1
  420. package/src/number/branded-types/uint32.test.mts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"range.mjs","sources":["../../src/iterator/range.mts"],"sourcesContent":["import {\n type NonZeroSafeInt,\n type PositiveSafeInt,\n type SafeUint,\n type WithSmallInt,\n} from 'ts-type-forge';\nimport { SafeInt, asSafeInt } from '../number/index.mjs';\n\n/**\n * Generates a sequence of numbers within a specified range using a generator\n * function.\n *\n * This function creates a generator that yields numbers from `start`\n * (inclusive) to `end` (exclusive) with the specified `step`\n * increment/decrement. The function implements the JavaScript iterator\n * protocol, making it compatible with for-of loops, spread operator,\n * Array.from(), and other iterator consumers.\n *\n * The function has two overloaded signatures:\n *\n * 1. For non-negative ranges: accepts SafeUint parameters and optional positive\n * step\n * 2. For general ranges: accepts SafeInt parameters and optional non-zero step\n *\n * **Generator Behavior:**\n *\n * - Yields values lazily (computed on-demand)\n * - Returns `void` when iteration completes\n * - Does not accept sent values (next parameter is ignored)\n * - Automatically handles direction based on step sign and start/end relationship\n *\n * **Step Parameter Behavior:**\n *\n * - Positive step: iterates from start toward end (start < end expected)\n * - Negative step: iterates from start toward end (start > end expected)\n * - Zero step: not allowed (NonZeroSafeInt constraint)\n * - Default step: 1 (positive direction)\n *\n * **Edge Cases:**\n *\n * - When start equals end: yields no values (empty sequence)\n * - When step direction conflicts with start/end relationship: yields no values\n * - All parameters must be safe integers (within JavaScript's safe integer range)\n *\n * @example\n *\n * ```ts\n * const zeroToThree = Array.from(range(0, 3));\n *\n * const threeToZero = Array.from(range(3, 0, -1));\n *\n * const defaultEnd = Array.from(range(4));\n *\n * assert.deepStrictEqual(zeroToThree, [0, 1, 2]);\n *\n * assert.deepStrictEqual(threeToZero, [3, 2, 1]);\n *\n * assert.deepStrictEqual(defaultEnd, [0, 1, 2, 3]);\n * ```\n *\n * @template T - The specific SafeInt or SafeUint type being generated\n * @param start - The starting number of the sequence (inclusive). Must be a\n * safe integer.\n * @param end - The end number of the sequence (exclusive). Must be a safe\n * integer.\n * @param step - The increment or decrement value. Defaults to 1. Must be\n * non-zero safe integer.\n * @returns A Generator object that yields safe integers in the specified range.\n */\nexport function range(\n end: WithSmallInt<SafeUint, MaxInt>,\n): Generator<SafeUint, void, unknown>;\n\nexport function range(\n start: WithSmallInt<SafeUint, MaxInt>,\n end: WithSmallInt<SafeUint, MaxInt>,\n // eslint-disable-next-line @typescript-eslint/unified-signatures\n step?: WithSmallInt<PositiveSafeInt, MaxInt>,\n): Generator<SafeUint, void, unknown>;\n\nexport function range(\n start: WithSmallInt<SafeInt, MaxInt>,\n end: WithSmallInt<SafeInt, MaxInt>,\n step?: WithSmallInt<NonZeroSafeInt, MaxInt>,\n): Generator<SafeInt, void, unknown>;\n\nexport function* range(\n ...args:\n | readonly [end: WithSmallInt<SafeInt, MaxInt>]\n | readonly [\n start: WithSmallInt<SafeInt, MaxInt>,\n end: WithSmallInt<SafeInt, MaxInt>,\n step?: WithSmallInt<NonZeroSafeInt, MaxInt>,\n ]\n): Generator<SafeInt, void, unknown> {\n switch (args.length) {\n case 1: {\n const [end] = args;\n\n for (const i of range(0, end, 1)) {\n yield i;\n }\n\n break;\n }\n\n case 2:\n\n // falls through\n case 3: {\n const [start, end, step = 1] = args;\n\n for (\n let mut_i: SafeInt = asSafeInt(start);\n step > 0 ? mut_i < end : mut_i > end;\n mut_i = SafeInt.add(mut_i, asSafeInt(step))\n ) {\n yield mut_i;\n }\n }\n }\n}\n\ntype MaxInt = 512;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFO,UAAU,SACZ,IAAA,EAOgC;AACnC,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,GAAG,CAAA,GAAI,IAAA;AAEd,MAAA,KAAA,MAAW,CAAA,IAAK,KAAA,CAAM,CAAA,EAAG,GAAA,EAA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KAAK,GAAG,GAAG,EACpC,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,EAC3C,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -1,2 +1,2 @@
1
- export { Json } from './json.mjs';
2
- //# sourceMappingURL=index.mjs.map
1
+ export * from './json.mjs';
2
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/json/index.mts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
@@ -1,111 +1,352 @@
1
- import '../number/branded-types/finite-number.mjs';
2
- import '../number/branded-types/int.mjs';
3
- import '../number/branded-types/int16.mjs';
4
- import '../number/branded-types/int32.mjs';
5
- import '../number/branded-types/negative-finite-number.mjs';
6
- import '../number/branded-types/negative-int.mjs';
7
- import '../number/branded-types/negative-safe-int.mjs';
8
- import '../number/branded-types/non-negative-finite-number.mjs';
9
- import '../number/branded-types/non-negative-int16.mjs';
10
- import '../number/branded-types/non-negative-int32.mjs';
11
- import '../number/branded-types/non-positive-finite-number.mjs';
12
- import '../number/branded-types/non-positive-int.mjs';
13
- import '../number/branded-types/non-positive-safe-int.mjs';
14
- import '../number/branded-types/non-zero-finite-number.mjs';
15
- import '../number/branded-types/non-zero-int.mjs';
16
- import '../number/branded-types/non-zero-int16.mjs';
17
- import '../number/branded-types/non-zero-int32.mjs';
18
- import '../number/branded-types/non-zero-safe-int.mjs';
19
- import '../number/branded-types/non-zero-uint16.mjs';
20
- import '../number/branded-types/non-zero-uint32.mjs';
21
- import '../number/branded-types/positive-finite-number.mjs';
22
- import '../number/branded-types/positive-int.mjs';
23
- import '../number/branded-types/positive-int16.mjs';
24
- import '../number/branded-types/positive-int32.mjs';
25
- import '../number/branded-types/positive-safe-int.mjs';
26
- import '../number/branded-types/positive-uint16.mjs';
27
- import '../number/branded-types/positive-uint32.mjs';
28
- import '../number/branded-types/safe-int.mjs';
29
- import '../number/branded-types/safe-uint.mjs';
30
- import '../number/branded-types/uint.mjs';
31
- import '../number/branded-types/uint16.mjs';
32
- import '../number/branded-types/uint32.mjs';
33
- import '../number/enum/int8.mjs';
34
- import '../number/enum/uint8.mjs';
35
- import '../number/num.mjs';
36
- import '../number/refined-number-utils.mjs';
37
- import { err } from '../functional/result/impl/result-err.mjs';
38
- import { ok } from '../functional/result/impl/result-ok.mjs';
39
- import { isRecord } from '../guard/is-record.mjs';
40
- import '@sindresorhus/is';
41
- import { castMutable } from '../others/cast-mutable.mjs';
42
- import { unknownToString } from '../others/unknown-to-string.mjs';
43
- import { pipe } from '../functional/pipe.mjs';
44
- import '../collections/imap-mapped.mjs';
45
- import '../collections/imap.mjs';
46
- import '../collections/iset-mapped.mjs';
47
- import '../collections/iset.mjs';
48
- import { uniq } from '../array/impl/array-utils-transformation.mjs';
49
-
50
- var Json;
51
- ((Json2) => {
52
- Json2.parse = (text, reviver) => {
53
- try {
54
- return ok(
55
- JSON.parse(
56
- text,
57
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
58
- reviver
59
- )
60
- );
61
- } catch (error) {
62
- const errStr = unknownToString(error);
63
- return err(errStr);
64
- }
65
- };
66
- Json2.stringify = (value, replacer, space) => {
67
- try {
68
- return ok(JSON.stringify(value, replacer, space));
69
- } catch (error) {
70
- const errStr = unknownToString(error);
71
- return err(errStr);
72
- }
73
- };
74
- Json2.stringifySelected = (value, propertiesToBeSelected, space) => {
75
- try {
76
- return ok(
77
- JSON.stringify(value, castMutable(propertiesToBeSelected), space)
78
- );
79
- } catch (error) {
80
- const errStr = unknownToString(error);
81
- return err(errStr);
82
- }
83
- };
84
- Json2.stringifySortedKey = (value, space) => {
85
- const allKeys = pipe(keysDeep(value)).map(uniq).map((ks) => ks.toSorted()).value;
86
- return (0, Json2.stringifySelected)(value, allKeys, space);
87
- };
1
+ import { Arr } from '../array/index.mjs';
2
+ import { pipe, Result } from '../functional/index.mjs';
3
+ import { isRecord } from '../guard/index.mjs';
4
+ import { unknownToString } from '../others/index.mjs';
5
+
6
+
7
+
8
+
9
+
10
+ export var Json;
11
+ (function (Json) {
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+ Json.parse = (text, reviver) => {
66
+ try {
67
+ return Result.ok(JSON.parse(text,
68
+
69
+ reviver));
70
+ }
71
+ catch (error) {
72
+ const errStr = unknownToString(error);
73
+ return Result.err(errStr);
74
+ }
75
+ };
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+ Json.stringify = (value, replacer, space) => {
141
+ try {
142
+ return Result.ok(JSON.stringify(value, replacer, space));
143
+ }
144
+ catch (error) {
145
+ const errStr = unknownToString(error);
146
+ return Result.err(errStr);
147
+ }
148
+ };
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+ Json.stringifySelected = (value, propertiesToBeSelected, space) => {
215
+ try {
216
+ return Result.ok(JSON.stringify(value, propertiesToBeSelected, space));
217
+ }
218
+ catch (error) {
219
+ const errStr = unknownToString(error);
220
+ return Result.err(errStr);
221
+ }
222
+ };
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+
299
+
300
+ Json.stringifySortedKey = (value, space) => {
301
+ const allKeys = pipe(keysDeep(value))
302
+ .map(Arr.uniq)
303
+ .map((ks) => ks.toSorted()).value;
304
+ return Json.stringifySelected(value, allKeys, space);
305
+ };
88
306
  })(Json || (Json = {}));
89
- const keysDeepImpl = (obj, mut_keys) => {
90
- for (const [k, v] of Object.entries(obj)) {
91
- mut_keys.push(k);
92
- if (isRecord(v)) {
93
- keysDeepImpl(v, mut_keys);
94
- }
95
- if (Array.isArray(v)) {
96
- for (const li of v) {
97
- if (isRecord(li)) {
98
- keysDeepImpl(li, mut_keys);
307
+
308
+
309
+
310
+
311
+
312
+
313
+
314
+
315
+
316
+
317
+
318
+ const keysDeepImpl = (obj,
319
+
320
+ mut_keys) => {
321
+ for (const [k, v] of Object.entries(obj)) {
322
+ mut_keys.push(k);
323
+ if (isRecord(v)) {
324
+ keysDeepImpl(v, mut_keys);
325
+ }
326
+ if (Array.isArray(v)) {
327
+ for (const li of v) {
328
+ if (isRecord(li)) {
329
+ keysDeepImpl(li, mut_keys);
330
+ }
331
+ }
99
332
  }
100
- }
101
333
  }
102
- }
103
334
  };
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+
104
347
  const keysDeep = (obj) => {
105
- const mut_keys = [];
106
- keysDeepImpl(obj, mut_keys);
107
- return mut_keys;
348
+ const mut_keys = [];
349
+ keysDeepImpl(obj, mut_keys);
350
+ return mut_keys;
108
351
  };
109
-
110
- export { Json };
111
- //# sourceMappingURL=json.mjs.map
352
+ //# sourceMappingURL=json.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"json.mjs","sources":["../../src/json/json.mts"],"sourcesContent":["import {\n type JsonValue,\n type UintRangeInclusive,\n type UnknownRecord,\n} from 'ts-type-forge';\nimport { Arr } from '../array/index.mjs';\nimport { pipe, Result } from '../functional/index.mjs';\nimport { isRecord } from '../guard/index.mjs';\nimport { castMutable, unknownToString } from '../others/index.mjs';\n\n/**\n * A collection of type-safe JSON utility functions that provide safe parsing,\n * stringification, and manipulation of JSON data. All functions return `Result`\n * types to handle errors without throwing exceptions.\n */\nexport namespace Json {\n /**\n * Safely converts a JSON string into a JavaScript value without throwing\n * exceptions.\n *\n * This function provides type-safe JSON parsing by wrapping the native\n * `JSON.parse` in a `Result` type, allowing you to handle parsing errors\n * gracefully without try-catch blocks.\n *\n * @example\n *\n * ```ts\n * const validJson = '{\"name\": \"Alice\", \"age\": 30}';\n *\n * const invalidJson = '{invalid json}';\n *\n * const parsed = Json.parse(validJson);\n *\n * const failed = Json.parse(invalidJson);\n *\n * assert.isTrue(Result.isOk(parsed));\n *\n * if (Result.isOk(parsed)) {\n * assert.deepStrictEqual(parsed.value, { name: 'Alice', age: 30 });\n * }\n *\n * assert.isTrue(Result.isErr(failed));\n *\n * // With reviver\n * const jsonWithDate = '{\"created\": \"2024-01-01T00:00:00.000Z\"}';\n *\n * const withReviver = Json.parse(jsonWithDate, (key, value) => {\n * if (key === 'created' && typeof value === 'string') {\n * return new Date(value);\n * }\n *\n * return value;\n * });\n *\n * assert.isTrue(Result.isOk(withReviver));\n * ```\n *\n * @param text - A valid JSON string to parse. Can contain any valid JSON data\n * type: primitives (string, number, boolean, null), arrays, or objects.\n * @param reviver - Optional function that transforms parsed values. Called\n * for each key-value pair in the JSON. The function receives the key name\n * and parsed value, and should return the transformed value. For nested\n * objects, inner objects are processed before outer objects.\n * @returns A `Result<JsonValue, string>` containing:\n *\n * - On success: `Result.ok(parsedValue)` where `parsedValue` is the parsed JSON\n * - On failure: `Result.err(errorMessage)` where `errorMessage` describes the\n * parsing error\n */\n export const parse = (\n text: string,\n reviver?: (this: unknown, key: string, value: JsonValue) => unknown,\n ): Result<JsonValue, string> => {\n try {\n return Result.ok(\n JSON.parse(\n text,\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n reviver as (this: unknown, key: string, value: unknown) => unknown,\n ),\n );\n } catch (error: unknown) {\n const errStr = unknownToString(error);\n\n return Result.err(errStr);\n }\n };\n\n /**\n * Safely converts a JavaScript value to a JSON string without throwing\n * exceptions.\n *\n * This function provides type-safe JSON stringification by wrapping the\n * native `JSON.stringify` in a `Result` type, allowing you to handle\n * serialization errors gracefully (such as circular references or BigInt\n * values).\n *\n * @example\n *\n * ```ts\n * const data = { name: 'Bob', age: 25, active: true } as const;\n *\n * // Basic stringify\n * const basic = Json.stringify(data);\n *\n * assert.isTrue(Result.isOk(basic));\n *\n * if (Result.isOk(basic)) {\n * assert.isTrue(basic.value === '{\"name\":\"Bob\",\"age\":25,\"active\":true}');\n * }\n *\n * // With formatting\n * const formatted = Json.stringify(data, undefined, 2);\n *\n * assert.isTrue(Result.isOk(formatted));\n *\n * // With replacer\n * const filtered = Json.stringify(data, (key, value) => {\n * if (key === 'age') return undefined; // omit age field\n *\n * return value;\n * });\n *\n * assert.isTrue(Result.isOk(filtered));\n *\n * if (Result.isOk(filtered)) {\n * assert.isTrue(isString(filtered.value));\n *\n * assert.isFalse(filtered.value.includes('age'));\n * }\n * ```\n *\n * @param value - The JavaScript value to serialize. Can be any value that\n * JSON.stringify accepts: primitives, objects, arrays. Non-serializable\n * values (functions, undefined, symbols) will be omitted or converted to\n * null according to JSON.stringify behavior.\n * @param replacer - Optional function that transforms values during\n * serialization. Called for each key-value pair. Should return the value to\n * be serialized, or undefined to omit the property from the result.\n * @param space - Optional parameter for formatting the output JSON:\n *\n * - Number (1-10): Number of spaces to indent each level\n * - String: String to use for indentation (first 10 characters)\n * - Undefined/null: No formatting (compact output)\n *\n * @returns A `Result<string, string>` containing:\n *\n * - On success: `Result.ok(jsonString)` where `jsonString` is the serialized\n * JSON\n * - On failure: `Result.err(errorMessage)` where `errorMessage` describes the\n * error\n */\n export const stringify = (\n value: unknown,\n replacer?: (this: unknown, key: string, val: unknown) => unknown,\n space?: UintRangeInclusive<1, 10> | string,\n ): Result<string | undefined, string> => {\n try {\n return Result.ok(JSON.stringify(value, replacer, space));\n } catch (error) {\n const errStr = unknownToString(error);\n\n return Result.err(errStr);\n }\n };\n\n /**\n * Safely converts a JavaScript value to a JSON string, including only the\n * specified properties.\n *\n * This function provides selective serialization by allowing you to specify\n * exactly which object properties should be included in the resulting JSON.\n * It's useful for creating filtered or minimal representations of objects,\n * such as for API responses or logging.\n *\n * @example\n *\n * ```ts\n * const user = {\n * id: 1,\n * name: 'Charlie',\n * email: 'charlie@example.com',\n * password: 'secret123',\n * role: 'admin',\n * } as const;\n *\n * // Select only safe properties to serialize\n * const safeJson = Json.stringifySelected(user, ['id', 'name', 'role']);\n *\n * assert.isTrue(Result.isOk(safeJson));\n *\n * if (Result.isOk(safeJson)) {\n * assert.isTrue(isString(safeJson.value));\n *\n * const parsed: unknown = JSON.parse(safeJson.value);\n *\n * assert.deepStrictEqual(parsed, {\n * id: 1,\n * name: 'Charlie',\n * role: 'admin',\n * });\n *\n * assert.isFalse(safeJson.value.includes('password'));\n *\n * assert.isFalse(safeJson.value.includes('email'));\n * }\n *\n * // With formatting\n * const formatted = Json.stringifySelected(user, ['id', 'name'], 2);\n *\n * assert.isTrue(Result.isOk(formatted));\n * ```\n *\n * @param value - The JavaScript value to serialize. While any value is\n * accepted, the property filtering only applies to objects and nested\n * objects.\n * @param propertiesToBeSelected - Optional array of property names (strings)\n * and array indices (numbers) to include in the serialization. If provided,\n * only these properties will appear in the output JSON. If undefined, all\n * properties are included.\n * @param space - Optional formatting parameter:\n *\n * - Number (1-10): Number of spaces to indent each level\n * - String: String to use for indentation (first 10 characters)\n * - Undefined/null: No formatting (compact output)\n *\n * @returns A `Result<string, string>` containing:\n *\n * - On success: `Result.ok(jsonString)` with only selected properties\n * - On failure: `Result.err(errorMessage)` describing the serialization error\n */\n export const stringifySelected = (\n value: unknown,\n propertiesToBeSelected?: readonly (number | string)[],\n space?: UintRangeInclusive<1, 10> | string,\n ): Result<string | undefined, string> => {\n try {\n return Result.ok(\n JSON.stringify(value, castMutable(propertiesToBeSelected), space),\n );\n } catch (error) {\n const errStr = unknownToString(error);\n\n return Result.err(errStr);\n }\n };\n\n /**\n * Safely converts a JavaScript record to a JSON string with keys sorted\n * alphabetically at all levels.\n *\n * This function creates deterministic JSON output by ensuring that object\n * keys appear in alphabetical order at every level of nesting. This is\n * particularly useful for creating consistent output for comparison, hashing,\n * caching, or when you need reproducible JSON representations across\n * different JavaScript engines or runs.\n *\n * @example\n *\n * ```ts\n * const unorderedData = {\n * zebra: 1,\n * apple: 2,\n * mango: 3,\n * nested: {\n * zulu: 'z',\n * alpha: 'a',\n * beta: 'b',\n * },\n * } as const;\n *\n * // Keys will be sorted alphabetically at all levels\n * const sorted = Json.stringifySortedKey(unorderedData);\n *\n * assert.isTrue(Result.isOk(sorted));\n *\n * if (Result.isOk(sorted)) {\n * // Keys should appear in alphabetical order\n * const expected =\n * '{\"apple\":2,\"mango\":3,\"nested\":{\"alpha\":\"a\",\"beta\":\"b\",\"zulu\":\"z\"},\"zebra\":1}';\n *\n * assert.isTrue(sorted.value === expected);\n * }\n *\n * // With formatting\n * const formatted = Json.stringifySortedKey(unorderedData, 2);\n *\n * assert.isTrue(Result.isOk(formatted));\n *\n * if (Result.isOk(formatted)) {\n * assert.isTrue(isString(formatted.value));\n *\n * // Check that keys are in order (first key should be \"apple\")\n * assert.isTrue(\n * formatted.value.indexOf('\"apple\"') < formatted.value.indexOf('\"mango\"'),\n * );\n *\n * assert.isTrue(\n * formatted.value.indexOf('\"mango\"') <\n * formatted.value.indexOf('\"nested\"'),\n * );\n *\n * assert.isTrue(\n * formatted.value.indexOf('\"nested\"') <\n * formatted.value.indexOf('\"zebra\"'),\n * );\n * }\n * ```\n *\n * @param value - An object (`UnknownRecord`) to serialize. Must be a plain\n * object (not an array, primitive, or null). Nested objects and arrays\n * within the object will also have their keys sorted alphabetically.\n * @param space - Optional formatting parameter:\n *\n * - Number (1-10): Number of spaces to indent each level\n * - String: String to use for indentation (first 10 characters)\n * - Undefined/null: No formatting (compact output)\n *\n * @returns A `Result<string, string>` containing:\n *\n * - On success: `Result.ok(jsonString)` with all object keys sorted\n * alphabetically\n * - On failure: `Result.err(errorMessage)` describing the serialization error\n */\n export const stringifySortedKey = (\n value: UnknownRecord,\n space?: UintRangeInclusive<1, 10> | string,\n ): Result<string | undefined, string> => {\n const allKeys = pipe(keysDeep(value))\n .map(Arr.uniq)\n .map((ks) => ks.toSorted()).value;\n\n return stringifySelected(value, allKeys, space);\n };\n}\n\n/**\n * @param obj - The record to extract keys from. Must be a plain object.\n * @param mut_keys - A mutable array to accumulate the collected keys. This\n * array will be modified in-place by the function for performance reasons.\n * @internal\n * Recursively collects all property keys from a nested object structure.\n *\n * This helper function traverses an object and its nested objects and arrays,\n * collecting all string keys found at any level of nesting. The function mutates\n * the provided keys array for performance reasons.\n */\nconst keysDeepImpl = (\n obj: UnknownRecord,\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n mut_keys: string[],\n): void => {\n for (const [k, v] of Object.entries(obj)) {\n mut_keys.push(k);\n\n if (isRecord(v)) {\n keysDeepImpl(v, mut_keys);\n }\n\n if (Array.isArray(v)) {\n for (const li of v) {\n if (isRecord(li)) {\n keysDeepImpl(li, mut_keys);\n }\n }\n }\n }\n};\n\n/**\n * @param obj - The record to extract keys from. Must be a plain object.\n * @returns A readonly array of all string keys found in the object and its\n * nested objects/arrays. May contain duplicates if the same key appears at\n * multiple levels.\n * @internal\n * Extracts all property keys from a nested object structure into a flat array.\n *\n * This function serves as a safe wrapper around `keysDeepImpl`, creating a new\n * mutable array and passing it to the recursive implementation. The result\n * contains all keys found at any level of nesting within the input object.\n */\nconst keysDeep = (obj: UnknownRecord): readonly string[] => {\n const mut_keys: string[] = [];\n\n keysDeepImpl(obj, mut_keys);\n\n return mut_keys;\n};\n"],"names":["Json","Result.ok","Result.err","Arr.uniq"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeO,IAAU;AAAA,CAAV,CAAUA,KAAAA,KAAV;AAsDE,EAAMA,KAAAA,CAAA,KAAA,GAAQ,CACnB,IAAA,EACA,OAAA,KAC8B;AAC9B,IAAA,IAAI;AACF,MAAA,OAAOC,EAAO;AAAA,QACZ,IAAA,CAAK,KAAA;AAAA,UACH,IAAA;AAAA;AAAA,UAEA;AAAA;AACF,OACF;AAAA,IACF,SAAS,KAAA,EAAgB;AACvB,MAAA,MAAM,MAAA,GAAS,gBAAgB,KAAK,CAAA;AAEpC,MAAA,OAAOC,IAAW,MAAM,CAAA;AAAA,IAC1B;AAAA,EACF,CAAA;AAkEO,EAAMF,KAAAA,CAAA,SAAA,GAAY,CACvB,KAAA,EACA,UACA,KAAA,KACuC;AACvC,IAAA,IAAI;AACF,MAAA,OAAOC,EAAO,CAAG,IAAA,CAAK,UAAU,KAAA,EAAO,QAAA,EAAU,KAAK,CAAC,CAAA;AAAA,IACzD,SAAS,KAAA,EAAO;AACd,MAAA,MAAM,MAAA,GAAS,gBAAgB,KAAK,CAAA;AAEpC,MAAA,OAA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