ts-data-forge 14.6.1 → 14.6.2

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 (393) 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 +69 -53
  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 +71 -33
  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 +100 -150
  18. package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
  19. package/dist/array/impl/array-utils-search.mjs +110 -134
  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 +94 -78
  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 +54 -56
  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 +183 -151
  48. package/dist/collections/queue.mjs.map +1 -1
  49. package/dist/collections/stack.mjs +169 -140
  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 +70 -4
  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 +19 -21
  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 +16 -19
  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 +16 -19
  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 +36 -9
  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 +16 -18
  82. package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +1 -1
  83. package/dist/functional/optional/impl/optional-filter.mjs +17 -19
  84. package/dist/functional/optional/impl/optional-filter.mjs.map +1 -1
  85. package/dist/functional/optional/impl/optional-flat-map.mjs +13 -15
  86. package/dist/functional/optional/impl/optional-flat-map.mjs.map +1 -1
  87. package/dist/functional/optional/impl/optional-from-nullable.mjs +26 -5
  88. package/dist/functional/optional/impl/optional-from-nullable.mjs.map +1 -1
  89. package/dist/functional/optional/impl/optional-is-none.mjs +21 -5
  90. package/dist/functional/optional/impl/optional-is-none.mjs.map +1 -1
  91. package/dist/functional/optional/impl/optional-is-optional.mjs +26 -8
  92. package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
  93. package/dist/functional/optional/impl/optional-is-some.mjs +22 -5
  94. package/dist/functional/optional/impl/optional-is-some.mjs.map +1 -1
  95. package/dist/functional/optional/impl/optional-map.mjs +16 -18
  96. package/dist/functional/optional/impl/optional-map.mjs.map +1 -1
  97. package/dist/functional/optional/impl/optional-match.mjs +16 -18
  98. package/dist/functional/optional/impl/optional-match.mjs.map +1 -1
  99. package/dist/functional/optional/impl/optional-none.mjs +18 -5
  100. package/dist/functional/optional/impl/optional-none.mjs.map +1 -1
  101. package/dist/functional/optional/impl/optional-or-else.mjs +13 -15
  102. package/dist/functional/optional/impl/optional-or-else.mjs.map +1 -1
  103. package/dist/functional/optional/impl/optional-some.mjs +23 -7
  104. package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
  105. package/dist/functional/optional/impl/optional-to-nullable.mjs +28 -5
  106. package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
  107. package/dist/functional/optional/impl/optional-unwrap-or.mjs +12 -14
  108. package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +1 -1
  109. package/dist/functional/optional/impl/optional-unwrap-throw.mjs +34 -9
  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 +36 -5
  114. package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
  115. package/dist/functional/optional/impl/tag.mjs +4 -5
  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 +29 -7
  128. package/dist/functional/result/impl/result-err.mjs.map +1 -1
  129. package/dist/functional/result/impl/result-expect-to-be.mjs +17 -18
  130. package/dist/functional/result/impl/result-expect-to-be.mjs.map +1 -1
  131. package/dist/functional/result/impl/result-flat-map.mjs +18 -21
  132. package/dist/functional/result/impl/result-flat-map.mjs.map +1 -1
  133. package/dist/functional/result/impl/result-fold.mjs +18 -21
  134. package/dist/functional/result/impl/result-fold.mjs.map +1 -1
  135. package/dist/functional/result/impl/result-from-optional.mjs +17 -20
  136. package/dist/functional/result/impl/result-from-optional.mjs.map +1 -1
  137. package/dist/functional/result/impl/result-from-promise.mjs +37 -8
  138. package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
  139. package/dist/functional/result/impl/result-from-throwable.mjs +41 -14
  140. package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
  141. package/dist/functional/result/impl/result-is-err.mjs +21 -5
  142. package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
  143. package/dist/functional/result/impl/result-is-ok.mjs +21 -5
  144. package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
  145. package/dist/functional/result/impl/result-is-result.mjs +25 -7
  146. package/dist/functional/result/impl/result-is-result.mjs.map +1 -1
  147. package/dist/functional/result/impl/result-map-err.mjs +18 -21
  148. package/dist/functional/result/impl/result-map-err.mjs.map +1 -1
  149. package/dist/functional/result/impl/result-map.mjs +18 -21
  150. package/dist/functional/result/impl/result-map.mjs.map +1 -1
  151. package/dist/functional/result/impl/result-match.mjs +17 -21
  152. package/dist/functional/result/impl/result-match.mjs.map +1 -1
  153. package/dist/functional/result/impl/result-ok.mjs +29 -7
  154. package/dist/functional/result/impl/result-ok.mjs.map +1 -1
  155. package/dist/functional/result/impl/result-or-else.mjs +14 -15
  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 +40 -12
  160. package/dist/functional/result/impl/result-safe-unwrap.mjs.map +1 -1
  161. package/dist/functional/result/impl/result-swap.mjs +23 -8
  162. package/dist/functional/result/impl/result-swap.mjs.map +1 -1
  163. package/dist/functional/result/impl/result-to-optional.mjs +30 -7
  164. package/dist/functional/result/impl/result-to-optional.mjs.map +1 -1
  165. package/dist/functional/result/impl/result-unwrap-err-or.mjs +13 -14
  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 +43 -20
  168. package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
  169. package/dist/functional/result/impl/result-unwrap-err.mjs +33 -8
  170. package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
  171. package/dist/functional/result/impl/result-unwrap-ok-or.mjs +13 -14
  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 +38 -11
  176. package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
  177. package/dist/functional/result/impl/result-zip.mjs +35 -5
  178. package/dist/functional/result/impl/result-zip.mjs.map +1 -1
  179. package/dist/functional/result/impl/tag.mjs +4 -5
  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 +6 -6
  190. package/dist/functional/ternary-result/impl/tag.mjs.map +1 -1
  191. package/dist/functional/ternary-result/impl/ternary-result-err.mjs +17 -7
  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 +28 -32
  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 +21 -8
  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 +28 -13
  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 +19 -5
  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 +21 -5
  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 +28 -8
  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 +20 -5
  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 +18 -7
  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 +24 -10
  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 +30 -19
  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 +20 -8
  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 +7 -9
  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 +30 -22
  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 +27 -17
  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 +20 -8
  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 +21 -8
  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 +47 -19
  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 +12 -14
  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 +43 -4
  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 +39 -4
  258. package/dist/guard/is-non-empty-string.mjs.map +1 -1
  259. package/dist/guard/is-non-null-object.mjs +36 -4
  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 +89 -6
  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 +42 -4
  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 +19 -57
  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 +122 -108
  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 +292 -258
  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 +284 -255
  336. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  337. package/dist/number/branded-types/safe-uint.mjs +135 -124
  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 +541 -83
  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 +355 -202
  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 +32 -5
  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 +52 -4
  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 +51 -10
  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 +3 -2
  392. package/dist/types.mjs.map +1 -1
  393. package/package.json +5 -6
