@kdtlabs/utils 0.0.4 → 0.0.6

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 (454) hide show
  1. package/SKILL.md +12 -9
  2. package/dist/arrays/comparators.d.ts +8 -0
  3. package/dist/arrays/comparators.d.ts.map +1 -0
  4. package/{arrays → dist/arrays}/index.d.ts +1 -0
  5. package/dist/arrays/index.d.ts.map +1 -0
  6. package/{common → dist/common}/assertions.d.ts +1 -1
  7. package/{common → dist/common}/assertions.d.ts.map +1 -1
  8. package/{common → dist/common}/types.d.ts +1 -1
  9. package/{common → dist/common}/types.d.ts.map +1 -1
  10. package/{functions → dist/functions}/executions.d.ts +1 -1
  11. package/{functions → dist/functions}/executions.d.ts.map +1 -1
  12. package/dist/index.js +14 -0
  13. package/dist/index.js.map +101 -0
  14. package/{objects → dist/objects}/transformations.d.ts +1 -1
  15. package/{objects → dist/objects}/transformations.d.ts.map +1 -1
  16. package/{objects → dist/objects}/types.d.ts +1 -1
  17. package/{objects → dist/objects}/types.d.ts.map +1 -1
  18. package/{promises → dist/promises}/deferred.d.ts +1 -1
  19. package/{promises → dist/promises}/deferred.d.ts.map +1 -1
  20. package/{promises → dist/promises}/timers.d.ts +1 -1
  21. package/{promises → dist/promises}/timers.d.ts.map +1 -1
  22. package/{serializer → dist/serializer}/context.d.ts +1 -1
  23. package/{serializer → dist/serializer}/context.d.ts.map +1 -1
  24. package/{serializer → dist/serializer}/serialize.d.ts +1 -1
  25. package/{serializer → dist/serializer}/serialize.d.ts.map +1 -1
  26. package/{serializer → dist/serializer}/serializers/array.d.ts +1 -1
  27. package/{serializer → dist/serializer}/serializers/array.d.ts.map +1 -1
  28. package/{serializer → dist/serializer}/serializers/binary.d.ts +1 -1
  29. package/dist/serializer/serializers/binary.d.ts.map +1 -0
  30. package/{serializer → dist/serializer}/serializers/blob.d.ts +1 -1
  31. package/dist/serializer/serializers/blob.d.ts.map +1 -0
  32. package/{serializer → dist/serializer}/serializers/collection.d.ts +1 -1
  33. package/{serializer → dist/serializer}/serializers/collection.d.ts.map +1 -1
  34. package/{serializer → dist/serializer}/serializers/compound.d.ts +1 -1
  35. package/{serializer → dist/serializer}/serializers/compound.d.ts.map +1 -1
  36. package/{serializer → dist/serializer}/serializers/error.d.ts +1 -1
  37. package/{serializer → dist/serializer}/serializers/error.d.ts.map +1 -1
  38. package/{serializer → dist/serializer}/serializers/function.d.ts +1 -1
  39. package/{serializer → dist/serializer}/serializers/function.d.ts.map +1 -1
  40. package/{serializer → dist/serializer}/serializers/leaf-object.d.ts +1 -1
  41. package/{serializer → dist/serializer}/serializers/leaf-object.d.ts.map +1 -1
  42. package/{serializer → dist/serializer}/serializers/number.d.ts +1 -1
  43. package/dist/serializer/serializers/number.d.ts.map +1 -0
  44. package/{serializer → dist/serializer}/serializers/object.d.ts +1 -1
  45. package/{serializer → dist/serializer}/serializers/object.d.ts.map +1 -1
  46. package/{serializer → dist/serializer}/serializers/opaque.d.ts +1 -1
  47. package/dist/serializer/serializers/opaque.d.ts.map +1 -0
  48. package/{serializer → dist/serializer}/serializers/primitive.d.ts +1 -1
  49. package/{serializer → dist/serializer}/serializers/primitive.d.ts.map +1 -1
  50. package/{serializer → dist/serializer}/types.d.ts +1 -1
  51. package/{serializer → dist/serializer}/types.d.ts.map +1 -1
  52. package/{serializer → dist/serializer}/utils.d.ts +1 -1
  53. package/{serializer → dist/serializer}/utils.d.ts.map +1 -1
  54. package/{strings → dist/strings}/index.d.ts +1 -0
  55. package/{strings → dist/strings}/index.d.ts.map +1 -1
  56. package/{strings → dist/strings}/manipulations.d.ts +2 -0
  57. package/{strings → dist/strings}/manipulations.d.ts.map +1 -1
  58. package/dist/strings/strip-ansi.d.ts +2 -0
  59. package/dist/strings/strip-ansi.d.ts.map +1 -0
  60. package/{system → dist/system}/fetch.d.ts +2 -2
  61. package/{system → dist/system}/fetch.d.ts.map +1 -1
  62. package/dist/system/types.d.ts +3 -0
  63. package/{system → dist/system}/types.d.ts.map +1 -1
  64. package/{times → dist/times}/conversions.d.ts +1 -1
  65. package/{times → dist/times}/conversions.d.ts.map +1 -1
  66. package/package.json +11 -73
  67. package/src/arrays/accessors.ts +25 -0
  68. package/src/arrays/comparators.ts +53 -0
  69. package/src/arrays/conversions.ts +16 -0
  70. package/src/arrays/factories.ts +13 -0
  71. package/src/arrays/guards.ts +7 -0
  72. package/src/arrays/index.ts +9 -0
  73. package/src/arrays/operations.ts +103 -0
  74. package/src/arrays/set-operations.ts +11 -0
  75. package/src/arrays/types.ts +21 -0
  76. package/src/buffers/conversions.ts +26 -0
  77. package/src/buffers/guards.ts +13 -0
  78. package/src/buffers/index.ts +5 -0
  79. package/src/buffers/operations.ts +44 -0
  80. package/src/buffers/types.ts +1 -0
  81. package/src/collections/fifo-map.ts +33 -0
  82. package/src/collections/fifo-set.ts +29 -0
  83. package/src/collections/guards.ts +11 -0
  84. package/src/collections/index.ts +10 -0
  85. package/src/collections/linked-base.ts +117 -0
  86. package/src/collections/linked-map.ts +82 -0
  87. package/src/collections/linked-set.ts +69 -0
  88. package/src/collections/lru-map.ts +36 -0
  89. package/src/collections/lru-set.ts +25 -0
  90. package/src/collections/types.ts +12 -0
  91. package/src/common/assertions.ts +11 -0
  92. package/src/common/guards.ts +58 -0
  93. package/src/common/index.ts +5 -0
  94. package/src/common/transformations.ts +20 -0
  95. package/src/common/types.ts +3 -0
  96. package/src/core/constants.ts +1 -0
  97. package/src/core/conversions.ts +9 -0
  98. package/src/core/guards.ts +57 -0
  99. package/src/core/index.ts +5 -0
  100. package/src/core/types.ts +15 -0
  101. package/src/errors/base-error.ts +48 -0
  102. package/src/errors/factories.ts +74 -0
  103. package/src/errors/guards.ts +12 -0
  104. package/src/errors/index.ts +7 -0
  105. package/src/errors/operations.ts +15 -0
  106. package/src/errors/stringify.ts +131 -0
  107. package/src/errors/types.ts +11 -0
  108. package/src/events/emitter.ts +117 -0
  109. package/src/events/index.ts +2 -0
  110. package/src/events/types.ts +11 -0
  111. package/src/functions/compositions.ts +17 -0
  112. package/src/functions/debounce.ts +34 -0
  113. package/src/functions/executions.ts +12 -0
  114. package/src/functions/guards.ts +5 -0
  115. package/src/functions/index.ts +11 -0
  116. package/src/functions/memoize.ts +33 -0
  117. package/src/functions/once.ts +33 -0
  118. package/src/functions/pipe.ts +39 -0
  119. package/src/functions/throttle.ts +59 -0
  120. package/src/functions/timer-state.ts +33 -0
  121. package/src/functions/types.ts +8 -0
  122. package/src/index.ts +16 -0
  123. package/src/json-rpc/constants.ts +15 -0
  124. package/src/json-rpc/factories.ts +22 -0
  125. package/src/json-rpc/guards.ts +58 -0
  126. package/src/json-rpc/index.ts +5 -0
  127. package/src/json-rpc/types.ts +48 -0
  128. package/src/numbers/bigint-math.ts +163 -0
  129. package/src/numbers/constants.ts +14 -0
  130. package/src/numbers/conversions.ts +83 -0
  131. package/src/numbers/factories.ts +6 -0
  132. package/src/numbers/formats.ts +52 -0
  133. package/src/numbers/guards.ts +22 -0
  134. package/src/numbers/index.ts +10 -0
  135. package/src/numbers/maths.ts +28 -0
  136. package/src/numbers/ranges.ts +17 -0
  137. package/src/numbers/types.ts +7 -0
  138. package/src/objects/deep-merge.ts +76 -0
  139. package/src/objects/guards.ts +21 -0
  140. package/src/objects/index.ts +5 -0
  141. package/src/objects/transformations.ts +34 -0
  142. package/src/objects/types.ts +33 -0
  143. package/src/promises/abortable.ts +37 -0
  144. package/src/promises/compositions.ts +18 -0
  145. package/src/promises/deferred.ts +131 -0
  146. package/src/promises/guards.ts +8 -0
  147. package/src/promises/index.ts +10 -0
  148. package/src/promises/pipe.ts +39 -0
  149. package/src/promises/poll.ts +92 -0
  150. package/src/promises/retry.ts +138 -0
  151. package/src/promises/timers.ts +16 -0
  152. package/src/promises/types.ts +1 -0
  153. package/src/serializer/constants.ts +5 -0
  154. package/src/serializer/context.ts +24 -0
  155. package/src/serializer/index.ts +8 -0
  156. package/src/serializer/serialize.ts +51 -0
  157. package/src/serializer/serializers/array.ts +17 -0
  158. package/src/serializer/serializers/binary.ts +24 -0
  159. package/src/serializer/serializers/blob.ts +18 -0
  160. package/src/serializer/serializers/collection.ts +25 -0
  161. package/src/serializer/serializers/compound.ts +79 -0
  162. package/src/serializer/serializers/error.ts +75 -0
  163. package/src/serializer/serializers/function.ts +13 -0
  164. package/src/serializer/serializers/index.ts +12 -0
  165. package/src/serializer/serializers/leaf-object.ts +18 -0
  166. package/src/serializer/serializers/number.ts +14 -0
  167. package/src/serializer/serializers/object.ts +62 -0
  168. package/src/serializer/serializers/opaque.ts +36 -0
  169. package/src/serializer/serializers/primitive.ts +32 -0
  170. package/src/serializer/symbol-registry.ts +28 -0
  171. package/src/serializer/types.ts +42 -0
  172. package/src/serializer/utils.ts +15 -0
  173. package/src/strings/constants.ts +1 -0
  174. package/src/strings/factories.ts +9 -0
  175. package/src/strings/guards.ts +51 -0
  176. package/src/strings/index.ts +7 -0
  177. package/src/strings/manipulations.ts +145 -0
  178. package/src/strings/strip-ansi.ts +14 -0
  179. package/src/strings/types.ts +3 -0
  180. package/src/system/env.ts +32 -0
  181. package/src/system/fetch.ts +23 -0
  182. package/src/system/graceful-exit.ts +46 -0
  183. package/src/system/index.ts +6 -0
  184. package/src/system/path.ts +12 -0
  185. package/src/system/types.ts +3 -0
  186. package/src/times/constants.ts +6 -0
  187. package/src/times/conversions.ts +85 -0
  188. package/src/times/factories.ts +3 -0
  189. package/src/times/guards.ts +3 -0
  190. package/src/times/index.ts +5 -0
  191. package/src/times/operations.ts +9 -0
  192. package/CHANGELOG.md +0 -57
  193. package/arrays/index.d.ts.map +0 -1
  194. package/arrays/index.js +0 -4
  195. package/arrays/index.js.map +0 -9
  196. package/buffers/index.js +0 -4
  197. package/buffers/index.js.map +0 -9
  198. package/chunk-25ja9350.js +0 -4
  199. package/chunk-25ja9350.js.map +0 -13
  200. package/chunk-3w6nt7kb.js +0 -4
  201. package/chunk-3w6nt7kb.js.map +0 -12
  202. package/chunk-5txwcr6j.js +0 -4
  203. package/chunk-5txwcr6j.js.map +0 -17
  204. package/chunk-6dxad51h.js +0 -4
  205. package/chunk-6dxad51h.js.map +0 -12
  206. package/chunk-6kdnnxe0.js +0 -4
  207. package/chunk-6kdnnxe0.js.map +0 -17
  208. package/chunk-7cndek91.js +0 -4
  209. package/chunk-7cndek91.js.map +0 -15
  210. package/chunk-bee0nxse.js +0 -6
  211. package/chunk-bee0nxse.js.map +0 -14
  212. package/chunk-bjmntg2y.js +0 -4
  213. package/chunk-bjmntg2y.js.map +0 -18
  214. package/chunk-d0d0d285.js +0 -4
  215. package/chunk-d0d0d285.js.map +0 -26
  216. package/chunk-jny2gdyy.js +0 -4
  217. package/chunk-jny2gdyy.js.map +0 -12
  218. package/chunk-kbzgn0z4.js +0 -4
  219. package/chunk-kbzgn0z4.js.map +0 -10
  220. package/chunk-qmbgp0vr.js +0 -4
  221. package/chunk-qmbgp0vr.js.map +0 -12
  222. package/chunk-qn6n0ff5.js +0 -4
  223. package/chunk-qn6n0ff5.js.map +0 -17
  224. package/chunk-r3maskdb.js +0 -5
  225. package/chunk-r3maskdb.js.map +0 -13
  226. package/chunk-st3dxvqt.js +0 -4
  227. package/chunk-st3dxvqt.js.map +0 -14
  228. package/chunk-xp18wdk6.js +0 -4
  229. package/chunk-xp18wdk6.js.map +0 -12
  230. package/collections/index.js +0 -4
  231. package/collections/index.js.map +0 -9
  232. package/common/index.js +0 -4
  233. package/common/index.js.map +0 -9
  234. package/core/index.js +0 -4
  235. package/core/index.js.map +0 -9
  236. package/errors/index.js +0 -4
  237. package/errors/index.js.map +0 -9
  238. package/events/index.js +0 -4
  239. package/events/index.js.map +0 -9
  240. package/functions/index.js +0 -4
  241. package/functions/index.js.map +0 -9
  242. package/index.js +0 -4
  243. package/index.js.map +0 -9
  244. package/json-rpc/index.js +0 -4
  245. package/json-rpc/index.js.map +0 -9
  246. package/meta.json +0 -2998
  247. package/meta.md +0 -1816
  248. package/numbers/index.js +0 -4
  249. package/numbers/index.js.map +0 -9
  250. package/objects/index.js +0 -4
  251. package/objects/index.js.map +0 -9
  252. package/promises/index.js +0 -4
  253. package/promises/index.js.map +0 -9
  254. package/serializer/index.js +0 -4
  255. package/serializer/index.js.map +0 -9
  256. package/serializer/serializers/binary.d.ts.map +0 -1
  257. package/serializer/serializers/blob.d.ts.map +0 -1
  258. package/serializer/serializers/number.d.ts.map +0 -1
  259. package/serializer/serializers/opaque.d.ts.map +0 -1
  260. package/strings/index.js +0 -4
  261. package/strings/index.js.map +0 -9
  262. package/system/index.js +0 -4
  263. package/system/index.js.map +0 -9
  264. package/system/types.d.ts +0 -3
  265. package/times/index.js +0 -4
  266. package/times/index.js.map +0 -9
  267. /package/{arrays → dist/arrays}/accessors.d.ts +0 -0
  268. /package/{arrays → dist/arrays}/accessors.d.ts.map +0 -0
  269. /package/{arrays → dist/arrays}/conversions.d.ts +0 -0
  270. /package/{arrays → dist/arrays}/conversions.d.ts.map +0 -0
  271. /package/{arrays → dist/arrays}/factories.d.ts +0 -0
  272. /package/{arrays → dist/arrays}/factories.d.ts.map +0 -0
  273. /package/{arrays → dist/arrays}/guards.d.ts +0 -0
  274. /package/{arrays → dist/arrays}/guards.d.ts.map +0 -0
  275. /package/{arrays → dist/arrays}/operations.d.ts +0 -0
  276. /package/{arrays → dist/arrays}/operations.d.ts.map +0 -0
  277. /package/{arrays → dist/arrays}/set-operations.d.ts +0 -0
  278. /package/{arrays → dist/arrays}/set-operations.d.ts.map +0 -0
  279. /package/{arrays → dist/arrays}/types.d.ts +0 -0
  280. /package/{arrays → dist/arrays}/types.d.ts.map +0 -0
  281. /package/{buffers → dist/buffers}/conversions.d.ts +0 -0
  282. /package/{buffers → dist/buffers}/conversions.d.ts.map +0 -0
  283. /package/{buffers → dist/buffers}/guards.d.ts +0 -0
  284. /package/{buffers → dist/buffers}/guards.d.ts.map +0 -0
  285. /package/{buffers → dist/buffers}/index.d.ts +0 -0
  286. /package/{buffers → dist/buffers}/index.d.ts.map +0 -0
  287. /package/{buffers → dist/buffers}/operations.d.ts +0 -0
  288. /package/{buffers → dist/buffers}/operations.d.ts.map +0 -0
  289. /package/{buffers → dist/buffers}/types.d.ts +0 -0
  290. /package/{buffers → dist/buffers}/types.d.ts.map +0 -0
  291. /package/{collections → dist/collections}/fifo-map.d.ts +0 -0
  292. /package/{collections → dist/collections}/fifo-map.d.ts.map +0 -0
  293. /package/{collections → dist/collections}/fifo-set.d.ts +0 -0
  294. /package/{collections → dist/collections}/fifo-set.d.ts.map +0 -0
  295. /package/{collections → dist/collections}/guards.d.ts +0 -0
  296. /package/{collections → dist/collections}/guards.d.ts.map +0 -0
  297. /package/{collections → dist/collections}/index.d.ts +0 -0
  298. /package/{collections → dist/collections}/index.d.ts.map +0 -0
  299. /package/{collections → dist/collections}/linked-base.d.ts +0 -0
  300. /package/{collections → dist/collections}/linked-base.d.ts.map +0 -0
  301. /package/{collections → dist/collections}/linked-map.d.ts +0 -0
  302. /package/{collections → dist/collections}/linked-map.d.ts.map +0 -0
  303. /package/{collections → dist/collections}/linked-set.d.ts +0 -0
  304. /package/{collections → dist/collections}/linked-set.d.ts.map +0 -0
  305. /package/{collections → dist/collections}/lru-map.d.ts +0 -0
  306. /package/{collections → dist/collections}/lru-map.d.ts.map +0 -0
  307. /package/{collections → dist/collections}/lru-set.d.ts +0 -0
  308. /package/{collections → dist/collections}/lru-set.d.ts.map +0 -0
  309. /package/{collections → dist/collections}/types.d.ts +0 -0
  310. /package/{collections → dist/collections}/types.d.ts.map +0 -0
  311. /package/{common → dist/common}/guards.d.ts +0 -0
  312. /package/{common → dist/common}/guards.d.ts.map +0 -0
  313. /package/{common → dist/common}/index.d.ts +0 -0
  314. /package/{common → dist/common}/index.d.ts.map +0 -0
  315. /package/{common → dist/common}/transformations.d.ts +0 -0
  316. /package/{common → dist/common}/transformations.d.ts.map +0 -0
  317. /package/{core → dist/core}/constants.d.ts +0 -0
  318. /package/{core → dist/core}/constants.d.ts.map +0 -0
  319. /package/{core → dist/core}/conversions.d.ts +0 -0
  320. /package/{core → dist/core}/conversions.d.ts.map +0 -0
  321. /package/{core → dist/core}/guards.d.ts +0 -0
  322. /package/{core → dist/core}/guards.d.ts.map +0 -0
  323. /package/{core → dist/core}/index.d.ts +0 -0
  324. /package/{core → dist/core}/index.d.ts.map +0 -0
  325. /package/{core → dist/core}/types.d.ts +0 -0
  326. /package/{core → dist/core}/types.d.ts.map +0 -0
  327. /package/{errors → dist/errors}/base-error.d.ts +0 -0
  328. /package/{errors → dist/errors}/base-error.d.ts.map +0 -0
  329. /package/{errors → dist/errors}/factories.d.ts +0 -0
  330. /package/{errors → dist/errors}/factories.d.ts.map +0 -0
  331. /package/{errors → dist/errors}/guards.d.ts +0 -0
  332. /package/{errors → dist/errors}/guards.d.ts.map +0 -0
  333. /package/{errors → dist/errors}/index.d.ts +0 -0
  334. /package/{errors → dist/errors}/index.d.ts.map +0 -0
  335. /package/{errors → dist/errors}/operations.d.ts +0 -0
  336. /package/{errors → dist/errors}/operations.d.ts.map +0 -0
  337. /package/{errors → dist/errors}/stringify.d.ts +0 -0
  338. /package/{errors → dist/errors}/stringify.d.ts.map +0 -0
  339. /package/{errors → dist/errors}/types.d.ts +0 -0
  340. /package/{errors → dist/errors}/types.d.ts.map +0 -0
  341. /package/{events → dist/events}/emitter.d.ts +0 -0
  342. /package/{events → dist/events}/emitter.d.ts.map +0 -0
  343. /package/{events → dist/events}/index.d.ts +0 -0
  344. /package/{events → dist/events}/index.d.ts.map +0 -0
  345. /package/{events → dist/events}/types.d.ts +0 -0
  346. /package/{events → dist/events}/types.d.ts.map +0 -0
  347. /package/{functions → dist/functions}/compositions.d.ts +0 -0
  348. /package/{functions → dist/functions}/compositions.d.ts.map +0 -0
  349. /package/{functions → dist/functions}/debounce.d.ts +0 -0
  350. /package/{functions → dist/functions}/debounce.d.ts.map +0 -0
  351. /package/{functions → dist/functions}/guards.d.ts +0 -0
  352. /package/{functions → dist/functions}/guards.d.ts.map +0 -0
  353. /package/{functions → dist/functions}/index.d.ts +0 -0
  354. /package/{functions → dist/functions}/index.d.ts.map +0 -0
  355. /package/{functions → dist/functions}/memoize.d.ts +0 -0
  356. /package/{functions → dist/functions}/memoize.d.ts.map +0 -0
  357. /package/{functions → dist/functions}/once.d.ts +0 -0
  358. /package/{functions → dist/functions}/once.d.ts.map +0 -0
  359. /package/{functions → dist/functions}/pipe.d.ts +0 -0
  360. /package/{functions → dist/functions}/pipe.d.ts.map +0 -0
  361. /package/{functions → dist/functions}/throttle.d.ts +0 -0
  362. /package/{functions → dist/functions}/throttle.d.ts.map +0 -0
  363. /package/{functions → dist/functions}/timer-state.d.ts +0 -0
  364. /package/{functions → dist/functions}/timer-state.d.ts.map +0 -0
  365. /package/{functions → dist/functions}/types.d.ts +0 -0
  366. /package/{functions → dist/functions}/types.d.ts.map +0 -0
  367. /package/{index.d.ts → dist/index.d.ts} +0 -0
  368. /package/{index.d.ts.map → dist/index.d.ts.map} +0 -0
  369. /package/{json-rpc → dist/json-rpc}/constants.d.ts +0 -0
  370. /package/{json-rpc → dist/json-rpc}/constants.d.ts.map +0 -0
  371. /package/{json-rpc → dist/json-rpc}/factories.d.ts +0 -0
  372. /package/{json-rpc → dist/json-rpc}/factories.d.ts.map +0 -0
  373. /package/{json-rpc → dist/json-rpc}/guards.d.ts +0 -0
  374. /package/{json-rpc → dist/json-rpc}/guards.d.ts.map +0 -0
  375. /package/{json-rpc → dist/json-rpc}/index.d.ts +0 -0
  376. /package/{json-rpc → dist/json-rpc}/index.d.ts.map +0 -0
  377. /package/{json-rpc → dist/json-rpc}/types.d.ts +0 -0
  378. /package/{json-rpc → dist/json-rpc}/types.d.ts.map +0 -0
  379. /package/{numbers → dist/numbers}/bigint-math.d.ts +0 -0
  380. /package/{numbers → dist/numbers}/bigint-math.d.ts.map +0 -0
  381. /package/{numbers → dist/numbers}/constants.d.ts +0 -0
  382. /package/{numbers → dist/numbers}/constants.d.ts.map +0 -0
  383. /package/{numbers → dist/numbers}/conversions.d.ts +0 -0
  384. /package/{numbers → dist/numbers}/conversions.d.ts.map +0 -0
  385. /package/{numbers → dist/numbers}/factories.d.ts +0 -0
  386. /package/{numbers → dist/numbers}/factories.d.ts.map +0 -0
  387. /package/{numbers → dist/numbers}/formats.d.ts +0 -0
  388. /package/{numbers → dist/numbers}/formats.d.ts.map +0 -0
  389. /package/{numbers → dist/numbers}/guards.d.ts +0 -0
  390. /package/{numbers → dist/numbers}/guards.d.ts.map +0 -0
  391. /package/{numbers → dist/numbers}/index.d.ts +0 -0
  392. /package/{numbers → dist/numbers}/index.d.ts.map +0 -0
  393. /package/{numbers → dist/numbers}/maths.d.ts +0 -0
  394. /package/{numbers → dist/numbers}/maths.d.ts.map +0 -0
  395. /package/{numbers → dist/numbers}/ranges.d.ts +0 -0
  396. /package/{numbers → dist/numbers}/ranges.d.ts.map +0 -0
  397. /package/{numbers → dist/numbers}/types.d.ts +0 -0
  398. /package/{numbers → dist/numbers}/types.d.ts.map +0 -0
  399. /package/{objects → dist/objects}/deep-merge.d.ts +0 -0
  400. /package/{objects → dist/objects}/deep-merge.d.ts.map +0 -0
  401. /package/{objects → dist/objects}/guards.d.ts +0 -0
  402. /package/{objects → dist/objects}/guards.d.ts.map +0 -0
  403. /package/{objects → dist/objects}/index.d.ts +0 -0
  404. /package/{objects → dist/objects}/index.d.ts.map +0 -0
  405. /package/{promises → dist/promises}/abortable.d.ts +0 -0
  406. /package/{promises → dist/promises}/abortable.d.ts.map +0 -0
  407. /package/{promises → dist/promises}/compositions.d.ts +0 -0
  408. /package/{promises → dist/promises}/compositions.d.ts.map +0 -0
  409. /package/{promises → dist/promises}/guards.d.ts +0 -0
  410. /package/{promises → dist/promises}/guards.d.ts.map +0 -0
  411. /package/{promises → dist/promises}/index.d.ts +0 -0
  412. /package/{promises → dist/promises}/index.d.ts.map +0 -0
  413. /package/{promises → dist/promises}/pipe.d.ts +0 -0
  414. /package/{promises → dist/promises}/pipe.d.ts.map +0 -0
  415. /package/{promises → dist/promises}/poll.d.ts +0 -0
  416. /package/{promises → dist/promises}/poll.d.ts.map +0 -0
  417. /package/{promises → dist/promises}/retry.d.ts +0 -0
  418. /package/{promises → dist/promises}/retry.d.ts.map +0 -0
  419. /package/{promises → dist/promises}/types.d.ts +0 -0
  420. /package/{promises → dist/promises}/types.d.ts.map +0 -0
  421. /package/{serializer → dist/serializer}/constants.d.ts +0 -0
  422. /package/{serializer → dist/serializer}/constants.d.ts.map +0 -0
  423. /package/{serializer → dist/serializer}/index.d.ts +0 -0
  424. /package/{serializer → dist/serializer}/index.d.ts.map +0 -0
  425. /package/{serializer → dist/serializer}/serializers/index.d.ts +0 -0
  426. /package/{serializer → dist/serializer}/serializers/index.d.ts.map +0 -0
  427. /package/{serializer → dist/serializer}/symbol-registry.d.ts +0 -0
  428. /package/{serializer → dist/serializer}/symbol-registry.d.ts.map +0 -0
  429. /package/{strings → dist/strings}/constants.d.ts +0 -0
  430. /package/{strings → dist/strings}/constants.d.ts.map +0 -0
  431. /package/{strings → dist/strings}/factories.d.ts +0 -0
  432. /package/{strings → dist/strings}/factories.d.ts.map +0 -0
  433. /package/{strings → dist/strings}/guards.d.ts +0 -0
  434. /package/{strings → dist/strings}/guards.d.ts.map +0 -0
  435. /package/{strings → dist/strings}/types.d.ts +0 -0
  436. /package/{strings → dist/strings}/types.d.ts.map +0 -0
  437. /package/{system → dist/system}/env.d.ts +0 -0
  438. /package/{system → dist/system}/env.d.ts.map +0 -0
  439. /package/{system → dist/system}/graceful-exit.d.ts +0 -0
  440. /package/{system → dist/system}/graceful-exit.d.ts.map +0 -0
  441. /package/{system → dist/system}/index.d.ts +0 -0
  442. /package/{system → dist/system}/index.d.ts.map +0 -0
  443. /package/{system → dist/system}/path.d.ts +0 -0
  444. /package/{system → dist/system}/path.d.ts.map +0 -0
  445. /package/{times → dist/times}/constants.d.ts +0 -0
  446. /package/{times → dist/times}/constants.d.ts.map +0 -0
  447. /package/{times → dist/times}/factories.d.ts +0 -0
  448. /package/{times → dist/times}/factories.d.ts.map +0 -0
  449. /package/{times → dist/times}/guards.d.ts +0 -0
  450. /package/{times → dist/times}/guards.d.ts.map +0 -0
  451. /package/{times → dist/times}/index.d.ts +0 -0
  452. /package/{times → dist/times}/index.d.ts.map +0 -0
  453. /package/{times → dist/times}/operations.d.ts +0 -0
  454. /package/{times → dist/times}/operations.d.ts.map +0 -0
