@kdtlabs/utils 0.0.4 → 0.0.5

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 (447) hide show
  1. package/SKILL.md +7 -9
  2. package/{common → dist/common}/assertions.d.ts +1 -1
  3. package/{common → dist/common}/assertions.d.ts.map +1 -1
  4. package/{common → dist/common}/types.d.ts +1 -1
  5. package/{common → dist/common}/types.d.ts.map +1 -1
  6. package/{functions → dist/functions}/executions.d.ts +1 -1
  7. package/{functions → dist/functions}/executions.d.ts.map +1 -1
  8. package/dist/index.js +7 -0
  9. package/dist/index.js.map +99 -0
  10. package/{objects → dist/objects}/transformations.d.ts +1 -1
  11. package/{objects → dist/objects}/transformations.d.ts.map +1 -1
  12. package/{objects → dist/objects}/types.d.ts +1 -1
  13. package/{objects → dist/objects}/types.d.ts.map +1 -1
  14. package/{promises → dist/promises}/deferred.d.ts +1 -1
  15. package/{promises → dist/promises}/deferred.d.ts.map +1 -1
  16. package/{promises → dist/promises}/timers.d.ts +1 -1
  17. package/{promises → dist/promises}/timers.d.ts.map +1 -1
  18. package/{serializer → dist/serializer}/context.d.ts +1 -1
  19. package/{serializer → dist/serializer}/context.d.ts.map +1 -1
  20. package/{serializer → dist/serializer}/serialize.d.ts +1 -1
  21. package/{serializer → dist/serializer}/serialize.d.ts.map +1 -1
  22. package/{serializer → dist/serializer}/serializers/array.d.ts +1 -1
  23. package/{serializer → dist/serializer}/serializers/array.d.ts.map +1 -1
  24. package/{serializer → dist/serializer}/serializers/binary.d.ts +1 -1
  25. package/dist/serializer/serializers/binary.d.ts.map +1 -0
  26. package/{serializer → dist/serializer}/serializers/blob.d.ts +1 -1
  27. package/dist/serializer/serializers/blob.d.ts.map +1 -0
  28. package/{serializer → dist/serializer}/serializers/collection.d.ts +1 -1
  29. package/{serializer → dist/serializer}/serializers/collection.d.ts.map +1 -1
  30. package/{serializer → dist/serializer}/serializers/compound.d.ts +1 -1
  31. package/{serializer → dist/serializer}/serializers/compound.d.ts.map +1 -1
  32. package/{serializer → dist/serializer}/serializers/error.d.ts +1 -1
  33. package/{serializer → dist/serializer}/serializers/error.d.ts.map +1 -1
  34. package/{serializer → dist/serializer}/serializers/function.d.ts +1 -1
  35. package/{serializer → dist/serializer}/serializers/function.d.ts.map +1 -1
  36. package/{serializer → dist/serializer}/serializers/leaf-object.d.ts +1 -1
  37. package/{serializer → dist/serializer}/serializers/leaf-object.d.ts.map +1 -1
  38. package/{serializer → dist/serializer}/serializers/number.d.ts +1 -1
  39. package/dist/serializer/serializers/number.d.ts.map +1 -0
  40. package/{serializer → dist/serializer}/serializers/object.d.ts +1 -1
  41. package/{serializer → dist/serializer}/serializers/object.d.ts.map +1 -1
  42. package/{serializer → dist/serializer}/serializers/opaque.d.ts +1 -1
  43. package/dist/serializer/serializers/opaque.d.ts.map +1 -0
  44. package/{serializer → dist/serializer}/serializers/primitive.d.ts +1 -1
  45. package/{serializer → dist/serializer}/serializers/primitive.d.ts.map +1 -1
  46. package/{serializer → dist/serializer}/types.d.ts +1 -1
  47. package/{serializer → dist/serializer}/types.d.ts.map +1 -1
  48. package/{serializer → dist/serializer}/utils.d.ts +1 -1
  49. package/{serializer → dist/serializer}/utils.d.ts.map +1 -1
  50. package/{system → dist/system}/fetch.d.ts +2 -2
  51. package/{system → dist/system}/fetch.d.ts.map +1 -1
  52. package/dist/system/types.d.ts +3 -0
  53. package/{system → dist/system}/types.d.ts.map +1 -1
  54. package/{times → dist/times}/conversions.d.ts +1 -1
  55. package/{times → dist/times}/conversions.d.ts.map +1 -1
  56. package/package.json +11 -73
  57. package/src/arrays/accessors.ts +25 -0
  58. package/src/arrays/conversions.ts +16 -0
  59. package/src/arrays/factories.ts +13 -0
  60. package/src/arrays/guards.ts +7 -0
  61. package/src/arrays/index.ts +8 -0
  62. package/src/arrays/operations.ts +103 -0
  63. package/src/arrays/set-operations.ts +11 -0
  64. package/src/arrays/types.ts +21 -0
  65. package/src/buffers/conversions.ts +26 -0
  66. package/src/buffers/guards.ts +13 -0
  67. package/src/buffers/index.ts +5 -0
  68. package/src/buffers/operations.ts +44 -0
  69. package/src/buffers/types.ts +1 -0
  70. package/src/collections/fifo-map.ts +33 -0
  71. package/src/collections/fifo-set.ts +29 -0
  72. package/src/collections/guards.ts +11 -0
  73. package/src/collections/index.ts +10 -0
  74. package/src/collections/linked-base.ts +117 -0
  75. package/src/collections/linked-map.ts +82 -0
  76. package/src/collections/linked-set.ts +69 -0
  77. package/src/collections/lru-map.ts +36 -0
  78. package/src/collections/lru-set.ts +25 -0
  79. package/src/collections/types.ts +12 -0
  80. package/src/common/assertions.ts +11 -0
  81. package/src/common/guards.ts +58 -0
  82. package/src/common/index.ts +5 -0
  83. package/src/common/transformations.ts +20 -0
  84. package/src/common/types.ts +3 -0
  85. package/src/core/constants.ts +1 -0
  86. package/src/core/conversions.ts +9 -0
  87. package/src/core/guards.ts +57 -0
  88. package/src/core/index.ts +5 -0
  89. package/src/core/types.ts +15 -0
  90. package/src/errors/base-error.ts +48 -0
  91. package/src/errors/factories.ts +74 -0
  92. package/src/errors/guards.ts +12 -0
  93. package/src/errors/index.ts +7 -0
  94. package/src/errors/operations.ts +15 -0
  95. package/src/errors/stringify.ts +131 -0
  96. package/src/errors/types.ts +11 -0
  97. package/src/events/emitter.ts +117 -0
  98. package/src/events/index.ts +2 -0
  99. package/src/events/types.ts +11 -0
  100. package/src/functions/compositions.ts +17 -0
  101. package/src/functions/debounce.ts +34 -0
  102. package/src/functions/executions.ts +12 -0
  103. package/src/functions/guards.ts +5 -0
  104. package/src/functions/index.ts +11 -0
  105. package/src/functions/memoize.ts +33 -0
  106. package/src/functions/once.ts +33 -0
  107. package/src/functions/pipe.ts +39 -0
  108. package/src/functions/throttle.ts +59 -0
  109. package/src/functions/timer-state.ts +33 -0
  110. package/src/functions/types.ts +8 -0
  111. package/src/index.ts +16 -0
  112. package/src/json-rpc/constants.ts +15 -0
  113. package/src/json-rpc/factories.ts +22 -0
  114. package/src/json-rpc/guards.ts +58 -0
  115. package/src/json-rpc/index.ts +5 -0
  116. package/src/json-rpc/types.ts +48 -0
  117. package/src/numbers/bigint-math.ts +163 -0
  118. package/src/numbers/constants.ts +14 -0
  119. package/src/numbers/conversions.ts +83 -0
  120. package/src/numbers/factories.ts +6 -0
  121. package/src/numbers/formats.ts +52 -0
  122. package/src/numbers/guards.ts +22 -0
  123. package/src/numbers/index.ts +10 -0
  124. package/src/numbers/maths.ts +28 -0
  125. package/src/numbers/ranges.ts +17 -0
  126. package/src/numbers/types.ts +7 -0
  127. package/src/objects/deep-merge.ts +76 -0
  128. package/src/objects/guards.ts +21 -0
  129. package/src/objects/index.ts +5 -0
  130. package/src/objects/transformations.ts +34 -0
  131. package/src/objects/types.ts +33 -0
  132. package/src/promises/abortable.ts +37 -0
  133. package/src/promises/compositions.ts +18 -0
  134. package/src/promises/deferred.ts +131 -0
  135. package/src/promises/guards.ts +8 -0
  136. package/src/promises/index.ts +10 -0
  137. package/src/promises/pipe.ts +39 -0
  138. package/src/promises/poll.ts +92 -0
  139. package/src/promises/retry.ts +138 -0
  140. package/src/promises/timers.ts +16 -0
  141. package/src/promises/types.ts +1 -0
  142. package/src/serializer/constants.ts +5 -0
  143. package/src/serializer/context.ts +24 -0
  144. package/src/serializer/index.ts +8 -0
  145. package/src/serializer/serialize.ts +51 -0
  146. package/src/serializer/serializers/array.ts +17 -0
  147. package/src/serializer/serializers/binary.ts +24 -0
  148. package/src/serializer/serializers/blob.ts +18 -0
  149. package/src/serializer/serializers/collection.ts +25 -0
  150. package/src/serializer/serializers/compound.ts +79 -0
  151. package/src/serializer/serializers/error.ts +75 -0
  152. package/src/serializer/serializers/function.ts +13 -0
  153. package/src/serializer/serializers/index.ts +12 -0
  154. package/src/serializer/serializers/leaf-object.ts +18 -0
  155. package/src/serializer/serializers/number.ts +14 -0
  156. package/src/serializer/serializers/object.ts +62 -0
  157. package/src/serializer/serializers/opaque.ts +36 -0
  158. package/src/serializer/serializers/primitive.ts +32 -0
  159. package/src/serializer/symbol-registry.ts +28 -0
  160. package/src/serializer/types.ts +42 -0
  161. package/src/serializer/utils.ts +15 -0
  162. package/src/strings/constants.ts +1 -0
  163. package/src/strings/factories.ts +9 -0
  164. package/src/strings/guards.ts +51 -0
  165. package/src/strings/index.ts +6 -0
  166. package/src/strings/manipulations.ts +99 -0
  167. package/src/strings/types.ts +3 -0
  168. package/src/system/env.ts +32 -0
  169. package/src/system/fetch.ts +23 -0
  170. package/src/system/graceful-exit.ts +46 -0
  171. package/src/system/index.ts +6 -0
  172. package/src/system/path.ts +12 -0
  173. package/src/system/types.ts +3 -0
  174. package/src/times/constants.ts +6 -0
  175. package/src/times/conversions.ts +85 -0
  176. package/src/times/factories.ts +3 -0
  177. package/src/times/guards.ts +3 -0
  178. package/src/times/index.ts +5 -0
  179. package/src/times/operations.ts +9 -0
  180. package/CHANGELOG.md +0 -57
  181. package/arrays/index.js +0 -4
  182. package/arrays/index.js.map +0 -9
  183. package/buffers/index.js +0 -4
  184. package/buffers/index.js.map +0 -9
  185. package/chunk-25ja9350.js +0 -4
  186. package/chunk-25ja9350.js.map +0 -13
  187. package/chunk-3w6nt7kb.js +0 -4
  188. package/chunk-3w6nt7kb.js.map +0 -12
  189. package/chunk-5txwcr6j.js +0 -4
  190. package/chunk-5txwcr6j.js.map +0 -17
  191. package/chunk-6dxad51h.js +0 -4
  192. package/chunk-6dxad51h.js.map +0 -12
  193. package/chunk-6kdnnxe0.js +0 -4
  194. package/chunk-6kdnnxe0.js.map +0 -17
  195. package/chunk-7cndek91.js +0 -4
  196. package/chunk-7cndek91.js.map +0 -15
  197. package/chunk-bee0nxse.js +0 -6
  198. package/chunk-bee0nxse.js.map +0 -14
  199. package/chunk-bjmntg2y.js +0 -4
  200. package/chunk-bjmntg2y.js.map +0 -18
  201. package/chunk-d0d0d285.js +0 -4
  202. package/chunk-d0d0d285.js.map +0 -26
  203. package/chunk-jny2gdyy.js +0 -4
  204. package/chunk-jny2gdyy.js.map +0 -12
  205. package/chunk-kbzgn0z4.js +0 -4
  206. package/chunk-kbzgn0z4.js.map +0 -10
  207. package/chunk-qmbgp0vr.js +0 -4
  208. package/chunk-qmbgp0vr.js.map +0 -12
  209. package/chunk-qn6n0ff5.js +0 -4
  210. package/chunk-qn6n0ff5.js.map +0 -17
  211. package/chunk-r3maskdb.js +0 -5
  212. package/chunk-r3maskdb.js.map +0 -13
  213. package/chunk-st3dxvqt.js +0 -4
  214. package/chunk-st3dxvqt.js.map +0 -14
  215. package/chunk-xp18wdk6.js +0 -4
  216. package/chunk-xp18wdk6.js.map +0 -12
  217. package/collections/index.js +0 -4
  218. package/collections/index.js.map +0 -9
  219. package/common/index.js +0 -4
  220. package/common/index.js.map +0 -9
  221. package/core/index.js +0 -4
  222. package/core/index.js.map +0 -9
  223. package/errors/index.js +0 -4
  224. package/errors/index.js.map +0 -9
  225. package/events/index.js +0 -4
  226. package/events/index.js.map +0 -9
  227. package/functions/index.js +0 -4
  228. package/functions/index.js.map +0 -9
  229. package/index.js +0 -4
  230. package/index.js.map +0 -9
  231. package/json-rpc/index.js +0 -4
  232. package/json-rpc/index.js.map +0 -9
  233. package/meta.json +0 -2998
  234. package/meta.md +0 -1816
  235. package/numbers/index.js +0 -4
  236. package/numbers/index.js.map +0 -9
  237. package/objects/index.js +0 -4
  238. package/objects/index.js.map +0 -9
  239. package/promises/index.js +0 -4
  240. package/promises/index.js.map +0 -9
  241. package/serializer/index.js +0 -4
  242. package/serializer/index.js.map +0 -9
  243. package/serializer/serializers/binary.d.ts.map +0 -1
  244. package/serializer/serializers/blob.d.ts.map +0 -1
  245. package/serializer/serializers/number.d.ts.map +0 -1
  246. package/serializer/serializers/opaque.d.ts.map +0 -1
  247. package/strings/index.js +0 -4
  248. package/strings/index.js.map +0 -9
  249. package/system/index.js +0 -4
  250. package/system/index.js.map +0 -9
  251. package/system/types.d.ts +0 -3
  252. package/times/index.js +0 -4
  253. package/times/index.js.map +0 -9
  254. /package/{arrays → dist/arrays}/accessors.d.ts +0 -0
  255. /package/{arrays → dist/arrays}/accessors.d.ts.map +0 -0
  256. /package/{arrays → dist/arrays}/conversions.d.ts +0 -0
  257. /package/{arrays → dist/arrays}/conversions.d.ts.map +0 -0
  258. /package/{arrays → dist/arrays}/factories.d.ts +0 -0
  259. /package/{arrays → dist/arrays}/factories.d.ts.map +0 -0
  260. /package/{arrays → dist/arrays}/guards.d.ts +0 -0
  261. /package/{arrays → dist/arrays}/guards.d.ts.map +0 -0
  262. /package/{arrays → dist/arrays}/index.d.ts +0 -0
  263. /package/{arrays → dist/arrays}/index.d.ts.map +0 -0
  264. /package/{arrays → dist/arrays}/operations.d.ts +0 -0
  265. /package/{arrays → dist/arrays}/operations.d.ts.map +0 -0
  266. /package/{arrays → dist/arrays}/set-operations.d.ts +0 -0
  267. /package/{arrays → dist/arrays}/set-operations.d.ts.map +0 -0
  268. /package/{arrays → dist/arrays}/types.d.ts +0 -0
  269. /package/{arrays → dist/arrays}/types.d.ts.map +0 -0
  270. /package/{buffers → dist/buffers}/conversions.d.ts +0 -0
  271. /package/{buffers → dist/buffers}/conversions.d.ts.map +0 -0
  272. /package/{buffers → dist/buffers}/guards.d.ts +0 -0
  273. /package/{buffers → dist/buffers}/guards.d.ts.map +0 -0
  274. /package/{buffers → dist/buffers}/index.d.ts +0 -0
  275. /package/{buffers → dist/buffers}/index.d.ts.map +0 -0
  276. /package/{buffers → dist/buffers}/operations.d.ts +0 -0
  277. /package/{buffers → dist/buffers}/operations.d.ts.map +0 -0
  278. /package/{buffers → dist/buffers}/types.d.ts +0 -0
  279. /package/{buffers → dist/buffers}/types.d.ts.map +0 -0
  280. /package/{collections → dist/collections}/fifo-map.d.ts +0 -0
  281. /package/{collections → dist/collections}/fifo-map.d.ts.map +0 -0
  282. /package/{collections → dist/collections}/fifo-set.d.ts +0 -0
  283. /package/{collections → dist/collections}/fifo-set.d.ts.map +0 -0
  284. /package/{collections → dist/collections}/guards.d.ts +0 -0
  285. /package/{collections → dist/collections}/guards.d.ts.map +0 -0
  286. /package/{collections → dist/collections}/index.d.ts +0 -0
  287. /package/{collections → dist/collections}/index.d.ts.map +0 -0
  288. /package/{collections → dist/collections}/linked-base.d.ts +0 -0
  289. /package/{collections → dist/collections}/linked-base.d.ts.map +0 -0
  290. /package/{collections → dist/collections}/linked-map.d.ts +0 -0
  291. /package/{collections → dist/collections}/linked-map.d.ts.map +0 -0
  292. /package/{collections → dist/collections}/linked-set.d.ts +0 -0
  293. /package/{collections → dist/collections}/linked-set.d.ts.map +0 -0
  294. /package/{collections → dist/collections}/lru-map.d.ts +0 -0
  295. /package/{collections → dist/collections}/lru-map.d.ts.map +0 -0
  296. /package/{collections → dist/collections}/lru-set.d.ts +0 -0
  297. /package/{collections → dist/collections}/lru-set.d.ts.map +0 -0
  298. /package/{collections → dist/collections}/types.d.ts +0 -0
  299. /package/{collections → dist/collections}/types.d.ts.map +0 -0
  300. /package/{common → dist/common}/guards.d.ts +0 -0
  301. /package/{common → dist/common}/guards.d.ts.map +0 -0
  302. /package/{common → dist/common}/index.d.ts +0 -0
  303. /package/{common → dist/common}/index.d.ts.map +0 -0
  304. /package/{common → dist/common}/transformations.d.ts +0 -0
  305. /package/{common → dist/common}/transformations.d.ts.map +0 -0
  306. /package/{core → dist/core}/constants.d.ts +0 -0
  307. /package/{core → dist/core}/constants.d.ts.map +0 -0
  308. /package/{core → dist/core}/conversions.d.ts +0 -0
  309. /package/{core → dist/core}/conversions.d.ts.map +0 -0
  310. /package/{core → dist/core}/guards.d.ts +0 -0
  311. /package/{core → dist/core}/guards.d.ts.map +0 -0
  312. /package/{core → dist/core}/index.d.ts +0 -0
  313. /package/{core → dist/core}/index.d.ts.map +0 -0
  314. /package/{core → dist/core}/types.d.ts +0 -0
  315. /package/{core → dist/core}/types.d.ts.map +0 -0
  316. /package/{errors → dist/errors}/base-error.d.ts +0 -0
  317. /package/{errors → dist/errors}/base-error.d.ts.map +0 -0
  318. /package/{errors → dist/errors}/factories.d.ts +0 -0
  319. /package/{errors → dist/errors}/factories.d.ts.map +0 -0
  320. /package/{errors → dist/errors}/guards.d.ts +0 -0
  321. /package/{errors → dist/errors}/guards.d.ts.map +0 -0
  322. /package/{errors → dist/errors}/index.d.ts +0 -0
  323. /package/{errors → dist/errors}/index.d.ts.map +0 -0
  324. /package/{errors → dist/errors}/operations.d.ts +0 -0
  325. /package/{errors → dist/errors}/operations.d.ts.map +0 -0
  326. /package/{errors → dist/errors}/stringify.d.ts +0 -0
  327. /package/{errors → dist/errors}/stringify.d.ts.map +0 -0
  328. /package/{errors → dist/errors}/types.d.ts +0 -0
  329. /package/{errors → dist/errors}/types.d.ts.map +0 -0
  330. /package/{events → dist/events}/emitter.d.ts +0 -0
  331. /package/{events → dist/events}/emitter.d.ts.map +0 -0
  332. /package/{events → dist/events}/index.d.ts +0 -0
  333. /package/{events → dist/events}/index.d.ts.map +0 -0
  334. /package/{events → dist/events}/types.d.ts +0 -0
  335. /package/{events → dist/events}/types.d.ts.map +0 -0
  336. /package/{functions → dist/functions}/compositions.d.ts +0 -0
  337. /package/{functions → dist/functions}/compositions.d.ts.map +0 -0
  338. /package/{functions → dist/functions}/debounce.d.ts +0 -0
  339. /package/{functions → dist/functions}/debounce.d.ts.map +0 -0
  340. /package/{functions → dist/functions}/guards.d.ts +0 -0
  341. /package/{functions → dist/functions}/guards.d.ts.map +0 -0
  342. /package/{functions → dist/functions}/index.d.ts +0 -0
  343. /package/{functions → dist/functions}/index.d.ts.map +0 -0
  344. /package/{functions → dist/functions}/memoize.d.ts +0 -0
  345. /package/{functions → dist/functions}/memoize.d.ts.map +0 -0
  346. /package/{functions → dist/functions}/once.d.ts +0 -0
  347. /package/{functions → dist/functions}/once.d.ts.map +0 -0
  348. /package/{functions → dist/functions}/pipe.d.ts +0 -0
  349. /package/{functions → dist/functions}/pipe.d.ts.map +0 -0
  350. /package/{functions → dist/functions}/throttle.d.ts +0 -0
  351. /package/{functions → dist/functions}/throttle.d.ts.map +0 -0
  352. /package/{functions → dist/functions}/timer-state.d.ts +0 -0
  353. /package/{functions → dist/functions}/timer-state.d.ts.map +0 -0
  354. /package/{functions → dist/functions}/types.d.ts +0 -0
  355. /package/{functions → dist/functions}/types.d.ts.map +0 -0
  356. /package/{index.d.ts → dist/index.d.ts} +0 -0
  357. /package/{index.d.ts.map → dist/index.d.ts.map} +0 -0
  358. /package/{json-rpc → dist/json-rpc}/constants.d.ts +0 -0
  359. /package/{json-rpc → dist/json-rpc}/constants.d.ts.map +0 -0
  360. /package/{json-rpc → dist/json-rpc}/factories.d.ts +0 -0
  361. /package/{json-rpc → dist/json-rpc}/factories.d.ts.map +0 -0
  362. /package/{json-rpc → dist/json-rpc}/guards.d.ts +0 -0
  363. /package/{json-rpc → dist/json-rpc}/guards.d.ts.map +0 -0
  364. /package/{json-rpc → dist/json-rpc}/index.d.ts +0 -0
  365. /package/{json-rpc → dist/json-rpc}/index.d.ts.map +0 -0
  366. /package/{json-rpc → dist/json-rpc}/types.d.ts +0 -0
  367. /package/{json-rpc → dist/json-rpc}/types.d.ts.map +0 -0
  368. /package/{numbers → dist/numbers}/bigint-math.d.ts +0 -0
  369. /package/{numbers → dist/numbers}/bigint-math.d.ts.map +0 -0
  370. /package/{numbers → dist/numbers}/constants.d.ts +0 -0
  371. /package/{numbers → dist/numbers}/constants.d.ts.map +0 -0
  372. /package/{numbers → dist/numbers}/conversions.d.ts +0 -0
  373. /package/{numbers → dist/numbers}/conversions.d.ts.map +0 -0
  374. /package/{numbers → dist/numbers}/factories.d.ts +0 -0
  375. /package/{numbers → dist/numbers}/factories.d.ts.map +0 -0
  376. /package/{numbers → dist/numbers}/formats.d.ts +0 -0
  377. /package/{numbers → dist/numbers}/formats.d.ts.map +0 -0
  378. /package/{numbers → dist/numbers}/guards.d.ts +0 -0
  379. /package/{numbers → dist/numbers}/guards.d.ts.map +0 -0
  380. /package/{numbers → dist/numbers}/index.d.ts +0 -0
  381. /package/{numbers → dist/numbers}/index.d.ts.map +0 -0
  382. /package/{numbers → dist/numbers}/maths.d.ts +0 -0
  383. /package/{numbers → dist/numbers}/maths.d.ts.map +0 -0
  384. /package/{numbers → dist/numbers}/ranges.d.ts +0 -0
  385. /package/{numbers → dist/numbers}/ranges.d.ts.map +0 -0
  386. /package/{numbers → dist/numbers}/types.d.ts +0 -0
  387. /package/{numbers → dist/numbers}/types.d.ts.map +0 -0
  388. /package/{objects → dist/objects}/deep-merge.d.ts +0 -0
  389. /package/{objects → dist/objects}/deep-merge.d.ts.map +0 -0
  390. /package/{objects → dist/objects}/guards.d.ts +0 -0
  391. /package/{objects → dist/objects}/guards.d.ts.map +0 -0
  392. /package/{objects → dist/objects}/index.d.ts +0 -0
  393. /package/{objects → dist/objects}/index.d.ts.map +0 -0
  394. /package/{promises → dist/promises}/abortable.d.ts +0 -0
  395. /package/{promises → dist/promises}/abortable.d.ts.map +0 -0
  396. /package/{promises → dist/promises}/compositions.d.ts +0 -0
  397. /package/{promises → dist/promises}/compositions.d.ts.map +0 -0
  398. /package/{promises → dist/promises}/guards.d.ts +0 -0
  399. /package/{promises → dist/promises}/guards.d.ts.map +0 -0
  400. /package/{promises → dist/promises}/index.d.ts +0 -0
  401. /package/{promises → dist/promises}/index.d.ts.map +0 -0
  402. /package/{promises → dist/promises}/pipe.d.ts +0 -0
  403. /package/{promises → dist/promises}/pipe.d.ts.map +0 -0
  404. /package/{promises → dist/promises}/poll.d.ts +0 -0
  405. /package/{promises → dist/promises}/poll.d.ts.map +0 -0
  406. /package/{promises → dist/promises}/retry.d.ts +0 -0
  407. /package/{promises → dist/promises}/retry.d.ts.map +0 -0
  408. /package/{promises → dist/promises}/types.d.ts +0 -0
  409. /package/{promises → dist/promises}/types.d.ts.map +0 -0
  410. /package/{serializer → dist/serializer}/constants.d.ts +0 -0
  411. /package/{serializer → dist/serializer}/constants.d.ts.map +0 -0
  412. /package/{serializer → dist/serializer}/index.d.ts +0 -0
  413. /package/{serializer → dist/serializer}/index.d.ts.map +0 -0
  414. /package/{serializer → dist/serializer}/serializers/index.d.ts +0 -0
  415. /package/{serializer → dist/serializer}/serializers/index.d.ts.map +0 -0
  416. /package/{serializer → dist/serializer}/symbol-registry.d.ts +0 -0
  417. /package/{serializer → dist/serializer}/symbol-registry.d.ts.map +0 -0
  418. /package/{strings → dist/strings}/constants.d.ts +0 -0
  419. /package/{strings → dist/strings}/constants.d.ts.map +0 -0
  420. /package/{strings → dist/strings}/factories.d.ts +0 -0
  421. /package/{strings → dist/strings}/factories.d.ts.map +0 -0
  422. /package/{strings → dist/strings}/guards.d.ts +0 -0
  423. /package/{strings → dist/strings}/guards.d.ts.map +0 -0
  424. /package/{strings → dist/strings}/index.d.ts +0 -0
  425. /package/{strings → dist/strings}/index.d.ts.map +0 -0
  426. /package/{strings → dist/strings}/manipulations.d.ts +0 -0
  427. /package/{strings → dist/strings}/manipulations.d.ts.map +0 -0
  428. /package/{strings → dist/strings}/types.d.ts +0 -0
  429. /package/{strings → dist/strings}/types.d.ts.map +0 -0
  430. /package/{system → dist/system}/env.d.ts +0 -0
  431. /package/{system → dist/system}/env.d.ts.map +0 -0
  432. /package/{system → dist/system}/graceful-exit.d.ts +0 -0
  433. /package/{system → dist/system}/graceful-exit.d.ts.map +0 -0
  434. /package/{system → dist/system}/index.d.ts +0 -0
  435. /package/{system → dist/system}/index.d.ts.map +0 -0
  436. /package/{system → dist/system}/path.d.ts +0 -0
  437. /package/{system → dist/system}/path.d.ts.map +0 -0
  438. /package/{times → dist/times}/constants.d.ts +0 -0
  439. /package/{times → dist/times}/constants.d.ts.map +0 -0
  440. /package/{times → dist/times}/factories.d.ts +0 -0
  441. /package/{times → dist/times}/factories.d.ts.map +0 -0
  442. /package/{times → dist/times}/guards.d.ts +0 -0
  443. /package/{times → dist/times}/guards.d.ts.map +0 -0
  444. /package/{times → dist/times}/index.d.ts +0 -0
  445. /package/{times → dist/times}/index.d.ts.map +0 -0
  446. /package/{times → dist/times}/operations.d.ts +0 -0
  447. /package/{times → dist/times}/operations.d.ts.map +0 -0