@@ -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
+ * A collection of type-safe JSON utility functions that provide safe parsing,
7
+ * stringification, and manipulation of JSON data. All functions return `Result`
8
+ * types to handle errors without throwing exceptions.
9
+ */
10
+ export var Json;
11
+ (function (Json) {
12
+ /**
13
+ * Safely converts a JSON string into a JavaScript value without throwing
14
+ * exceptions.
15
+ *
16
+ * This function provides type-safe JSON parsing by wrapping the native
17
+ * `JSON.parse` in a `Result` type, allowing you to handle parsing errors
18
+ * gracefully without try-catch blocks.
19
+ *
20
+ * @example
21
+ *
22
+ * ```ts
23
+ * const validJson = '{"name": "Alice", "age": 30}';
24
+ *
25
+ * const invalidJson = '{invalid json}';
26
+ *
27
+ * const parsed = Json.parse(validJson);
28
+ *
29
+ * const failed = Json.parse(invalidJson);
30
+ *
31
+ * assert.isTrue(Result.isOk(parsed));
32
+ *
33
+ * if (Result.isOk(parsed)) {
34
+ * assert.deepStrictEqual(parsed.value, { name: 'Alice', age: 30 });
35
+ * }
36
+ *
37
+ * assert.isTrue(Result.isErr(failed));
38
+ *
39
+ * // With reviver
40
+ * const jsonWithDate = '{"created": "2024-01-01T00:00:00.000Z"}';
41
+ *
42
+ * const withReviver = Json.parse(jsonWithDate, (key, value) => {
43
+ * if (key === 'created' && typeof value === 'string') {
44
+ * return new Date(value);
45
+ * }
46
+ *
47
+ * return value;
48
+ * });
49
+ *
50
+ * assert.isTrue(Result.isOk(withReviver));
51
+ * ```
52
+ *
53
+ * @param text - A valid JSON string to parse. Can contain any valid JSON data
54
+ * type: primitives (string, number, boolean, null), arrays, or objects.
55
+ * @param reviver - Optional function that transforms parsed values. Called
56
+ * for each key-value pair in the JSON. The function receives the key name
57
+ * and parsed value, and should return the transformed value. For nested
58
+ * objects, inner objects are processed before outer objects.
59
+ * @returns A `Result<JsonValue, string>` containing:
60
+ *
61
+ * - On success: `Result.ok(parsedValue)` where `parsedValue` is the parsed JSON
62
+ * - On failure: `Result.err(errorMessage)` where `errorMessage` describes the
63
+ * parsing error
64
+ */
65
+ Json.parse = (text, reviver) => {
66
+ try {
67
+ return Result.ok(JSON.parse(text,
68
+ // eslint-disable-next-line total-functions/no-unsafe-type-assertion
69
+ reviver));
70
+ }
71
+ catch (error) {
72
+ const errStr = unknownToString(error);
73
+ return Result.err(errStr);
74
+ }
75
+ };
76
+ /**
77
+ * Safely converts a JavaScript value to a JSON string without throwing
78
+ * exceptions.
79
+ *
80
+ * This function provides type-safe JSON stringification by wrapping the
81
+ * native `JSON.stringify` in a `Result` type, allowing you to handle
82
+ * serialization errors gracefully (such as circular references or BigInt
83
+ * values).
84
+ *
85
+ * @example
86
+ *
87
+ * ```ts
88
+ * const data = { name: 'Bob', age: 25, active: true } as const;
89
+ *
90
+ * // Basic stringify
91
+ * const basic = Json.stringify(data);
92
+ *
93
+ * assert.isTrue(Result.isOk(basic));
94
+ *
95
+ * if (Result.isOk(basic)) {
96
+ * assert.isTrue(basic.value === '{"name":"Bob","age":25,"active":true}');
97
+ * }
98
+ *
99
+ * // With formatting
100
+ * const formatted = Json.stringify(data, undefined, 2);
101
+ *
102
+ * assert.isTrue(Result.isOk(formatted));
103
+ *
104
+ * // With replacer
105
+ * const filtered = Json.stringify(data, (key, value) => {
106
+ * if (key === 'age') return undefined; // omit age field
107
+ *
108
+ * return value;
109
+ * });
110
+ *
111
+ * assert.isTrue(Result.isOk(filtered));
112
+ *
113
+ * if (Result.isOk(filtered)) {
114
+ * assert.isTrue(isString(filtered.value));
115
+ *
116
+ * assert.isFalse(filtered.value.includes('age'));
117
+ * }
118
+ * ```
119
+ *
120
+ * @param value - The JavaScript value to serialize. Can be any value that
121
+ * JSON.stringify accepts: primitives, objects, arrays. Non-serializable
122
+ * values (functions, undefined, symbols) will be omitted or converted to
123
+ * null according to JSON.stringify behavior.
124
+ * @param replacer - Optional function that transforms values during
125
+ * serialization. Called for each key-value pair. Should return the value to
126
+ * be serialized, or undefined to omit the property from the result.
127
+ * @param space - Optional parameter for formatting the output JSON:
128
+ *
129
+ * - Number (1-10): Number of spaces to indent each level
130
+ * - String: String to use for indentation (first 10 characters)
131
+ * - Undefined/null: No formatting (compact output)
132
+ *
133
+ * @returns A `Result<string, string>` containing:
134
+ *
135
+ * - On success: `Result.ok(jsonString)` where `jsonString` is the serialized
136
+ * JSON
137
+ * - On failure: `Result.err(errorMessage)` where `errorMessage` describes the
138
+ * error
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
+ * Safely converts a JavaScript value to a JSON string, including only the
151
+ * specified properties.
152
+ *
153
+ * This function provides selective serialization by allowing you to specify
154
+ * exactly which object properties should be included in the resulting JSON.
155
+ * It's useful for creating filtered or minimal representations of objects,
156
+ * such as for API responses or logging.
157
+ *
158
+ * @example
159
+ *
160
+ * ```ts
161
+ * const user = {
162
+ * id: 1,
163
+ * name: 'Charlie',
164
+ * email: 'charlie@example.com',
165
+ * password: 'secret123',
166
+ * role: 'admin',
167
+ * } as const;
168
+ *
169
+ * // Select only safe properties to serialize
170
+ * const safeJson = Json.stringifySelected(user, ['id', 'name', 'role']);
171
+ *
172
+ * assert.isTrue(Result.isOk(safeJson));
173
+ *
174
+ * if (Result.isOk(safeJson)) {
175
+ * assert.isTrue(isString(safeJson.value));
176
+ *
177
+ * const parsed: unknown = JSON.parse(safeJson.value);
178
+ *
179
+ * assert.deepStrictEqual(parsed, {
180
+ * id: 1,
181
+ * name: 'Charlie',
182
+ * role: 'admin',
183
+ * });
184
+ *
185
+ * assert.isFalse(safeJson.value.includes('password'));
186
+ *
187
+ * assert.isFalse(safeJson.value.includes('email'));
188
+ * }
189
+ *
190
+ * // With formatting
191
+ * const formatted = Json.stringifySelected(user, ['id', 'name'], 2);
192
+ *
193
+ * assert.isTrue(Result.isOk(formatted));
194
+ * ```
195
+ *
196
+ * @param value - The JavaScript value to serialize. While any value is
197
+ * accepted, the property filtering only applies to objects and nested
198
+ * objects.
199
+ * @param propertiesToBeSelected - Optional array of property names (strings)
200
+ * and array indices (numbers) to include in the serialization. If provided,
201
+ * only these properties will appear in the output JSON. If undefined, all
202
+ * properties are included.
203
+ * @param space - Optional formatting parameter:
204
+ *
205
+ * - Number (1-10): Number of spaces to indent each level
206
+ * - String: String to use for indentation (first 10 characters)
207
+ * - Undefined/null: No formatting (compact output)
208
+ *
209
+ * @returns A `Result<string, string>` containing:
210
+ *
211
+ * - On success: `Result.ok(jsonString)` with only selected properties
212
+ * - On failure: `Result.err(errorMessage)` describing the serialization error
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
+ * Safely converts a JavaScript record to a JSON string with keys sorted
225
+ * alphabetically at all levels.
226
+ *
227
+ * This function creates deterministic JSON output by ensuring that object
228
+ * keys appear in alphabetical order at every level of nesting. This is
229
+ * particularly useful for creating consistent output for comparison, hashing,
230
+ * caching, or when you need reproducible JSON representations across
231
+ * different JavaScript engines or runs.
232
+ *
233
+ * @example
234
+ *
235
+ * ```ts
236
+ * const unorderedData = {
237
+ * zebra: 1,
238
+ * apple: 2,
239
+ * mango: 3,
240
+ * nested: {
241
+ * zulu: 'z',
242
+ * alpha: 'a',
243
+ * beta: 'b',
244
+ * },
245
+ * } as const;
246
+ *
247
+ * // Keys will be sorted alphabetically at all levels
248
+ * const sorted = Json.stringifySortedKey(unorderedData);
249
+ *
250
+ * assert.isTrue(Result.isOk(sorted));
251
+ *
252
+ * if (Result.isOk(sorted)) {
253
+ * // Keys should appear in alphabetical order
254
+ * const expected =
255
+ * '{"apple":2,"mango":3,"nested":{"alpha":"a","beta":"b","zulu":"z"},"zebra":1}';
256
+ *
257
+ * assert.isTrue(sorted.value === expected);
258
+ * }
259
+ *
260
+ * // With formatting
261
+ * const formatted = Json.stringifySortedKey(unorderedData, 2);
262
+ *
263
+ * assert.isTrue(Result.isOk(formatted));
264
+ *
265
+ * if (Result.isOk(formatted)) {
266
+ * assert.isTrue(isString(formatted.value));
267
+ *
268
+ * // Check that keys are in order (first key should be "apple")
269
+ * assert.isTrue(
270
+ * formatted.value.indexOf('"apple"') < formatted.value.indexOf('"mango"'),
271
+ * );
272
+ *
273
+ * assert.isTrue(
274
+ * formatted.value.indexOf('"mango"') <
275
+ * formatted.value.indexOf('"nested"'),
276
+ * );
277
+ *
278
+ * assert.isTrue(
279
+ * formatted.value.indexOf('"nested"') <
280
+ * formatted.value.indexOf('"zebra"'),
281
+ * );
282
+ * }
283
+ * ```
284
+ *
285
+ * @param value - An object (`UnknownRecord`) to serialize. Must be a plain
286
+ * object (not an array, primitive, or null). Nested objects and arrays
287
+ * within the object will also have their keys sorted alphabetically.
288
+ * @param space - Optional formatting parameter:
289
+ *
290
+ * - Number (1-10): Number of spaces to indent each level
291
+ * - String: String to use for indentation (first 10 characters)
292
+ * - Undefined/null: No formatting (compact output)
293
+ *
294
+ * @returns A `Result<string, string>` containing:
295
+ *
296
+ * - On success: `Result.ok(jsonString)` with all object keys sorted
297
+ * alphabetically
298
+ * - On failure: `Result.err(errorMessage)` describing the serialization error
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
+ * @param obj - The record to extract keys from. Must be a plain object.
309
+ * @param mut_keys - A mutable array to accumulate the collected keys. This
310
+ * array will be modified in-place by the function for performance reasons.
311
+ * @internal
312
+ * Recursively collects all property keys from a nested object structure.
313
+ *
314
+ * This helper function traverses an object and its nested objects and arrays,
315
+ * collecting all string keys found at any level of nesting. The function mutates
316
+ * the provided keys array for performance reasons.
317
+ */
318
+ const keysDeepImpl = (obj,
319
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
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
+ * @param obj - The record to extract keys from. Must be a plain object.
337
+ * @returns A readonly array of all string keys found in the object and its
338
+ * nested objects/arrays. May contain duplicates if the same key appears at
339
+ * multiple levels.
340
+ * @internal
341
+ * Extracts all property keys from a nested object structure into a flat array.
342
+ *
343
+ * This function serves as a safe wrapper around `keysDeepImpl`, creating a new
344
+ * mutable array and passing it to the recursive implementation. The result
345
+ * contains all keys found at any level of nesting within the input object.
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,KAA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