@@ -0,0 +1,103 @@
1
+ import type { Nullable } from '../core'
2
+ import type { MaybeArray } from './types'
3
+ import { toArray } from './conversions'
4
+
5
+ export const merge = <T>(...arrays: Array<Nullable<MaybeArray<T>>>) => arrays.flatMap((array) => toArray(array))
6
+
7
+ export const flatten = <T>(array?: Nullable<MaybeArray<T | T[]>>) => toArray(array).flat() as T[]
8
+
9
+ export function shuffle<T>(array: T[]): T[] {
10
+ const result = [...array]
11
+
12
+ for (let i = result.length - 1; i > 0; i--) {
13
+ const j = Math.floor(Math.random() * (i + 1))
14
+ const temp = result[i]
15
+
16
+ result[i] = result[j]!
17
+ result[j] = temp!
18
+ }
19
+
20
+ return result
21
+ }
22
+
23
+ export function groupBy<T, K extends PropertyKey>(array: T[], keyFn: (item: T) => K): Record<K, T[]> {
24
+ const result = {} as Record<K, T[]>
25
+
26
+ for (const item of array) {
27
+ const key = keyFn(item)
28
+ const group = result[key]
29
+
30
+ if (group) {
31
+ group.push(item)
32
+ } else {
33
+ result[key] = [item]
34
+ }
35
+ }
36
+
37
+ return result
38
+ }
39
+
40
+ export function keyBy<T, K extends PropertyKey>(array: T[], keyFn: (item: T) => K): Record<K, T> {
41
+ const result = {} as Record<K, T>
42
+
43
+ for (const item of array) {
44
+ result[keyFn(item)] = item
45
+ }
46
+
47
+ return result
48
+ }
49
+
50
+ export function chunk<T>(array: T[], size: number): T[][] {
51
+ if (size <= 0 || !Number.isFinite(size)) {
52
+ throw new RangeError(`chunk size must be a positive finite number, got ${size}`)
53
+ }
54
+
55
+ const step = Math.floor(size)
56
+ const result: T[][] = []
57
+
58
+ for (let i = 0; i < array.length; i += step) {
59
+ result.push(array.slice(i, i + step))
60
+ }
61
+
62
+ return result
63
+ }
64
+
65
+ export type SortDirection = 'asc' | 'desc'
66
+
67
+ export type SortKey<T> = ((item: T) => number | string) | { fn: (item: T) => number | string, order: SortDirection }
68
+
69
+ export function sortBy<T>(array: T[], ...keys: Array<SortKey<T>>): T[] {
70
+ const normalizedKeys = keys.map((key) => (typeof key === 'function' ? { fn: key, order: 'asc' as const } : key))
71
+
72
+ return array.toSorted((a, b) => {
73
+ for (const { fn, order } of normalizedKeys) {
74
+ const va = fn(a)
75
+ const vb = fn(b)
76
+
77
+ if (va < vb) {
78
+ return order === 'asc' ? -1 : 1
79
+ }
80
+
81
+ if (va > vb) {
82
+ return order === 'asc' ? 1 : -1
83
+ }
84
+ }
85
+
86
+ return 0
87
+ })
88
+ }
89
+
90
+ export function partition<T>(array: T[], predicate: (item: T) => boolean): [T[], T[]] {
91
+ const pass: T[] = []
92
+ const fail: T[] = []
93
+
94
+ for (const item of array) {
95
+ if (predicate(item)) {
96
+ pass.push(item)
97
+ } else {
98
+ fail.push(item)
99
+ }
100
+ }
101
+
102
+ return [pass, fail]
103
+ }
@@ -0,0 +1,11 @@
1
+ export const unique = <T>(array: T[]) => [...new Set(array)]
2
+
3
+ export const uniqueBy = <T>(array: T[], equalFn: (a: T, b: T) => boolean) => (
4
+ array.reduce<T[]>((r, c) => (r.some((v) => equalFn(v, c)) ? r : [...r, c]), [])
5
+ )
6
+
7
+ export const intersection = <T>(a: T[], b: T[]) => a.filter((v) => b.includes(v))
8
+
9
+ export const diff = <T>(a: T[], b: T[]) => a.filter((v) => !b.includes(v))
10
+
11
+ export const symmetricDiff = <T>(a: T[], b: T[]) => [...diff(a, b), ...diff(b, a)]
@@ -0,0 +1,21 @@
1
+ export type MaybeArray<T> = Iterable<T> | T | T[]
2
+
3
+ export type EmptyArray = []
4
+
5
+ export type NonEmptyArray<T> = [T, ...T[]]
6
+
7
+ export type ElementOf<T> = T extends Array<infer E> ? E : never
8
+
9
+ export type Head<T extends readonly unknown[]> = T extends readonly [infer H, ...unknown[]] ? H : never
10
+
11
+ export type Tail<T extends readonly unknown[]> = T extends readonly [unknown, ...infer R] ? R : []
12
+
13
+ export type Last<T extends readonly unknown[]> = T extends readonly [...unknown[], infer L] ? L : never
14
+
15
+ export type Flatten<T extends readonly unknown[]> = T extends ReadonlyArray<infer U> ? U extends ReadonlyArray<infer V> ? V[] : U[] : never
16
+
17
+ export type TupleToUnion<T extends readonly unknown[]> = T[number]
18
+
19
+ export type FixedLength<T, N extends number, R extends T[] = []> = R['length'] extends N ? R : FixedLength<T, N, [...R, T]>
20
+
21
+ export type ReadonlyNonEmptyArray<T> = readonly [T, ...T[]]
@@ -0,0 +1,26 @@
1
+ import type { BufferLike } from './types'
2
+ import { isArrayBuffer, isBuffer, isSharedArrayBuffer } from './guards'
3
+
4
+ export function bufferToString(buffer: BufferLike, encoding: BufferEncoding = 'utf8') {
5
+ if (isBuffer(buffer)) {
6
+ return buffer.toString(encoding)
7
+ }
8
+
9
+ if (isArrayBuffer(buffer) || isSharedArrayBuffer(buffer)) {
10
+ return Buffer.from(buffer).toString(encoding)
11
+ }
12
+
13
+ return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength).toString(encoding)
14
+ }
15
+
16
+ export function toUint8Array(input: BufferLike) {
17
+ if (input instanceof Uint8Array) {
18
+ return input
19
+ }
20
+
21
+ if (input instanceof ArrayBuffer || input instanceof SharedArrayBuffer) {
22
+ return new Uint8Array(input)
23
+ }
24
+
25
+ return new Uint8Array(input.buffer, input.byteOffset, input.byteLength)
26
+ }
@@ -0,0 +1,13 @@
1
+ import type { BufferLike } from './types'
2
+
3
+ export const isBuffer = (value: unknown): value is Buffer => Buffer.isBuffer(value)
4
+
5
+ export const isArrayBuffer = (value: unknown): value is ArrayBuffer => value instanceof ArrayBuffer
6
+
7
+ export const isSharedArrayBuffer = (value: unknown): value is SharedArrayBuffer => value instanceof SharedArrayBuffer
8
+
9
+ export const isArrayBufferView = (value: unknown): value is ArrayBufferView => ArrayBuffer.isView(value)
10
+
11
+ export const isBufferLike = (value: unknown): value is BufferLike => (
12
+ isBuffer(value) || isArrayBuffer(value) || isSharedArrayBuffer(value) || isArrayBufferView(value)
13
+ )
@@ -0,0 +1,5 @@
1
+ export * from './conversions'
2
+ export * from './guards'
3
+ export * from './operations'
4
+
5
+ export type * from './types'
@@ -0,0 +1,44 @@
1
+ import type { BufferLike } from './types'
2
+ import { toUint8Array } from './conversions'
3
+
4
+ export function concatBuffers(buffers: BufferLike[]) {
5
+ if (buffers.length === 0) {
6
+ return new Uint8Array(0)
7
+ }
8
+
9
+ const normalized = buffers.map(toUint8Array)
10
+
11
+ let totalLength = 0
12
+ let offset = 0
13
+
14
+ for (const buf of normalized) {
15
+ totalLength += buf.byteLength
16
+ }
17
+
18
+ const result = new Uint8Array(totalLength)
19
+
20
+ for (const buf of normalized) {
21
+ result.set(buf, offset)
22
+ offset += buf.byteLength
23
+ }
24
+
25
+ return result
26
+ }
27
+
28
+ export function bufferEquals(a: BufferLike, b: BufferLike) {
29
+ if (a === b) {
30
+ return true
31
+ }
32
+
33
+ const u8a = toUint8Array(a)
34
+ const u8b = toUint8Array(b)
35
+
36
+ if (u8a.byteLength !== u8b.byteLength) {
37
+ return false
38
+ }
39
+
40
+ const bufA = Buffer.from(u8a.buffer, u8a.byteOffset, u8a.byteLength)
41
+ const bufB = Buffer.from(u8b.buffer, u8b.byteOffset, u8b.byteLength)
42
+
43
+ return bufA.equals(bufB)
44
+ }
@@ -0,0 +1 @@
1
+ export type BufferLike = ArrayBuffer | ArrayBufferView | Buffer | SharedArrayBuffer
@@ -0,0 +1,33 @@
1
+ import { LinkedMap } from './linked-map'
2
+
3
+ export class FifoMap<K, V> extends LinkedMap<K, V> {
4
+ public override peekNewest(): [K, V] | undefined {
5
+ return this.tail ? [this.tail.key, this.tail.value] : undefined
6
+ }
7
+
8
+ public override peekOldest(): [K, V] | undefined {
9
+ return this.head ? [this.head.key, this.head.value] : undefined
10
+ }
11
+
12
+ public set(key: K, value: V): this {
13
+ const existingNode = this.nodeMap.get(key)
14
+
15
+ if (existingNode) {
16
+ existingNode.value = value
17
+
18
+ return this
19
+ }
20
+
21
+ const newNode = this.createNode(key, value)
22
+
23
+ this.nodeMap.set(key, newNode)
24
+ this.addToTail(newNode)
25
+ this.currentSize++
26
+
27
+ if (this.maxSize && this.currentSize > this.maxSize) {
28
+ this.removeHead()
29
+ }
30
+
31
+ return this
32
+ }
33
+ }
@@ -0,0 +1,29 @@
1
+ import { LinkedSet } from './linked-set'
2
+
3
+ export class FifoSet<T> extends LinkedSet<T> {
4
+ public add(value: T): this {
5
+ if (this.nodeMap.has(value)) {
6
+ return this
7
+ }
8
+
9
+ const newNode = this.createNode(value)
10
+
11
+ this.nodeMap.set(value, newNode)
12
+ this.addToTail(newNode)
13
+ this.currentSize++
14
+
15
+ if (this.maxSize && this.currentSize > this.maxSize) {
16
+ this.removeHead()
17
+ }
18
+
19
+ return this
20
+ }
21
+
22
+ public override peekOldest(): T | undefined {
23
+ return this.head?.value
24
+ }
25
+
26
+ public override peekNewest(): T | undefined {
27
+ return this.tail?.value
28
+ }
29
+ }
@@ -0,0 +1,11 @@
1
+ import type { CollectionLike, MapLike, SetLike } from './types'
2
+
3
+ export const isIterable = <T>(value: unknown): value is Iterable<T> => value != null && typeof value === 'object' && Symbol.iterator in value && typeof value[Symbol.iterator] === 'function'
4
+
5
+ export const isCollectionLike = <T>(value: unknown): value is CollectionLike<T> => isIterable(value) && 'size' in value && typeof value.size === 'number'
6
+
7
+ export const isEmptyCollection = (value: CollectionLike) => value.size === 0
8
+
9
+ export const isSetLike = <T>(value: unknown): value is SetLike<T> => isCollectionLike(value) && 'has' in value && typeof value.has === 'function'
10
+
11
+ export const isMapLike = <K, V>(value: unknown): value is MapLike<K, V> => isCollectionLike(value) && 'get' in value && typeof value.get === 'function' && 'entries' in value && typeof value.entries === 'function'
@@ -0,0 +1,10 @@
1
+ export * from './fifo-map'
2
+ export * from './fifo-set'
3
+ export * from './guards'
4
+ export * from './linked-base'
5
+ export * from './linked-map'
6
+ export * from './linked-set'
7
+ export * from './lru-map'
8
+ export * from './lru-set'
9
+
10
+ export type * from './types'
@@ -0,0 +1,117 @@
1
+ export interface LinkedBaseNode {
2
+ next: LinkedBaseNode | null
3
+ prev: LinkedBaseNode | null
4
+ }
5
+
6
+ export abstract class LinkedBase<NodeKey, N extends LinkedBaseNode> {
7
+ protected readonly nodeMap = new Map<NodeKey, N>()
8
+
9
+ protected currentSize = 0
10
+ protected head: N | null = null
11
+ protected tail: N | null = null
12
+
13
+ public constructor(public readonly maxSize?: number) {
14
+ if (maxSize != null && (maxSize < 1 || !Number.isInteger(maxSize))) {
15
+ throw new RangeError('maxSize must be a positive integer')
16
+ }
17
+ }
18
+
19
+ public get size() {
20
+ return this.currentSize
21
+ }
22
+
23
+ public get [Symbol.toStringTag]() {
24
+ return this.constructor.name
25
+ }
26
+
27
+ public clear() {
28
+ this.nodeMap.clear()
29
+ this.head = null
30
+ this.tail = null
31
+ this.currentSize = 0
32
+ }
33
+
34
+ protected abstract getNodeKey(node: N): NodeKey
35
+
36
+ protected addToHead(node: N) {
37
+ node.prev = null
38
+ node.next = this.head
39
+
40
+ if (this.head) {
41
+ this.head.prev = node
42
+ } else {
43
+ this.tail = node
44
+ }
45
+
46
+ this.head = node
47
+ }
48
+
49
+ protected addToTail(node: N) {
50
+ node.next = null
51
+ node.prev = this.tail
52
+
53
+ if (this.tail) {
54
+ this.tail.next = node
55
+ } else {
56
+ this.head = node
57
+ }
58
+
59
+ this.tail = node
60
+ }
61
+
62
+ protected deleteByKey(key: NodeKey) {
63
+ const node = this.nodeMap.get(key)
64
+
65
+ if (!node) {
66
+ return false
67
+ }
68
+
69
+ this.nodeMap.delete(key)
70
+ this.removeNode(node)
71
+ this.currentSize--
72
+
73
+ return true
74
+ }
75
+
76
+ protected moveToHead(node: N) {
77
+ this.removeNode(node)
78
+ this.addToHead(node)
79
+ }
80
+
81
+ protected removeHead() {
82
+ if (!this.head) {
83
+ return
84
+ }
85
+
86
+ this.nodeMap.delete(this.getNodeKey(this.head))
87
+ this.removeNode(this.head)
88
+ this.currentSize--
89
+ }
90
+
91
+ protected removeNode(node: N) {
92
+ if (node.prev) {
93
+ node.prev.next = node.next
94
+ } else {
95
+ this.head = node.next as N | null
96
+ }
97
+
98
+ if (node.next) {
99
+ node.next.prev = node.prev
100
+ } else {
101
+ this.tail = node.prev as N | null
102
+ }
103
+
104
+ node.prev = null
105
+ node.next = null
106
+ }
107
+
108
+ protected removeTail() {
109
+ if (!this.tail) {
110
+ return
111
+ }
112
+
113
+ this.nodeMap.delete(this.getNodeKey(this.tail))
114
+ this.removeNode(this.tail)
115
+ this.currentSize--
116
+ }
117
+ }
@@ -0,0 +1,82 @@
1
+ import type { MapLike } from './types'
2
+ import { LinkedBase, type LinkedBaseNode } from './linked-base'
3
+
4
+ export interface LinkedMapNode<K, V> extends LinkedBaseNode {
5
+ key: K
6
+ next: LinkedMapNode<K, V> | null
7
+ prev: LinkedMapNode<K, V> | null
8
+ value: V
9
+ }
10
+
11
+ export abstract class LinkedMap<K, V> extends LinkedBase<K, LinkedMapNode<K, V>> implements MapLike<K, V> {
12
+ public delete(key: K) {
13
+ return this.deleteByKey(key)
14
+ }
15
+
16
+ public * entries(): IterableIterator<[K, V]> {
17
+ let current = this.head
18
+
19
+ while (current) {
20
+ yield [current.key, current.value]
21
+ current = current.next
22
+ }
23
+ }
24
+
25
+ public forEach(callback: (value: V, key: K, map: this) => void) {
26
+ for (const [key, value] of this.entries()) {
27
+ callback(value, key, this)
28
+ }
29
+ }
30
+
31
+ public get(key: K) {
32
+ return this.nodeMap.get(key)?.value
33
+ }
34
+
35
+ public has(key: K) {
36
+ return this.nodeMap.has(key)
37
+ }
38
+
39
+ public * keys(): IterableIterator<K> {
40
+ let current = this.head
41
+
42
+ while (current) {
43
+ yield current.key
44
+ current = current.next
45
+ }
46
+ }
47
+
48
+ public peekNewest(): [K, V] | undefined {
49
+ return this.head ? [this.head.key, this.head.value] : undefined
50
+ }
51
+
52
+ public peekOldest(): [K, V] | undefined {
53
+ return this.tail ? [this.tail.key, this.tail.value] : undefined
54
+ }
55
+
56
+ public abstract set(key: K, value: V): this
57
+
58
+ public [Symbol.iterator](): IterableIterator<[K, V]> {
59
+ return this.entries()
60
+ }
61
+
62
+ public toJSON(): Array<[K, V]> {
63
+ return [...this.entries()]
64
+ }
65
+
66
+ public * values(): IterableIterator<V> {
67
+ let current = this.head
68
+
69
+ while (current) {
70
+ yield current.value
71
+ current = current.next
72
+ }
73
+ }
74
+
75
+ protected createNode(key: K, value: V): LinkedMapNode<K, V> {
76
+ return { key, next: null, prev: null, value }
77
+ }
78
+
79
+ protected getNodeKey(node: LinkedMapNode<K, V>) {
80
+ return node.key
81
+ }
82
+ }
@@ -0,0 +1,69 @@
1
+ import type { SetLike } from './types'
2
+ import { LinkedBase, type LinkedBaseNode } from './linked-base'
3
+
4
+ export interface LinkedSetNode<T> extends LinkedBaseNode {
5
+ next: LinkedSetNode<T> | null
6
+ prev: LinkedSetNode<T> | null
7
+ value: T
8
+ }
9
+
10
+ export abstract class LinkedSet<T> extends LinkedBase<T, LinkedSetNode<T>> implements SetLike<T> {
11
+ public abstract add(value: T): this
12
+
13
+ public delete(value: T) {
14
+ return this.deleteByKey(value)
15
+ }
16
+
17
+ public * entries(): IterableIterator<[T, T]> {
18
+ for (const value of this.values()) {
19
+ yield [value, value]
20
+ }
21
+ }
22
+
23
+ public forEach(callback: (value: T, value2: T, set: this) => void) {
24
+ for (const value of this.values()) {
25
+ callback(value, value, this)
26
+ }
27
+ }
28
+
29
+ public has(value: T) {
30
+ return this.nodeMap.has(value)
31
+ }
32
+
33
+ public keys() {
34
+ return this.values()
35
+ }
36
+
37
+ public peekNewest(): T | undefined {
38
+ return this.head?.value
39
+ }
40
+
41
+ public peekOldest(): T | undefined {
42
+ return this.tail?.value
43
+ }
44
+
45
+ public [Symbol.iterator]() {
46
+ return this.values()
47
+ }
48
+
49
+ public toJSON(): T[] {
50
+ return [...this.values()]
51
+ }
52
+
53
+ public * values(): IterableIterator<T> {
54
+ let current = this.head
55
+
56
+ while (current) {
57
+ yield current.value
58
+ current = current.next
59
+ }
60
+ }
61
+
62
+ protected createNode(value: T): LinkedSetNode<T> {
63
+ return { next: null, prev: null, value }
64
+ }
65
+
66
+ protected getNodeKey(node: LinkedSetNode<T>) {
67
+ return node.value
68
+ }
69
+ }
@@ -0,0 +1,36 @@
1
+ import { LinkedMap } from './linked-map'
2
+
3
+ export class LruMap<K, V> extends LinkedMap<K, V> {
4
+ public override get(key: K) {
5
+ const node = this.nodeMap.get(key)
6
+
7
+ if (node) {
8
+ this.moveToHead(node)
9
+ }
10
+
11
+ return node?.value
12
+ }
13
+
14
+ public set(key: K, value: V): this {
15
+ const existingNode = this.nodeMap.get(key)
16
+
17
+ if (existingNode) {
18
+ existingNode.value = value
19
+ this.moveToHead(existingNode)
20
+
21
+ return this
22
+ }
23
+
24
+ const newNode = this.createNode(key, value)
25
+
26
+ this.nodeMap.set(key, newNode)
27
+ this.addToHead(newNode)
28
+ this.currentSize++
29
+
30
+ if (this.maxSize && this.currentSize > this.maxSize) {
31
+ this.removeTail()
32
+ }
33
+
34
+ return this
35
+ }
36
+ }
@@ -0,0 +1,25 @@
1
+ import { LinkedSet } from './linked-set'
2
+
3
+ export class LruSet<T> extends LinkedSet<T> {
4
+ public add(value: T): this {
5
+ const existingNode = this.nodeMap.get(value)
6
+
7
+ if (existingNode) {
8
+ this.moveToHead(existingNode)
9
+
10
+ return this
11
+ }
12
+
13
+ const newNode = this.createNode(value)
14
+
15
+ this.nodeMap.set(value, newNode)
16
+ this.addToHead(newNode)
17
+ this.currentSize++
18
+
19
+ if (this.maxSize && this.currentSize > this.maxSize) {
20
+ this.removeTail()
21
+ }
22
+
23
+ return this
24
+ }
25
+ }
@@ -0,0 +1,12 @@
1
+ export type CollectionLike<T = unknown> = Iterable<T> & {
2
+ readonly size: number
3
+ }
4
+
5
+ export type SetLike<T = unknown> = CollectionLike<T> & {
6
+ has(value: T): boolean
7
+ }
8
+
9
+ export type MapLike<K = unknown, V = unknown> = CollectionLike<[K, V]> & {
10
+ entries(): Iterable<[K, V]>
11
+ get(key: K): V | undefined
12
+ }
@@ -0,0 +1,11 @@
1
+ import { ensureError, type Errorable, type ErrorCtor } from '../errors'
2
+
3
+ export function assert(condition: unknown, message: Errorable, ctor?: ErrorCtor): asserts condition {
4
+ if (!condition) {
5
+ throw ensureError(message, ctor)
6
+ }
7
+ }
8
+
9
+ export function assertParam(condition: unknown, message: Errorable, ctor?: ErrorCtor): asserts condition {
10
+ assert(condition, message, ctor ?? TypeError)
11
+ }