@@ -0,0 +1,16 @@
1
+ import { combineSignals, createAbortController, type Errorable } from '../errors'
2
+ import { transform } from '../functions'
3
+ import { abortable } from './abortable'
4
+
5
+ export interface TimerOptions {
6
+ error?: Errorable
7
+ signal?: AbortSignal
8
+ }
9
+
10
+ export const sleep = async (ms: number, { error, signal }: TimerOptions = {}) => (
11
+ abortable(new Promise<void>((resolve) => setTimeout(resolve, ms)), signal, error)
12
+ )
13
+
14
+ export const withTimeout = <T>(promise: Promise<T>, ms: number, { error, signal }: TimerOptions = {}) => (
15
+ transform(createAbortController(ms, error), (controller) => abortable(promise, combineSignals(signal, controller.signal)).finally(() => controller.abort()))
16
+ )
@@ -0,0 +1 @@
1
+ export type Awaitable<T> = PromiseLike<T> | T
@@ -0,0 +1,5 @@
1
+ export const SERIALIZE = Symbol.for('serialize.custom')
2
+
3
+ export const GENERATOR_PATTERNS = /\bfunction\s*\*|^async\s+function\s*\*|\*\s*\[|^\*\s/u
4
+
5
+ export const OMIT_SENTINEL = Symbol('omit')
@@ -0,0 +1,24 @@
1
+ import type { Jsonable } from '../core'
2
+ import type { SerializeContext, SerializedValue, SerializeErrorStrategy, SerializeOptions } from './types'
3
+ import { createSymbolKeySerializer } from './symbol-registry'
4
+
5
+ export const DEFAULT_REPLACER = (value: Omit<SerializedValue, '__serialized__'>): Jsonable => ({ ...value, __serialized__: true }) as Jsonable
6
+
7
+ export function createContext(options: SerializeOptions = {}): SerializeContext {
8
+ const { maxDepth = Number.POSITIVE_INFINITY, onUnserializable = false, replacer = DEFAULT_REPLACER } = options
9
+ let onCircularRef: SerializeErrorStrategy = 'placeholder'
10
+ let onMaxDepth: SerializeErrorStrategy = 'placeholder'
11
+ let onPropertyAccess: SerializeErrorStrategy = 'placeholder'
12
+
13
+ if (typeof options.onError === 'string') {
14
+ onCircularRef = options.onError
15
+ onMaxDepth = options.onError
16
+ onPropertyAccess = options.onError
17
+ } else if (typeof options.onError === 'object' && options.onError != null) {
18
+ onCircularRef = options.onError.circularRef ?? 'placeholder'
19
+ onMaxDepth = options.onError.maxDepth ?? 'placeholder'
20
+ onPropertyAccess = options.onError.propertyAccess ?? 'placeholder'
21
+ }
22
+
23
+ return { depth: 0, maxDepth, onCircularRef, onMaxDepth, onPropertyAccess, onUnserializable, replacer, symbolRegistry: createSymbolKeySerializer(), visited: new Set() }
24
+ }
@@ -0,0 +1,8 @@
1
+ export * from './constants'
2
+ export * from './context'
3
+ export * from './serialize'
4
+ export * from './serializers'
5
+ export * from './symbol-registry'
6
+ export * from './utils'
7
+
8
+ export type * from './types'
@@ -0,0 +1,51 @@
1
+ import type { Jsonable } from '../core'
2
+ import type { SerializeContext, SerializeOptions } from './types'
3
+ import { OMIT_SENTINEL } from './constants'
4
+ import { createContext } from './context'
5
+ import { serializeCompound } from './serializers/compound'
6
+ import { serializeLeafObject } from './serializers/leaf-object'
7
+ import { serializePrimitive } from './serializers/primitive'
8
+ import { handleError } from './utils'
9
+
10
+ export function serialize(value: unknown, options?: SerializeOptions): Jsonable {
11
+ const ctx = createContext(options)
12
+ const serializedValue = serializeValue(value, ctx)
13
+
14
+ if (serializedValue === OMIT_SENTINEL) {
15
+ return null
16
+ }
17
+
18
+ return serializedValue
19
+ }
20
+
21
+ export function serializeValue(value: unknown, ctx: SerializeContext): Jsonable | typeof OMIT_SENTINEL {
22
+ const primitive = serializePrimitive(value, ctx)
23
+
24
+ if (primitive !== undefined) {
25
+ return primitive
26
+ }
27
+
28
+ const leaf = serializeLeafObject(value, ctx)
29
+
30
+ if (leaf !== undefined) {
31
+ return leaf
32
+ }
33
+
34
+ if (ctx.visited.has(value as object)) {
35
+ return handleError(ctx.onCircularRef, 'circular-ref', '[Circular]', ctx)
36
+ }
37
+
38
+ if (ctx.depth >= ctx.maxDepth) {
39
+ return handleError(ctx.onMaxDepth, 'max-depth', '[Max Depth]', ctx)
40
+ }
41
+
42
+ ctx.visited.add(value as object)
43
+ ctx.depth++
44
+
45
+ try {
46
+ return serializeCompound(value as object, ctx, serializeValue)
47
+ } finally {
48
+ ctx.depth--
49
+ ctx.visited.delete(value as object)
50
+ }
51
+ }
@@ -0,0 +1,17 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { SerializeContext, SerializeValueFn } from '../types'
3
+ import { OMIT_SENTINEL } from '../constants'
4
+
5
+ export function serializeArrayEntry(entry: unknown, ctx: SerializeContext, serializeValue: SerializeValueFn): Jsonable {
6
+ const serializedValue = serializeValue(entry, ctx)
7
+
8
+ return serializedValue === OMIT_SENTINEL ? null : serializedValue
9
+ }
10
+
11
+ export const serializeArray = (value: unknown[], ctx: SerializeContext, serializeValue: SerializeValueFn): Jsonable[] => (
12
+ value.map((entry) => serializeArrayEntry(entry, ctx, serializeValue))
13
+ )
14
+
15
+ export const serializeIterableEntries = (value: Iterable<unknown>, ctx: SerializeContext, serializeValue: SerializeValueFn): Jsonable[] => (
16
+ Array.from(value, (entry) => serializeArrayEntry(entry, ctx, serializeValue))
17
+ )
@@ -0,0 +1,24 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { SerializeContext } from '../types'
3
+
4
+ export function serializeBinary(value: object, ctx: SerializeContext): Jsonable | undefined {
5
+ if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {
6
+ const typed = value as unknown as { [Symbol.toStringTag]: string, byteLength: number, byteOffset: number, length: number }
7
+
8
+ return ctx.replacer({
9
+ metadata: { byteLength: typed.byteLength, byteOffset: typed.byteOffset },
10
+ type: typed[Symbol.toStringTag]?.toLowerCase() ?? 'typedarray',
11
+ value: Array.from({ length: typed.length }, (_, index) => (value as unknown as ArrayLike<number>)[index]!),
12
+ })
13
+ }
14
+
15
+ if (value instanceof ArrayBuffer || (typeof SharedArrayBuffer !== 'undefined' && value instanceof SharedArrayBuffer)) {
16
+ return ctx.replacer({ metadata: { byteLength: value.byteLength }, type: 'arraybuffer', value: [...new Uint8Array(value)] })
17
+ }
18
+
19
+ if (value instanceof DataView) {
20
+ return ctx.replacer({ metadata: { byteLength: value.byteLength, byteOffset: value.byteOffset }, type: 'dataview', value: null })
21
+ }
22
+
23
+ return undefined
24
+ }
@@ -0,0 +1,18 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { SerializeContext } from '../types'
3
+
4
+ export function serializeBlob(value: object, ctx: SerializeContext): Jsonable | undefined {
5
+ if (typeof Blob === 'undefined' || !(value instanceof Blob)) {
6
+ return undefined
7
+ }
8
+
9
+ const metadata: Record<string, Jsonable> = { size: value.size, type: value.type }
10
+
11
+ if (typeof File !== 'undefined' && value instanceof File) {
12
+ metadata.name = value.name
13
+
14
+ return ctx.replacer({ metadata, type: 'file', value: null })
15
+ }
16
+
17
+ return ctx.replacer({ metadata, type: 'blob', value: null })
18
+ }
@@ -0,0 +1,25 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { SerializeContext, SerializeValueFn } from '../types'
3
+ import { isCollectionLike, isMapLike, isSetLike } from '../../collections'
4
+ import { serializeIterableEntries } from './array'
5
+
6
+ export function serializeCollection(value: object, ctx: SerializeContext, serializeValue: SerializeValueFn): Jsonable | undefined {
7
+ if (isCollectionLike(value)) {
8
+ const name = value.constructor?.name
9
+ const metadata: Record<string, Jsonable> = { size: value.size }
10
+
11
+ if (name) {
12
+ metadata.name = name
13
+ }
14
+
15
+ if (isMapLike(value)) {
16
+ return ctx.replacer({ metadata, type: 'map', value: serializeIterableEntries(value.entries(), ctx, serializeValue) })
17
+ }
18
+
19
+ if (isSetLike(value)) {
20
+ return ctx.replacer({ metadata, type: 'set', value: serializeIterableEntries(value, ctx, serializeValue) })
21
+ }
22
+ }
23
+
24
+ return undefined
25
+ }
@@ -0,0 +1,79 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { SerializeContext, SerializeValueFn } from '../types'
3
+ import { isArray } from '../../arrays'
4
+ import { isIterable } from '../../collections'
5
+ import { typeOf } from '../../core'
6
+ import { isPlainObject } from '../../objects'
7
+ import { type OMIT_SENTINEL, SERIALIZE } from '../constants'
8
+ import { serializeArray, serializeIterableEntries } from './array'
9
+ import { serializeBinary } from './binary'
10
+ import { serializeBlob } from './blob'
11
+ import { serializeCollection } from './collection'
12
+ import { serializeError } from './error'
13
+ import { serializeObject } from './object'
14
+ import { serializeOpaque } from './opaque'
15
+
16
+ export function serializeCompound(value: object, ctx: SerializeContext, serializeValue: SerializeValueFn): Jsonable | typeof OMIT_SENTINEL {
17
+ const customSerialize = (value as Record<PropertyKey, unknown>)[SERIALIZE]
18
+
19
+ if (typeof customSerialize === 'function') {
20
+ return serializeValue((customSerialize as () => unknown)(), ctx)
21
+ }
22
+
23
+ if (isArray(value)) {
24
+ return serializeArray(value, ctx, serializeValue)
25
+ }
26
+
27
+ const collection = serializeCollection(value, ctx, serializeValue)
28
+
29
+ if (collection !== undefined) {
30
+ return collection
31
+ }
32
+
33
+ const binary = serializeBinary(value, ctx)
34
+
35
+ if (binary !== undefined) {
36
+ return binary
37
+ }
38
+
39
+ const blob = serializeBlob(value, ctx)
40
+
41
+ if (blob !== undefined) {
42
+ return blob
43
+ }
44
+
45
+ if (value instanceof Error) {
46
+ return ctx.replacer({ type: 'error', value: serializeError(value, ctx, serializeValue) })
47
+ }
48
+
49
+ if (isPlainObject(value)) {
50
+ return serializeObject(value, ctx, serializeValue)
51
+ }
52
+
53
+ const opaque = serializeOpaque(value, ctx)
54
+
55
+ if (opaque !== undefined) {
56
+ return opaque
57
+ }
58
+
59
+ if (typeof (value as Record<string, unknown>).toJSON === 'function') {
60
+ return serializeValue((value as { toJSON: () => unknown }).toJSON(), ctx)
61
+ }
62
+
63
+ if (isIterable(value)) {
64
+ const name = value.constructor?.name
65
+ const metadata: Record<string, Jsonable> = {}
66
+
67
+ if (name) {
68
+ metadata.name = name
69
+ }
70
+
71
+ return ctx.replacer({ metadata, type: 'iterable', value: serializeIterableEntries(value, ctx, serializeValue) })
72
+ }
73
+
74
+ if (ctx.onUnserializable) {
75
+ return ctx.onUnserializable(value)
76
+ }
77
+
78
+ return ctx.replacer({ type: typeOf(value), value: `[${value.constructor?.name ?? typeOf(value)}]` })
79
+ }
@@ -0,0 +1,75 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { ErrorPropertyValue, SerializeContext, SerializeValueFn } from '../types'
3
+ import { OMIT_SENTINEL } from '../constants'
4
+ import { handlePropertyAccessError } from './object'
5
+
6
+ export const isUsableValue = (value: ErrorPropertyValue): value is Jsonable => (
7
+ value !== undefined && value !== OMIT_SENTINEL
8
+ )
9
+
10
+ export function readProperty(error: Error, key: string | symbol, ctx: SerializeContext, serializeValue: SerializeValueFn): ErrorPropertyValue {
11
+ try {
12
+ const value = (error as unknown as Record<string | symbol, unknown>)[key]
13
+
14
+ if (value === undefined) {
15
+ return undefined
16
+ }
17
+
18
+ return serializeValue(value, ctx)
19
+ } catch (error_) {
20
+ return handlePropertyAccessError(error_, ctx.onPropertyAccess, key, ctx)
21
+ }
22
+ }
23
+
24
+ export function serializeErrorCoreFields(error: Error, ctx: SerializeContext, serializeValue: SerializeValueFn): Record<string, Jsonable> {
25
+ const result: Record<string, Jsonable> = { name: error.name }
26
+ const serializedMessage = readProperty(error, 'message', ctx, serializeValue)
27
+ const serializedStack = readProperty(error, 'stack', ctx, serializeValue)
28
+ const serializedCause = readProperty(error, 'cause', ctx, serializeValue)
29
+
30
+ if (typeof serializedMessage === 'string' && serializedMessage.length > 0) {
31
+ result.message = serializedMessage
32
+ }
33
+
34
+ if (typeof serializedStack === 'string' && serializedStack.length > 0) {
35
+ result.stack = serializedStack
36
+ }
37
+
38
+ if (isUsableValue(serializedCause)) {
39
+ result.cause = serializedCause
40
+ }
41
+
42
+ if (error instanceof AggregateError) {
43
+ const serializedErrors = readProperty(error, 'errors', ctx, serializeValue)
44
+
45
+ if (isUsableValue(serializedErrors)) {
46
+ result.errors = serializedErrors
47
+ }
48
+ }
49
+
50
+ return result
51
+ }
52
+
53
+ export function serializeError(error: Error, ctx: SerializeContext, serializeValue: SerializeValueFn): Record<string, Jsonable> {
54
+ const result = serializeErrorCoreFields(error, ctx, serializeValue)
55
+
56
+ for (const key of Object.keys(error)) {
57
+ if (!(key in result)) {
58
+ const serializedValue = readProperty(error, key, ctx, serializeValue)
59
+
60
+ if (isUsableValue(serializedValue)) {
61
+ result[key] = serializedValue
62
+ }
63
+ }
64
+ }
65
+
66
+ for (const sym of Object.getOwnPropertySymbols(error)) {
67
+ const serializedValue = readProperty(error, sym, ctx, serializeValue)
68
+
69
+ if (isUsableValue(serializedValue)) {
70
+ result[ctx.symbolRegistry(sym)] = serializedValue
71
+ }
72
+ }
73
+
74
+ return result
75
+ }
@@ -0,0 +1,13 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { SerializeContext } from '../types'
3
+ import { GENERATOR_PATTERNS } from '../constants'
4
+
5
+ export function serializeFunction(fn: (...args: unknown[]) => unknown, ctx: SerializeContext): Jsonable {
6
+ const metadata: Record<string, Jsonable> = {}
7
+ const str = fn.toString()
8
+
9
+ metadata.async = str.startsWith('async')
10
+ metadata.generator = GENERATOR_PATTERNS.test(str)
11
+
12
+ return ctx.replacer({ metadata, type: 'function', value: { length: fn.length, name: fn.name || 'anonymous' } })
13
+ }
@@ -0,0 +1,12 @@
1
+ export * from './array'
2
+ export * from './binary'
3
+ export * from './blob'
4
+ export * from './collection'
5
+ export * from './compound'
6
+ export * from './error'
7
+ export * from './function'
8
+ export * from './leaf-object'
9
+ export * from './number'
10
+ export * from './object'
11
+ export * from './opaque'
12
+ export * from './primitive'
@@ -0,0 +1,18 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { SerializeContext } from '../types'
3
+
4
+ export function serializeLeafObject(value: unknown, ctx: SerializeContext): Jsonable | undefined {
5
+ if (value instanceof Date) {
6
+ return ctx.replacer({ type: 'date', value: value.toISOString() })
7
+ }
8
+
9
+ if (value instanceof RegExp) {
10
+ return ctx.replacer({ type: 'regexp', value: value.toString() })
11
+ }
12
+
13
+ if (value instanceof URL) {
14
+ return ctx.replacer({ type: 'url', value: value.href })
15
+ }
16
+
17
+ return undefined
18
+ }
@@ -0,0 +1,14 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { SerializeContext } from '../types'
3
+
4
+ export function serializeNumber(value: number, ctx: SerializeContext): Jsonable {
5
+ if (Number.isNaN(value)) {
6
+ return ctx.replacer({ type: 'number', value: 'NaN' })
7
+ }
8
+
9
+ if (!Number.isFinite(value)) {
10
+ return ctx.replacer({ type: 'number', value: value > 0 ? 'Infinity' : '-Infinity' })
11
+ }
12
+
13
+ return value
14
+ }
@@ -0,0 +1,62 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { SerializeContext, SerializeValueFn } from '../types'
3
+ import { OMIT_SENTINEL } from '../constants'
4
+
5
+ export function handlePropertyAccessError(error: unknown, strategy: SerializeContext['onPropertyAccess'], key: string | symbol, ctx: SerializeContext): Jsonable | typeof OMIT_SENTINEL {
6
+ if (strategy === 'throw') {
7
+ throw error
8
+ }
9
+
10
+ if (strategy === 'omit') {
11
+ return OMIT_SENTINEL
12
+ }
13
+
14
+ return ctx.replacer({ type: 'property-access-error', value: `[Property Access Error: ${String(key)}]` })
15
+ }
16
+
17
+ export function safeAccess(obj: object, key: string | symbol, strategy: SerializeContext['onPropertyAccess'], ctx: SerializeContext): unknown {
18
+ try {
19
+ return (obj as Record<string | symbol, unknown>)[key]
20
+ } catch (error) {
21
+ return handlePropertyAccessError(error, strategy, key, ctx)
22
+ }
23
+ }
24
+
25
+ export function serializeObject(obj: object, ctx: SerializeContext, serializeValue: SerializeValueFn): Record<string, Jsonable> {
26
+ const result: Record<string, Jsonable> = {}
27
+ const { onPropertyAccess, symbolRegistry } = ctx
28
+
29
+ for (const key of Object.keys(obj)) {
30
+ const value = safeAccess(obj, key, onPropertyAccess, ctx)
31
+
32
+ if (value === OMIT_SENTINEL) {
33
+ continue
34
+ }
35
+
36
+ const serializedValue = serializeValue(value, ctx)
37
+
38
+ if (serializedValue === OMIT_SENTINEL) {
39
+ continue
40
+ }
41
+
42
+ result[key] = serializedValue
43
+ }
44
+
45
+ for (const sym of Object.getOwnPropertySymbols(obj)) {
46
+ const value = safeAccess(obj, sym, onPropertyAccess, ctx)
47
+
48
+ if (value === OMIT_SENTINEL) {
49
+ continue
50
+ }
51
+
52
+ const serializedValue = serializeValue(value, ctx)
53
+
54
+ if (serializedValue === OMIT_SENTINEL) {
55
+ continue
56
+ }
57
+
58
+ result[symbolRegistry(sym)] = serializedValue
59
+ }
60
+
61
+ return result
62
+ }
@@ -0,0 +1,36 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { SerializeContext } from '../types'
3
+ import { isGenerator } from '../../core'
4
+ import { serializeFunction } from './function'
5
+
6
+ export function serializeOpaque(value: unknown, ctx: SerializeContext): Jsonable | undefined {
7
+ if (typeof value === 'function') {
8
+ return serializeFunction(value as (...args: unknown[]) => unknown, ctx)
9
+ }
10
+
11
+ if (value instanceof Promise) {
12
+ return ctx.replacer({ type: 'promise', value: '[Promise]' })
13
+ }
14
+
15
+ if (value instanceof WeakMap) {
16
+ return ctx.replacer({ type: 'weakmap', value: '[WeakMap]' })
17
+ }
18
+
19
+ if (value instanceof WeakSet) {
20
+ return ctx.replacer({ type: 'weakset', value: '[WeakSet]' })
21
+ }
22
+
23
+ if (typeof WeakRef !== 'undefined' && value instanceof WeakRef) {
24
+ return ctx.replacer({ type: 'weakref', value: '[WeakRef]' })
25
+ }
26
+
27
+ if (typeof ReadableStream !== 'undefined' && value instanceof ReadableStream) {
28
+ return ctx.replacer({ type: 'readablestream', value: '[ReadableStream]' })
29
+ }
30
+
31
+ if (isGenerator(value)) {
32
+ return ctx.replacer({ type: 'generator', value: '[Generator]' })
33
+ }
34
+
35
+ return undefined
36
+ }
@@ -0,0 +1,32 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { SerializeContext } from '../types'
3
+ import { isBigInt, isJsonablePrimitive, isNumber, isSymbol } from '../../core'
4
+ import { serializeNumber } from './number'
5
+
6
+ export function serializePrimitive(value: unknown, ctx: SerializeContext): Jsonable | undefined {
7
+ if (value === null) {
8
+ return null
9
+ }
10
+
11
+ if (value === undefined) {
12
+ return ctx.replacer({ type: 'undefined', value: null })
13
+ }
14
+
15
+ if (isNumber(value)) {
16
+ return serializeNumber(value, ctx)
17
+ }
18
+
19
+ if (isJsonablePrimitive(value)) {
20
+ return value
21
+ }
22
+
23
+ if (isBigInt(value)) {
24
+ return ctx.replacer({ type: 'bigint', value: value.toString() })
25
+ }
26
+
27
+ if (isSymbol(value)) {
28
+ return ctx.replacer({ type: 'symbol', value: ctx.symbolRegistry(value) })
29
+ }
30
+
31
+ return undefined
32
+ }
@@ -0,0 +1,28 @@
1
+ export function createSymbolKeySerializer() {
2
+ const cache = new Map<symbol, string>()
3
+ const usedKeys = new Set<string>()
4
+
5
+ let counter = 0
6
+
7
+ return (symbol: symbol): string => {
8
+ const cached = cache.get(symbol)
9
+
10
+ if (cached !== undefined) {
11
+ return cached
12
+ }
13
+
14
+ const desc = symbol.description
15
+ const base = desc?.length ? desc : `@@${++counter}`
16
+
17
+ let key = `[Symbol(${base})]`
18
+
19
+ while (usedKeys.has(key)) {
20
+ key = `[Symbol(${base}@@${++counter})]`
21
+ }
22
+
23
+ usedKeys.add(key)
24
+ cache.set(symbol, key)
25
+
26
+ return key
27
+ }
28
+ }
@@ -0,0 +1,42 @@
1
+ import type { Jsonable } from '../core'
2
+ import type { OMIT_SENTINEL } from './constants'
3
+
4
+ export interface SerializedValue {
5
+ __serialized__: true
6
+ metadata?: Record<string, Jsonable>
7
+ type: string
8
+ value: Jsonable
9
+ }
10
+
11
+ export type SerializeReplacer = (value: Omit<SerializedValue, '__serialized__'>) => Jsonable
12
+
13
+ export type SerializeErrorStrategy = 'omit' | 'placeholder' | 'throw'
14
+
15
+ export interface SerializeErrorHandlers {
16
+ circularRef?: SerializeErrorStrategy
17
+ maxDepth?: SerializeErrorStrategy
18
+ propertyAccess?: SerializeErrorStrategy
19
+ }
20
+
21
+ export interface SerializeOptions {
22
+ maxDepth?: number
23
+ onError?: SerializeErrorHandlers | SerializeErrorStrategy
24
+ onUnserializable?: ((value: unknown) => Jsonable) | false
25
+ replacer?: SerializeReplacer
26
+ }
27
+
28
+ export interface SerializeContext {
29
+ depth: number
30
+ readonly maxDepth: number
31
+ readonly onCircularRef: SerializeErrorStrategy
32
+ readonly onMaxDepth: SerializeErrorStrategy
33
+ readonly onPropertyAccess: SerializeErrorStrategy
34
+ readonly onUnserializable: ((value: unknown) => Jsonable) | false
35
+ readonly replacer: SerializeReplacer
36
+ readonly symbolRegistry: (symbol: symbol) => string
37
+ readonly visited: Set<object>
38
+ }
39
+
40
+ export type SerializeValueFn = (value: unknown, ctx: SerializeContext) => Jsonable | typeof OMIT_SENTINEL
41
+
42
+ export type ErrorPropertyValue = Jsonable | typeof OMIT_SENTINEL | undefined
@@ -0,0 +1,15 @@
1
+ import type { Jsonable } from '../core'
2
+ import type { SerializeContext, SerializeErrorStrategy } from './types'
3
+ import { OMIT_SENTINEL } from './constants'
4
+
5
+ export function handleError(strategy: SerializeErrorStrategy, type: string, placeholder: string, ctx: SerializeContext): Jsonable | typeof OMIT_SENTINEL {
6
+ if (strategy === 'throw') {
7
+ throw new Error(placeholder)
8
+ }
9
+
10
+ if (strategy === 'omit') {
11
+ return OMIT_SENTINEL
12
+ }
13
+
14
+ return ctx.replacer({ type, value: placeholder })
15
+ }
@@ -0,0 +1 @@
1
+ export const WHITESPACE_CHARACTERS = new Set([' ', '\n', '\r', '\t', '\v', '\f'])
@@ -0,0 +1,9 @@
1
+ export function randomStr(length = 16, characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') {
2
+ let result = ''
3
+
4
+ for (let i = 0; i < length; i++) {
5
+ result += characters.charAt(Math.floor(Math.random() * characters.length))
6
+ }
7
+
8
+ return result
9
+ }