@vielzeug/toolkit 1.0.11

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 (422) hide show
  1. package/dist/array/aggregate.cjs +2 -0
  2. package/dist/array/aggregate.cjs.map +1 -0
  3. package/dist/array/aggregate.js +16 -0
  4. package/dist/array/aggregate.js.map +1 -0
  5. package/dist/array/alternate.cjs +2 -0
  6. package/dist/array/alternate.cjs.map +1 -0
  7. package/dist/array/alternate.js +9 -0
  8. package/dist/array/alternate.js.map +1 -0
  9. package/dist/array/chunk.cjs +2 -0
  10. package/dist/array/chunk.cjs.map +1 -0
  11. package/dist/array/chunk.js +22 -0
  12. package/dist/array/chunk.js.map +1 -0
  13. package/dist/array/compact.cjs +2 -0
  14. package/dist/array/compact.cjs.map +1 -0
  15. package/dist/array/compact.js +9 -0
  16. package/dist/array/compact.js.map +1 -0
  17. package/dist/array/contains.cjs +2 -0
  18. package/dist/array/contains.cjs.map +1 -0
  19. package/dist/array/contains.js +11 -0
  20. package/dist/array/contains.js.map +1 -0
  21. package/dist/array/every.cjs +2 -0
  22. package/dist/array/every.cjs.map +1 -0
  23. package/dist/array/every.js +14 -0
  24. package/dist/array/every.js.map +1 -0
  25. package/dist/array/filter.cjs +2 -0
  26. package/dist/array/filter.cjs.map +1 -0
  27. package/dist/array/filter.js +14 -0
  28. package/dist/array/filter.js.map +1 -0
  29. package/dist/array/find.cjs +2 -0
  30. package/dist/array/find.cjs.map +1 -0
  31. package/dist/array/find.js +14 -0
  32. package/dist/array/find.js.map +1 -0
  33. package/dist/array/findIndex.cjs +2 -0
  34. package/dist/array/findIndex.cjs.map +1 -0
  35. package/dist/array/findIndex.js +14 -0
  36. package/dist/array/findIndex.js.map +1 -0
  37. package/dist/array/findLast.cjs +2 -0
  38. package/dist/array/findLast.cjs.map +1 -0
  39. package/dist/array/findLast.js +14 -0
  40. package/dist/array/findLast.js.map +1 -0
  41. package/dist/array/flatten.cjs +2 -0
  42. package/dist/array/flatten.cjs.map +1 -0
  43. package/dist/array/flatten.js +7 -0
  44. package/dist/array/flatten.js.map +1 -0
  45. package/dist/array/group.cjs +2 -0
  46. package/dist/array/group.cjs.map +1 -0
  47. package/dist/array/group.js +16 -0
  48. package/dist/array/group.js.map +1 -0
  49. package/dist/array/list.cjs +2 -0
  50. package/dist/array/list.cjs.map +1 -0
  51. package/dist/array/list.js +70 -0
  52. package/dist/array/list.js.map +1 -0
  53. package/dist/array/map.cjs +2 -0
  54. package/dist/array/map.cjs.map +1 -0
  55. package/dist/array/map.js +18 -0
  56. package/dist/array/map.js.map +1 -0
  57. package/dist/array/pick.cjs +2 -0
  58. package/dist/array/pick.cjs.map +1 -0
  59. package/dist/array/pick.js +15 -0
  60. package/dist/array/pick.js.map +1 -0
  61. package/dist/array/reduce.cjs +2 -0
  62. package/dist/array/reduce.cjs.map +1 -0
  63. package/dist/array/reduce.js +16 -0
  64. package/dist/array/reduce.js.map +1 -0
  65. package/dist/array/search.cjs +2 -0
  66. package/dist/array/search.cjs.map +1 -0
  67. package/dist/array/search.js +14 -0
  68. package/dist/array/search.js.map +1 -0
  69. package/dist/array/select.cjs +2 -0
  70. package/dist/array/select.cjs.map +1 -0
  71. package/dist/array/select.js +16 -0
  72. package/dist/array/select.js.map +1 -0
  73. package/dist/array/shift.cjs +2 -0
  74. package/dist/array/shift.cjs.map +1 -0
  75. package/dist/array/shift.js +13 -0
  76. package/dist/array/shift.js.map +1 -0
  77. package/dist/array/some.cjs +2 -0
  78. package/dist/array/some.cjs.map +1 -0
  79. package/dist/array/some.js +14 -0
  80. package/dist/array/some.js.map +1 -0
  81. package/dist/array/sort.cjs +2 -0
  82. package/dist/array/sort.cjs.map +1 -0
  83. package/dist/array/sort.js +13 -0
  84. package/dist/array/sort.js.map +1 -0
  85. package/dist/array/sortBy.cjs +2 -0
  86. package/dist/array/sortBy.cjs.map +1 -0
  87. package/dist/array/sortBy.js +6 -0
  88. package/dist/array/sortBy.js.map +1 -0
  89. package/dist/array/substitute.cjs +2 -0
  90. package/dist/array/substitute.cjs.map +1 -0
  91. package/dist/array/substitute.js +13 -0
  92. package/dist/array/substitute.js.map +1 -0
  93. package/dist/array/uniq.cjs +2 -0
  94. package/dist/array/uniq.cjs.map +1 -0
  95. package/dist/array/uniq.js +18 -0
  96. package/dist/array/uniq.js.map +1 -0
  97. package/dist/date/expires.cjs +2 -0
  98. package/dist/date/expires.cjs.map +1 -0
  99. package/dist/date/expires.js +11 -0
  100. package/dist/date/expires.js.map +1 -0
  101. package/dist/date/interval.cjs +2 -0
  102. package/dist/date/interval.cjs.map +1 -0
  103. package/dist/date/interval.js +39 -0
  104. package/dist/date/interval.js.map +1 -0
  105. package/dist/date/timeDiff.cjs +2 -0
  106. package/dist/date/timeDiff.cjs.map +1 -0
  107. package/dist/date/timeDiff.js +29 -0
  108. package/dist/date/timeDiff.js.map +1 -0
  109. package/dist/function/assert.cjs +3 -0
  110. package/dist/function/assert.cjs.map +1 -0
  111. package/dist/function/assert.js +12 -0
  112. package/dist/function/assert.js.map +1 -0
  113. package/dist/function/assertParams.cjs +2 -0
  114. package/dist/function/assertParams.cjs.map +1 -0
  115. package/dist/function/assertParams.js +13 -0
  116. package/dist/function/assertParams.js.map +1 -0
  117. package/dist/function/attempt.cjs +2 -0
  118. package/dist/function/attempt.cjs.map +1 -0
  119. package/dist/function/attempt.js +15 -0
  120. package/dist/function/attempt.js.map +1 -0
  121. package/dist/function/compare.cjs +2 -0
  122. package/dist/function/compare.cjs.map +1 -0
  123. package/dist/function/compare.js +22 -0
  124. package/dist/function/compare.js.map +1 -0
  125. package/dist/function/compareBy.cjs +2 -0
  126. package/dist/function/compareBy.cjs.map +1 -0
  127. package/dist/function/compareBy.js +15 -0
  128. package/dist/function/compareBy.js.map +1 -0
  129. package/dist/function/compose.cjs +2 -0
  130. package/dist/function/compose.cjs.map +1 -0
  131. package/dist/function/compose.js +14 -0
  132. package/dist/function/compose.js.map +1 -0
  133. package/dist/function/curry.cjs +2 -0
  134. package/dist/function/curry.cjs.map +1 -0
  135. package/dist/function/curry.js +8 -0
  136. package/dist/function/curry.js.map +1 -0
  137. package/dist/function/debounce.cjs +2 -0
  138. package/dist/function/debounce.cjs.map +1 -0
  139. package/dist/function/debounce.js +10 -0
  140. package/dist/function/debounce.js.map +1 -0
  141. package/dist/function/delay.cjs +2 -0
  142. package/dist/function/delay.cjs.map +1 -0
  143. package/dist/function/delay.js +8 -0
  144. package/dist/function/delay.js.map +1 -0
  145. package/dist/function/fp.cjs +2 -0
  146. package/dist/function/fp.cjs.map +1 -0
  147. package/dist/function/fp.js +10 -0
  148. package/dist/function/fp.js.map +1 -0
  149. package/dist/function/memo.cjs +2 -0
  150. package/dist/function/memo.cjs.map +1 -0
  151. package/dist/function/memo.js +24 -0
  152. package/dist/function/memo.js.map +1 -0
  153. package/dist/function/once.cjs +2 -0
  154. package/dist/function/once.cjs.map +1 -0
  155. package/dist/function/once.js +11 -0
  156. package/dist/function/once.js.map +1 -0
  157. package/dist/function/pipe.cjs +2 -0
  158. package/dist/function/pipe.cjs.map +1 -0
  159. package/dist/function/pipe.js +11 -0
  160. package/dist/function/pipe.js.map +1 -0
  161. package/dist/function/predict.cjs +2 -0
  162. package/dist/function/predict.cjs.map +1 -0
  163. package/dist/function/predict.js +13 -0
  164. package/dist/function/predict.js.map +1 -0
  165. package/dist/function/proxy.cjs +2 -0
  166. package/dist/function/proxy.cjs.map +1 -0
  167. package/dist/function/proxy.js +22 -0
  168. package/dist/function/proxy.js.map +1 -0
  169. package/dist/function/retry.cjs +2 -0
  170. package/dist/function/retry.cjs.map +1 -0
  171. package/dist/function/retry.js +25 -0
  172. package/dist/function/retry.js.map +1 -0
  173. package/dist/function/sleep.cjs +2 -0
  174. package/dist/function/sleep.cjs.map +1 -0
  175. package/dist/function/sleep.js +7 -0
  176. package/dist/function/sleep.js.map +1 -0
  177. package/dist/function/throttle.cjs +2 -0
  178. package/dist/function/throttle.cjs.map +1 -0
  179. package/dist/function/throttle.js +11 -0
  180. package/dist/function/throttle.js.map +1 -0
  181. package/dist/function/worker.cjs +14 -0
  182. package/dist/function/worker.cjs.map +1 -0
  183. package/dist/function/worker.js +29 -0
  184. package/dist/function/worker.js.map +1 -0
  185. package/dist/index.cjs +2 -0
  186. package/dist/index.cjs.map +1 -0
  187. package/dist/index.d.ts +2278 -0
  188. package/dist/index.js +217 -0
  189. package/dist/index.js.map +1 -0
  190. package/dist/logit/dist/logit.cjs +2 -0
  191. package/dist/logit/dist/logit.cjs.map +1 -0
  192. package/dist/logit/dist/logit.js +178 -0
  193. package/dist/logit/dist/logit.js.map +1 -0
  194. package/dist/math/average.cjs +2 -0
  195. package/dist/math/average.cjs.map +1 -0
  196. package/dist/math/average.js +19 -0
  197. package/dist/math/average.js.map +1 -0
  198. package/dist/math/boil.cjs +2 -0
  199. package/dist/math/boil.cjs.map +1 -0
  200. package/dist/math/boil.js +17 -0
  201. package/dist/math/boil.js.map +1 -0
  202. package/dist/math/clamp.cjs +2 -0
  203. package/dist/math/clamp.cjs.map +1 -0
  204. package/dist/math/clamp.js +7 -0
  205. package/dist/math/clamp.js.map +1 -0
  206. package/dist/math/max.cjs +2 -0
  207. package/dist/math/max.cjs.map +1 -0
  208. package/dist/math/max.js +12 -0
  209. package/dist/math/max.js.map +1 -0
  210. package/dist/math/median.cjs +2 -0
  211. package/dist/math/median.cjs.map +1 -0
  212. package/dist/math/median.js +11 -0
  213. package/dist/math/median.js.map +1 -0
  214. package/dist/math/min.cjs +2 -0
  215. package/dist/math/min.cjs.map +1 -0
  216. package/dist/math/min.js +12 -0
  217. package/dist/math/min.js.map +1 -0
  218. package/dist/math/range.cjs +2 -0
  219. package/dist/math/range.cjs.map +1 -0
  220. package/dist/math/range.js +10 -0
  221. package/dist/math/range.js.map +1 -0
  222. package/dist/math/rate.cjs +2 -0
  223. package/dist/math/rate.cjs.map +1 -0
  224. package/dist/math/rate.js +9 -0
  225. package/dist/math/rate.js.map +1 -0
  226. package/dist/math/round.cjs +2 -0
  227. package/dist/math/round.cjs.map +1 -0
  228. package/dist/math/round.js +9 -0
  229. package/dist/math/round.js.map +1 -0
  230. package/dist/math/sum.cjs +2 -0
  231. package/dist/math/sum.cjs.map +1 -0
  232. package/dist/math/sum.js +22 -0
  233. package/dist/math/sum.js.map +1 -0
  234. package/dist/object/clone.cjs +2 -0
  235. package/dist/object/clone.cjs.map +1 -0
  236. package/dist/object/clone.js +7 -0
  237. package/dist/object/clone.js.map +1 -0
  238. package/dist/object/diff.cjs +2 -0
  239. package/dist/object/diff.cjs.map +1 -0
  240. package/dist/object/diff.js +18 -0
  241. package/dist/object/diff.js.map +1 -0
  242. package/dist/object/entries.cjs +2 -0
  243. package/dist/object/entries.cjs.map +1 -0
  244. package/dist/object/entries.js +9 -0
  245. package/dist/object/entries.js.map +1 -0
  246. package/dist/object/keys.cjs +2 -0
  247. package/dist/object/keys.cjs.map +1 -0
  248. package/dist/object/keys.js +9 -0
  249. package/dist/object/keys.js.map +1 -0
  250. package/dist/object/merge.cjs +2 -0
  251. package/dist/object/merge.cjs.map +1 -0
  252. package/dist/object/merge.js +29 -0
  253. package/dist/object/merge.js.map +1 -0
  254. package/dist/object/parseJSON.cjs +2 -0
  255. package/dist/object/parseJSON.cjs.map +1 -0
  256. package/dist/object/parseJSON.js +19 -0
  257. package/dist/object/parseJSON.js.map +1 -0
  258. package/dist/object/path.cjs +2 -0
  259. package/dist/object/path.cjs.map +1 -0
  260. package/dist/object/path.js +24 -0
  261. package/dist/object/path.js.map +1 -0
  262. package/dist/object/seek.cjs +2 -0
  263. package/dist/object/seek.cjs.map +1 -0
  264. package/dist/object/seek.js +11 -0
  265. package/dist/object/seek.js.map +1 -0
  266. package/dist/object/values.cjs +2 -0
  267. package/dist/object/values.cjs.map +1 -0
  268. package/dist/object/values.js +9 -0
  269. package/dist/object/values.js.map +1 -0
  270. package/dist/random/draw.cjs +2 -0
  271. package/dist/random/draw.cjs.map +1 -0
  272. package/dist/random/draw.js +11 -0
  273. package/dist/random/draw.js.map +1 -0
  274. package/dist/random/random.cjs +2 -0
  275. package/dist/random/random.cjs.map +1 -0
  276. package/dist/random/random.js +10 -0
  277. package/dist/random/random.js.map +1 -0
  278. package/dist/random/shuffle.cjs +2 -0
  279. package/dist/random/shuffle.cjs.map +1 -0
  280. package/dist/random/shuffle.js +15 -0
  281. package/dist/random/shuffle.js.map +1 -0
  282. package/dist/random/uuid.cjs +2 -0
  283. package/dist/random/uuid.cjs.map +1 -0
  284. package/dist/random/uuid.js +7 -0
  285. package/dist/random/uuid.js.map +1 -0
  286. package/dist/string/_caseUtils.cjs +2 -0
  287. package/dist/string/_caseUtils.cjs.map +1 -0
  288. package/dist/string/_caseUtils.js +9 -0
  289. package/dist/string/_caseUtils.js.map +1 -0
  290. package/dist/string/camelCase.cjs +2 -0
  291. package/dist/string/camelCase.cjs.map +1 -0
  292. package/dist/string/camelCase.js +8 -0
  293. package/dist/string/camelCase.js.map +1 -0
  294. package/dist/string/kebabCase.cjs +2 -0
  295. package/dist/string/kebabCase.cjs.map +1 -0
  296. package/dist/string/kebabCase.js +8 -0
  297. package/dist/string/kebabCase.js.map +1 -0
  298. package/dist/string/pascalCase.cjs +2 -0
  299. package/dist/string/pascalCase.cjs.map +1 -0
  300. package/dist/string/pascalCase.js +8 -0
  301. package/dist/string/pascalCase.js.map +1 -0
  302. package/dist/string/similarity.cjs +2 -0
  303. package/dist/string/similarity.cjs.map +1 -0
  304. package/dist/string/similarity.js +34 -0
  305. package/dist/string/similarity.js.map +1 -0
  306. package/dist/string/snakeCase.cjs +2 -0
  307. package/dist/string/snakeCase.cjs.map +1 -0
  308. package/dist/string/snakeCase.js +8 -0
  309. package/dist/string/snakeCase.js.map +1 -0
  310. package/dist/string/truncate.cjs +2 -0
  311. package/dist/string/truncate.cjs.map +1 -0
  312. package/dist/string/truncate.js +9 -0
  313. package/dist/string/truncate.js.map +1 -0
  314. package/dist/typed/ge.cjs +2 -0
  315. package/dist/typed/ge.cjs.map +1 -0
  316. package/dist/typed/ge.js +7 -0
  317. package/dist/typed/ge.js.map +1 -0
  318. package/dist/typed/gt.cjs +2 -0
  319. package/dist/typed/gt.cjs.map +1 -0
  320. package/dist/typed/gt.js +7 -0
  321. package/dist/typed/gt.js.map +1 -0
  322. package/dist/typed/is.cjs +2 -0
  323. package/dist/typed/is.cjs.map +1 -0
  324. package/dist/typed/is.js +44 -0
  325. package/dist/typed/is.js.map +1 -0
  326. package/dist/typed/isArray.cjs +2 -0
  327. package/dist/typed/isArray.cjs.map +1 -0
  328. package/dist/typed/isArray.js +9 -0
  329. package/dist/typed/isArray.js.map +1 -0
  330. package/dist/typed/isBoolean.cjs +2 -0
  331. package/dist/typed/isBoolean.cjs.map +1 -0
  332. package/dist/typed/isBoolean.js +7 -0
  333. package/dist/typed/isBoolean.js.map +1 -0
  334. package/dist/typed/isDate.cjs +2 -0
  335. package/dist/typed/isDate.cjs.map +1 -0
  336. package/dist/typed/isDate.js +9 -0
  337. package/dist/typed/isDate.js.map +1 -0
  338. package/dist/typed/isDefined.cjs +2 -0
  339. package/dist/typed/isDefined.cjs.map +1 -0
  340. package/dist/typed/isDefined.js +7 -0
  341. package/dist/typed/isDefined.js.map +1 -0
  342. package/dist/typed/isEmpty.cjs +2 -0
  343. package/dist/typed/isEmpty.cjs.map +1 -0
  344. package/dist/typed/isEmpty.js +12 -0
  345. package/dist/typed/isEmpty.js.map +1 -0
  346. package/dist/typed/isEqual.cjs +2 -0
  347. package/dist/typed/isEqual.cjs.map +1 -0
  348. package/dist/typed/isEqual.js +25 -0
  349. package/dist/typed/isEqual.js.map +1 -0
  350. package/dist/typed/isEven.cjs +2 -0
  351. package/dist/typed/isEven.cjs.map +1 -0
  352. package/dist/typed/isEven.js +7 -0
  353. package/dist/typed/isEven.js.map +1 -0
  354. package/dist/typed/isFunction.cjs +2 -0
  355. package/dist/typed/isFunction.cjs.map +1 -0
  356. package/dist/typed/isFunction.js +9 -0
  357. package/dist/typed/isFunction.js.map +1 -0
  358. package/dist/typed/isMatch.cjs +2 -0
  359. package/dist/typed/isMatch.cjs.map +1 -0
  360. package/dist/typed/isMatch.js +19 -0
  361. package/dist/typed/isMatch.js.map +1 -0
  362. package/dist/typed/isNegative.cjs +2 -0
  363. package/dist/typed/isNegative.cjs.map +1 -0
  364. package/dist/typed/isNegative.js +7 -0
  365. package/dist/typed/isNegative.js.map +1 -0
  366. package/dist/typed/isNil.cjs +2 -0
  367. package/dist/typed/isNil.cjs.map +1 -0
  368. package/dist/typed/isNil.js +9 -0
  369. package/dist/typed/isNil.js.map +1 -0
  370. package/dist/typed/isNumber.cjs +2 -0
  371. package/dist/typed/isNumber.cjs.map +1 -0
  372. package/dist/typed/isNumber.js +9 -0
  373. package/dist/typed/isNumber.js.map +1 -0
  374. package/dist/typed/isObject.cjs +2 -0
  375. package/dist/typed/isObject.cjs.map +1 -0
  376. package/dist/typed/isObject.js +9 -0
  377. package/dist/typed/isObject.js.map +1 -0
  378. package/dist/typed/isOdd.cjs +2 -0
  379. package/dist/typed/isOdd.cjs.map +1 -0
  380. package/dist/typed/isOdd.js +7 -0
  381. package/dist/typed/isOdd.js.map +1 -0
  382. package/dist/typed/isPositive.cjs +2 -0
  383. package/dist/typed/isPositive.cjs.map +1 -0
  384. package/dist/typed/isPositive.js +7 -0
  385. package/dist/typed/isPositive.js.map +1 -0
  386. package/dist/typed/isPrimitive.cjs +2 -0
  387. package/dist/typed/isPrimitive.cjs.map +1 -0
  388. package/dist/typed/isPrimitive.js +10 -0
  389. package/dist/typed/isPrimitive.js.map +1 -0
  390. package/dist/typed/isPromise.cjs +2 -0
  391. package/dist/typed/isPromise.cjs.map +1 -0
  392. package/dist/typed/isPromise.js +10 -0
  393. package/dist/typed/isPromise.js.map +1 -0
  394. package/dist/typed/isRegex.cjs +2 -0
  395. package/dist/typed/isRegex.cjs.map +1 -0
  396. package/dist/typed/isRegex.js +7 -0
  397. package/dist/typed/isRegex.js.map +1 -0
  398. package/dist/typed/isString.cjs +2 -0
  399. package/dist/typed/isString.cjs.map +1 -0
  400. package/dist/typed/isString.js +9 -0
  401. package/dist/typed/isString.js.map +1 -0
  402. package/dist/typed/isWithin.cjs +2 -0
  403. package/dist/typed/isWithin.cjs.map +1 -0
  404. package/dist/typed/isWithin.js +10 -0
  405. package/dist/typed/isWithin.js.map +1 -0
  406. package/dist/typed/isZero.cjs +2 -0
  407. package/dist/typed/isZero.cjs.map +1 -0
  408. package/dist/typed/isZero.js +7 -0
  409. package/dist/typed/isZero.js.map +1 -0
  410. package/dist/typed/le.cjs +2 -0
  411. package/dist/typed/le.cjs.map +1 -0
  412. package/dist/typed/le.js +7 -0
  413. package/dist/typed/le.js.map +1 -0
  414. package/dist/typed/lt.cjs +2 -0
  415. package/dist/typed/lt.cjs.map +1 -0
  416. package/dist/typed/lt.js +7 -0
  417. package/dist/typed/lt.js.map +1 -0
  418. package/dist/typed/typeOf.cjs +2 -0
  419. package/dist/typed/typeOf.cjs.map +1 -0
  420. package/dist/typed/typeOf.js +14 -0
  421. package/dist/typed/typeOf.js.map +1 -0
  422. package/package.json +38 -0
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=(t,e)=>{if(t===e)return 0;if(t===void 0)return 1;if(e===void 0)return-1;if(t===null)return e===null?0:-1;if(e===null)return 1;if(typeof t=="string"&&typeof e=="string")return t.localeCompare(e);if(typeof t=="number"&&typeof e=="number")return t-e;if(t instanceof Date&&e instanceof Date)return t.getTime()-e.getTime();if(typeof t=="object"&&typeof e=="object"){const r=JSON.stringify(t),n=JSON.stringify(e);return r.localeCompare(n)}return String(t).localeCompare(String(e))};exports.compare=i;
2
+ //# sourceMappingURL=compare.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare.cjs","sources":["../../src/function/compare.ts"],"sourcesContent":["/**\n * Compares two values and returns:\n * - 0 if they are equal\n * - 1 if the first value is greater\n * - -1 if the second value is greater\n *\n * @example\n * ```ts\n * compare('a', 'b'); // -1\n * compare(1, 2); // -1\n * compare(new Date('2023-01-01'), new Date('2023-01-02')); // -1\n * compare('a', 'a'); // 0\n * compare(1, 1); // 0\n * compare(new Date('2023-01-01'), new Date('2023-01-01')); // 0\n * ```\n *\n * @param a - The first value to compare.\n * @param b - The second value to compare.\n *\n * @returns 0 if equal, 1 if the first value is greater, -1 if the second value is greater.\n */\n// biome-ignore lint/suspicious/noExplicitAny: -\nexport const compare = (a: any, b: any): number => {\n if (a === b) return 0;\n if (a === undefined) return 1;\n if (b === undefined) return -1;\n if (a === null) return b === null ? 0 : -1;\n if (b === null) return 1;\n\n if (typeof a === 'string' && typeof b === 'string') {\n return a.localeCompare(b);\n }\n\n if (typeof a === 'number' && typeof b === 'number') {\n return a - b;\n }\n\n if (a instanceof Date && b instanceof Date) {\n return a.getTime() - b.getTime();\n }\n\n if (typeof a === 'object' && typeof b === 'object') {\n const aString = JSON.stringify(a);\n const bString = JSON.stringify(b);\n return aString.localeCompare(bString);\n }\n\n return String(a).localeCompare(String(b));\n};\n"],"names":["compare","a","b","aString","bString"],"mappings":"gFAsBO,MAAMA,EAAU,CAACC,EAAQC,IAAmB,CACjD,GAAID,IAAMC,EAAG,MAAO,GACpB,GAAID,IAAM,OAAW,MAAO,GAC5B,GAAIC,IAAM,OAAW,MAAO,GAC5B,GAAID,IAAM,KAAM,OAAOC,IAAM,KAAO,EAAI,GACxC,GAAIA,IAAM,KAAM,MAAO,GAEvB,GAAI,OAAOD,GAAM,UAAY,OAAOC,GAAM,SACxC,OAAOD,EAAE,cAAcC,CAAC,EAG1B,GAAI,OAAOD,GAAM,UAAY,OAAOC,GAAM,SACxC,OAAOD,EAAIC,EAGb,GAAID,aAAa,MAAQC,aAAa,KACpC,OAAOD,EAAE,UAAYC,EAAE,QAAA,EAGzB,GAAI,OAAOD,GAAM,UAAY,OAAOC,GAAM,SAAU,CAClD,MAAMC,EAAU,KAAK,UAAUF,CAAC,EAC1BG,EAAU,KAAK,UAAUF,CAAC,EAChC,OAAOC,EAAQ,cAAcC,CAAO,CACtC,CAEA,OAAO,OAAOH,CAAC,EAAE,cAAc,OAAOC,CAAC,CAAC,CAC1C"}
@@ -0,0 +1,22 @@
1
+ const i = (t, e) => {
2
+ if (t === e) return 0;
3
+ if (t === void 0) return 1;
4
+ if (e === void 0) return -1;
5
+ if (t === null) return e === null ? 0 : -1;
6
+ if (e === null) return 1;
7
+ if (typeof t == "string" && typeof e == "string")
8
+ return t.localeCompare(e);
9
+ if (typeof t == "number" && typeof e == "number")
10
+ return t - e;
11
+ if (t instanceof Date && e instanceof Date)
12
+ return t.getTime() - e.getTime();
13
+ if (typeof t == "object" && typeof e == "object") {
14
+ const r = JSON.stringify(t), n = JSON.stringify(e);
15
+ return r.localeCompare(n);
16
+ }
17
+ return String(t).localeCompare(String(e));
18
+ };
19
+ export {
20
+ i as compare
21
+ };
22
+ //# sourceMappingURL=compare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare.js","sources":["../../src/function/compare.ts"],"sourcesContent":["/**\n * Compares two values and returns:\n * - 0 if they are equal\n * - 1 if the first value is greater\n * - -1 if the second value is greater\n *\n * @example\n * ```ts\n * compare('a', 'b'); // -1\n * compare(1, 2); // -1\n * compare(new Date('2023-01-01'), new Date('2023-01-02')); // -1\n * compare('a', 'a'); // 0\n * compare(1, 1); // 0\n * compare(new Date('2023-01-01'), new Date('2023-01-01')); // 0\n * ```\n *\n * @param a - The first value to compare.\n * @param b - The second value to compare.\n *\n * @returns 0 if equal, 1 if the first value is greater, -1 if the second value is greater.\n */\n// biome-ignore lint/suspicious/noExplicitAny: -\nexport const compare = (a: any, b: any): number => {\n if (a === b) return 0;\n if (a === undefined) return 1;\n if (b === undefined) return -1;\n if (a === null) return b === null ? 0 : -1;\n if (b === null) return 1;\n\n if (typeof a === 'string' && typeof b === 'string') {\n return a.localeCompare(b);\n }\n\n if (typeof a === 'number' && typeof b === 'number') {\n return a - b;\n }\n\n if (a instanceof Date && b instanceof Date) {\n return a.getTime() - b.getTime();\n }\n\n if (typeof a === 'object' && typeof b === 'object') {\n const aString = JSON.stringify(a);\n const bString = JSON.stringify(b);\n return aString.localeCompare(bString);\n }\n\n return String(a).localeCompare(String(b));\n};\n"],"names":["compare","a","b","aString","bString"],"mappings":"AAsBO,MAAMA,IAAU,CAACC,GAAQC,MAAmB;AACjD,MAAID,MAAMC,EAAG,QAAO;AACpB,MAAID,MAAM,OAAW,QAAO;AAC5B,MAAIC,MAAM,OAAW,QAAO;AAC5B,MAAID,MAAM,KAAM,QAAOC,MAAM,OAAO,IAAI;AACxC,MAAIA,MAAM,KAAM,QAAO;AAEvB,MAAI,OAAOD,KAAM,YAAY,OAAOC,KAAM;AACxC,WAAOD,EAAE,cAAcC,CAAC;AAG1B,MAAI,OAAOD,KAAM,YAAY,OAAOC,KAAM;AACxC,WAAOD,IAAIC;AAGb,MAAID,aAAa,QAAQC,aAAa;AACpC,WAAOD,EAAE,YAAYC,EAAE,QAAA;AAGzB,MAAI,OAAOD,KAAM,YAAY,OAAOC,KAAM,UAAU;AAClD,UAAMC,IAAU,KAAK,UAAUF,CAAC,GAC1BG,IAAU,KAAK,UAAUF,CAAC;AAChC,WAAOC,EAAQ,cAAcC,CAAO;AAAA,EACtC;AAEA,SAAO,OAAOH,CAAC,EAAE,cAAc,OAAOC,CAAC,CAAC;AAC1C;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./compare.cjs"),p=t=>{const o=Object.entries(t);return(c,n)=>{for(const[e,s]of o){const i=c[e],u=n[e],a=s==="desc"?-1:1,r=m.compare(i,u);if(r!==0)return r*a}return 0}};exports.compareBy=p;
2
+ //# sourceMappingURL=compareBy.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compareBy.cjs","sources":["../../src/function/compareBy.ts"],"sourcesContent":["import { compare } from './compare';\n\n/**\n * Compares two objects based on multiple selectors.\n * The comparison is done in the order of the selectors provided.\n * Each selector can be 'asc' for ascending or 'desc' for descending order.\n *\n * @example\n * ```ts\n * const compareByNameAndAge = compareBy<{ name: string; age: number }>({\n * name: 'asc',\n * age: 'desc',\n * });\n *\n * const a = { name: 'Alice', age: 30 };\n * const b = { name: 'Bob', age: 25 };\n *\n * console.log(compareByNameAndAge(a, b)); // -1 (Alice < Bob)\n * ```\n *\n * @param selectors - An object where keys are properties to compare and values are 'asc' or 'desc'.\n *\n * @returns A comparison function that can be used with array sorting methods.\n */\nexport const compareBy = <T>(selectors: Partial<Record<keyof T, 'asc' | 'desc'>>) => {\n const entries = Object.entries(selectors) as [keyof T, 'asc' | 'desc'][];\n\n return (a: T, b: T) => {\n for (const [key, direction] of entries) {\n const v1 = a[key];\n const v2 = b[key];\n const dir = direction === 'desc' ? -1 : 1;\n\n const cmp = compare(v1, v2);\n if (cmp !== 0) return cmp * dir;\n }\n\n return 0;\n };\n};\n"],"names":["compareBy","selectors","entries","a","b","key","direction","v1","v2","dir","cmp","compare"],"mappings":"iHAwBaA,EAAgBC,GAAwD,CACnF,MAAMC,EAAU,OAAO,QAAQD,CAAS,EAExC,MAAO,CAACE,EAAMC,IAAS,CACrB,SAAW,CAACC,EAAKC,CAAS,IAAKJ,EAAS,CACtC,MAAMK,EAAKJ,EAAEE,CAAG,EACVG,EAAKJ,EAAEC,CAAG,EACVI,EAAMH,IAAc,OAAS,GAAK,EAElCI,EAAMC,EAAAA,QAAQJ,EAAIC,CAAE,EAC1B,GAAIE,IAAQ,EAAG,OAAOA,EAAMD,CAC9B,CAEA,MAAO,EACT,CACF"}
@@ -0,0 +1,15 @@
1
+ import { compare as f } from "./compare.js";
2
+ const u = (o) => {
3
+ const e = Object.entries(o);
4
+ return (c, n) => {
5
+ for (const [r, s] of e) {
6
+ const i = c[r], m = n[r], p = s === "desc" ? -1 : 1, t = f(i, m);
7
+ if (t !== 0) return t * p;
8
+ }
9
+ return 0;
10
+ };
11
+ };
12
+ export {
13
+ u as compareBy
14
+ };
15
+ //# sourceMappingURL=compareBy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compareBy.js","sources":["../../src/function/compareBy.ts"],"sourcesContent":["import { compare } from './compare';\n\n/**\n * Compares two objects based on multiple selectors.\n * The comparison is done in the order of the selectors provided.\n * Each selector can be 'asc' for ascending or 'desc' for descending order.\n *\n * @example\n * ```ts\n * const compareByNameAndAge = compareBy<{ name: string; age: number }>({\n * name: 'asc',\n * age: 'desc',\n * });\n *\n * const a = { name: 'Alice', age: 30 };\n * const b = { name: 'Bob', age: 25 };\n *\n * console.log(compareByNameAndAge(a, b)); // -1 (Alice < Bob)\n * ```\n *\n * @param selectors - An object where keys are properties to compare and values are 'asc' or 'desc'.\n *\n * @returns A comparison function that can be used with array sorting methods.\n */\nexport const compareBy = <T>(selectors: Partial<Record<keyof T, 'asc' | 'desc'>>) => {\n const entries = Object.entries(selectors) as [keyof T, 'asc' | 'desc'][];\n\n return (a: T, b: T) => {\n for (const [key, direction] of entries) {\n const v1 = a[key];\n const v2 = b[key];\n const dir = direction === 'desc' ? -1 : 1;\n\n const cmp = compare(v1, v2);\n if (cmp !== 0) return cmp * dir;\n }\n\n return 0;\n };\n};\n"],"names":["compareBy","selectors","entries","a","b","key","direction","v1","v2","dir","cmp","compare"],"mappings":";AAwBO,MAAMA,IAAY,CAAIC,MAAwD;AACnF,QAAMC,IAAU,OAAO,QAAQD,CAAS;AAExC,SAAO,CAACE,GAAMC,MAAS;AACrB,eAAW,CAACC,GAAKC,CAAS,KAAKJ,GAAS;AACtC,YAAMK,IAAKJ,EAAEE,CAAG,GACVG,IAAKJ,EAAEC,CAAG,GACVI,IAAMH,MAAc,SAAS,KAAK,GAElCI,IAAMC,EAAQJ,GAAIC,CAAE;AAC1B,UAAIE,MAAQ,EAAG,QAAOA,IAAMD;AAAA,IAC9B;AAEA,WAAO;AAAA,EACT;AACF;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../typed/isPromise.cjs"),n=require("./assert.cjs");function u(...e){n.assert(e.length>0,"compose requires at least one function",{args:{fns:e}});const o=e[e.length-1],r=e.slice(0,-1);return((...i)=>r.reduceRight((t,s)=>c.isPromise(t)?t.then(s):s(t),o(...i)))}exports.compose=u;
2
+ //# sourceMappingURL=compose.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.cjs","sources":["../../src/function/compose.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noExplicitAny: - */\n\nimport { isPromise } from '../typed/isPromise';\nimport type { FnDynamic } from '../types';\nimport { assert } from './assert';\n\ntype LastParameters<T> = T extends [...any, infer Last extends FnDynamic] ? Parameters<Last> : never;\ntype FirstReturnType<F> = F extends [infer First extends FnDynamic, ...any] ? ReturnType<First> : never;\ntype ComposeReturn<T extends FnDynamic[]> = (\n ...args: LastParameters<T>\n) => FirstReturnType<T> extends Promise<any> ? Promise<Awaited<FirstReturnType<T>>> : FirstReturnType<T>;\n/**\n * Composes multiple functions into a single function. It starts from the rightmost function and proceeds to the left.\n *\n * @example\n * ```ts\n * const add = (x) => x + 2;\n * const multiply = (x) => x * 3;\n * const subtract = (x) => x - 4;\n * const composedFn = compose(subtract, multiply, add);\n * composedFn(5); // ((5 + 2) * 3) - 4 = 17\n * ```\n *\n * @example\n * ```ts\n * const square = async (x) => x * x;\n * const add = async (x) => x + 2;\n * const composedFn = compose(square, add);\n * await composedFn(4); // (4 * 4) + 2 = 18\n * ```\n *\n * @param fns - List of the functions to be composed.\n *\n * @returns A new function that is the composition of the input functions.\n */\nexport function compose<T extends FnDynamic[]>(...fns: T): ComposeReturn<T> {\n assert(fns.length > 0, 'compose requires at least one function', { args: { fns } });\n\n const lastFn = fns[fns.length - 1];\n const restFns = fns.slice(0, -1);\n\n return ((...args: LastParameters<T>) =>\n restFns.reduceRight(\n (prev, fn) => (isPromise(prev) ? prev.then(fn) : fn(prev)),\n lastFn(...args),\n )) as ComposeReturn<T>;\n}\n"],"names":["compose","fns","assert","lastFn","restFns","args","prev","fn","isPromise"],"mappings":"oJAmCO,SAASA,KAAkCC,EAA0B,CAC1EC,SAAOD,EAAI,OAAS,EAAG,yCAA0C,CAAE,KAAM,CAAE,IAAAA,CAAA,EAAO,EAElF,MAAME,EAASF,EAAIA,EAAI,OAAS,CAAC,EAC3BG,EAAUH,EAAI,MAAM,EAAG,EAAE,EAE/B,OAAQ,IAAII,IACVD,EAAQ,YACN,CAACE,EAAMC,IAAQC,EAAAA,UAAUF,CAAI,EAAIA,EAAK,KAAKC,CAAE,EAAIA,EAAGD,CAAI,EACxDH,EAAO,GAAGE,CAAI,CAAA,EAEpB"}
@@ -0,0 +1,14 @@
1
+ import { isPromise as c } from "../typed/isPromise.js";
2
+ import { assert as n } from "./assert.js";
3
+ function l(...t) {
4
+ n(t.length > 0, "compose requires at least one function", { args: { fns: t } });
5
+ const r = t[t.length - 1], s = t.slice(0, -1);
6
+ return ((...i) => s.reduceRight(
7
+ (e, o) => c(e) ? e.then(o) : o(e),
8
+ r(...i)
9
+ ));
10
+ }
11
+ export {
12
+ l as compose
13
+ };
14
+ //# sourceMappingURL=compose.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.js","sources":["../../src/function/compose.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noExplicitAny: - */\n\nimport { isPromise } from '../typed/isPromise';\nimport type { FnDynamic } from '../types';\nimport { assert } from './assert';\n\ntype LastParameters<T> = T extends [...any, infer Last extends FnDynamic] ? Parameters<Last> : never;\ntype FirstReturnType<F> = F extends [infer First extends FnDynamic, ...any] ? ReturnType<First> : never;\ntype ComposeReturn<T extends FnDynamic[]> = (\n ...args: LastParameters<T>\n) => FirstReturnType<T> extends Promise<any> ? Promise<Awaited<FirstReturnType<T>>> : FirstReturnType<T>;\n/**\n * Composes multiple functions into a single function. It starts from the rightmost function and proceeds to the left.\n *\n * @example\n * ```ts\n * const add = (x) => x + 2;\n * const multiply = (x) => x * 3;\n * const subtract = (x) => x - 4;\n * const composedFn = compose(subtract, multiply, add);\n * composedFn(5); // ((5 + 2) * 3) - 4 = 17\n * ```\n *\n * @example\n * ```ts\n * const square = async (x) => x * x;\n * const add = async (x) => x + 2;\n * const composedFn = compose(square, add);\n * await composedFn(4); // (4 * 4) + 2 = 18\n * ```\n *\n * @param fns - List of the functions to be composed.\n *\n * @returns A new function that is the composition of the input functions.\n */\nexport function compose<T extends FnDynamic[]>(...fns: T): ComposeReturn<T> {\n assert(fns.length > 0, 'compose requires at least one function', { args: { fns } });\n\n const lastFn = fns[fns.length - 1];\n const restFns = fns.slice(0, -1);\n\n return ((...args: LastParameters<T>) =>\n restFns.reduceRight(\n (prev, fn) => (isPromise(prev) ? prev.then(fn) : fn(prev)),\n lastFn(...args),\n )) as ComposeReturn<T>;\n}\n"],"names":["compose","fns","assert","lastFn","restFns","args","prev","fn","isPromise"],"mappings":";;AAmCO,SAASA,KAAkCC,GAA0B;AAC1E,EAAAC,EAAOD,EAAI,SAAS,GAAG,0CAA0C,EAAE,MAAM,EAAE,KAAAA,EAAA,GAAO;AAElF,QAAME,IAASF,EAAIA,EAAI,SAAS,CAAC,GAC3BG,IAAUH,EAAI,MAAM,GAAG,EAAE;AAE/B,UAAQ,IAAII,MACVD,EAAQ;AAAA,IACN,CAACE,GAAMC,MAAQC,EAAUF,CAAI,IAAIA,EAAK,KAAKC,CAAE,IAAIA,EAAGD,CAAI;AAAA,IACxDH,EAAO,GAAGE,CAAI;AAAA,EAAA;AAEpB;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=t=>{const e=(...r)=>r.length>=t.length?t(...r):(...c)=>e(...r.concat(c));return e};exports.curry=n;
2
+ //# sourceMappingURL=curry.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"curry.cjs","sources":["../../src/function/curry.ts"],"sourcesContent":["/**\n * Curries a function, allowing it to be called with partial arguments.\n *\n * @example\n * ```ts\n * const add = (a: number, b: number) => a + b;\n * const curriedAdd = curry(add);\n * curriedAdd(1)(2) // 3;\n * ```\n *\n * @param fn - The function to curry.\n *\n * @returns A curried version of the function.\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: -\nexport const curry = <T extends (...args: any[]) => any>(fn: T) => {\n // biome-ignore lint/suspicious/noExplicitAny: -\n const curried = (...args: Parameters<T>): any => {\n if (args.length >= fn.length) {\n return fn(...args);\n }\n return (...rest: Exclude<Parameters<T>, typeof args>) => curried(...(args.concat(rest) as Parameters<T>));\n };\n return curried as T extends (...args: infer P) => infer R ? CurriedFunction<P, R> : never;\n};\n\n// biome-ignore lint/suspicious/noExplicitAny: -\ntype CurriedFunction<Params extends any[], R> = Params extends [infer A, ...infer Rest]\n ? (arg: A) => CurriedFunction<Rest, R>\n : R;\n"],"names":["curry","fn","curried","args","rest"],"mappings":"gFAgBO,MAAMA,EAA4CC,GAAU,CAEjE,MAAMC,EAAU,IAAIC,IACdA,EAAK,QAAUF,EAAG,OACbA,EAAG,GAAGE,CAAI,EAEZ,IAAIC,IAA8CF,EAAQ,GAAIC,EAAK,OAAOC,CAAI,CAAmB,EAE1G,OAAOF,CACT"}
@@ -0,0 +1,8 @@
1
+ const c = (t) => {
2
+ const e = (...r) => r.length >= t.length ? t(...r) : (...n) => e(...r.concat(n));
3
+ return e;
4
+ };
5
+ export {
6
+ c as curry
7
+ };
8
+ //# sourceMappingURL=curry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"curry.js","sources":["../../src/function/curry.ts"],"sourcesContent":["/**\n * Curries a function, allowing it to be called with partial arguments.\n *\n * @example\n * ```ts\n * const add = (a: number, b: number) => a + b;\n * const curriedAdd = curry(add);\n * curriedAdd(1)(2) // 3;\n * ```\n *\n * @param fn - The function to curry.\n *\n * @returns A curried version of the function.\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: -\nexport const curry = <T extends (...args: any[]) => any>(fn: T) => {\n // biome-ignore lint/suspicious/noExplicitAny: -\n const curried = (...args: Parameters<T>): any => {\n if (args.length >= fn.length) {\n return fn(...args);\n }\n return (...rest: Exclude<Parameters<T>, typeof args>) => curried(...(args.concat(rest) as Parameters<T>));\n };\n return curried as T extends (...args: infer P) => infer R ? CurriedFunction<P, R> : never;\n};\n\n// biome-ignore lint/suspicious/noExplicitAny: -\ntype CurriedFunction<Params extends any[], R> = Params extends [infer A, ...infer Rest]\n ? (arg: A) => CurriedFunction<Rest, R>\n : R;\n"],"names":["curry","fn","curried","args","rest"],"mappings":"AAgBO,MAAMA,IAAQ,CAAoCC,MAAU;AAEjE,QAAMC,IAAU,IAAIC,MACdA,EAAK,UAAUF,EAAG,SACbA,EAAG,GAAGE,CAAI,IAEZ,IAAIC,MAA8CF,EAAQ,GAAIC,EAAK,OAAOC,CAAI,CAAmB;AAE1G,SAAOF;AACT;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function i(t,o=300){let e;return(...u)=>{clearTimeout(e),e=setTimeout(()=>t(...u),o)}}exports.debounce=i;
2
+ //# sourceMappingURL=debounce.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debounce.cjs","sources":["../../src/function/debounce.ts"],"sourcesContent":["import type { Fn } from '../types';\n\n/**\n * Creates a debounced function that delays invoking the provided function until after\n * a specified wait time has elapsed since the last invocation.\n *\n * @example\n * ```ts\n * const debouncedLog = debounce(console.log, 1000);\n *\n * debouncedLog('Hello'); // Will log after 1 second if not called again\n * debouncedLog('World'); // Resets the timer, will log 'World' after 1 second\n * ```\n *\n * @param fn - The function to debounce.\n * @param [delay=300] - - The number of milliseconds to delay invoking the function.\n *\n * @returns - A debounced function\n */\nexport function debounce<T extends Fn>(fn: T, delay = 300): (...args: Parameters<T>) => void {\n let timeoutId: ReturnType<typeof setTimeout>;\n\n return (...args: Parameters<T>) => {\n clearTimeout(timeoutId);\n timeoutId = setTimeout(() => fn(...args), delay);\n };\n}\n"],"names":["debounce","fn","delay","timeoutId","args"],"mappings":"gFAmBO,SAASA,EAAuBC,EAAOC,EAAQ,IAAuC,CAC3F,IAAIC,EAEJ,MAAO,IAAIC,IAAwB,CACjC,aAAaD,CAAS,EACtBA,EAAY,WAAW,IAAMF,EAAG,GAAGG,CAAI,EAAGF,CAAK,CACjD,CACF"}
@@ -0,0 +1,10 @@
1
+ function i(t, o = 300) {
2
+ let e;
3
+ return (...u) => {
4
+ clearTimeout(e), e = setTimeout(() => t(...u), o);
5
+ };
6
+ }
7
+ export {
8
+ i as debounce
9
+ };
10
+ //# sourceMappingURL=debounce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debounce.js","sources":["../../src/function/debounce.ts"],"sourcesContent":["import type { Fn } from '../types';\n\n/**\n * Creates a debounced function that delays invoking the provided function until after\n * a specified wait time has elapsed since the last invocation.\n *\n * @example\n * ```ts\n * const debouncedLog = debounce(console.log, 1000);\n *\n * debouncedLog('Hello'); // Will log after 1 second if not called again\n * debouncedLog('World'); // Resets the timer, will log 'World' after 1 second\n * ```\n *\n * @param fn - The function to debounce.\n * @param [delay=300] - - The number of milliseconds to delay invoking the function.\n *\n * @returns - A debounced function\n */\nexport function debounce<T extends Fn>(fn: T, delay = 300): (...args: Parameters<T>) => void {\n let timeoutId: ReturnType<typeof setTimeout>;\n\n return (...args: Parameters<T>) => {\n clearTimeout(timeoutId);\n timeoutId = setTimeout(() => fn(...args), delay);\n };\n}\n"],"names":["debounce","fn","delay","timeoutId","args"],"mappings":"AAmBO,SAASA,EAAuBC,GAAOC,IAAQ,KAAuC;AAC3F,MAAIC;AAEJ,SAAO,IAAIC,MAAwB;AACjC,iBAAaD,CAAS,GACtBA,IAAY,WAAW,MAAMF,EAAG,GAAGG,CAAI,GAAGF,CAAK;AAAA,EACjD;AACF;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./sleep.cjs");async function a(e,t=700){return await r.sleep(t),e()}exports.delay=a;
2
+ //# sourceMappingURL=delay.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delay.cjs","sources":["../../src/function/delay.ts"],"sourcesContent":["import type { Fn } from '../types';\nimport { sleep } from './sleep';\n\n/**\n * Delays the execution of a function by a specified amount of time.\n *\n * @example\n * ```ts\n * const log = () => console.log('Hello, world!');\n *\n * delay(log, 1000); // logs 'Hello, world!' after 1 second\n * ```\n *\n * @param fn - The function to be delayed.\n * @param delay - The amount of time to delay the function execution, in milliseconds. Default is 700.\n *\n * @returns A Promise that resolves with the result of the function execution.\n */\nexport async function delay<T extends Fn>(fn: T, delay = 700) {\n await sleep(delay);\n\n return fn();\n}\n"],"names":["delay","fn","sleep"],"mappings":"+GAkBA,eAAsBA,EAAoBC,EAAOD,EAAQ,IAAK,CAC5D,aAAME,EAAAA,MAAMF,CAAK,EAEVC,EAAA,CACT"}
@@ -0,0 +1,8 @@
1
+ import { sleep as t } from "./sleep.js";
2
+ async function n(e, r = 700) {
3
+ return await t(r), e();
4
+ }
5
+ export {
6
+ n as delay
7
+ };
8
+ //# sourceMappingURL=delay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delay.js","sources":["../../src/function/delay.ts"],"sourcesContent":["import type { Fn } from '../types';\nimport { sleep } from './sleep';\n\n/**\n * Delays the execution of a function by a specified amount of time.\n *\n * @example\n * ```ts\n * const log = () => console.log('Hello, world!');\n *\n * delay(log, 1000); // logs 'Hello, world!' after 1 second\n * ```\n *\n * @param fn - The function to be delayed.\n * @param delay - The amount of time to delay the function execution, in milliseconds. Default is 700.\n *\n * @returns A Promise that resolves with the result of the function execution.\n */\nexport async function delay<T extends Fn>(fn: T, delay = 700) {\n await sleep(delay);\n\n return fn();\n}\n"],"names":["delay","fn","sleep"],"mappings":";AAkBA,eAAsBA,EAAoBC,GAAOD,IAAQ,KAAK;AAC5D,eAAME,EAAMF,CAAK,GAEVC,EAAA;AACT;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./assert.cjs"),o=(e,...n)=>(r.assert(e.fp,`"${e.name}" cannot be used in functional programming mode. Please use the original function.`),t=>e(t,...n));exports.fp=o;
2
+ //# sourceMappingURL=fp.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fp.cjs","sources":["../../src/function/fp.ts"],"sourcesContent":["import type { Fn } from '../types';\nimport { assert } from './assert';\n\n// biome-ignore lint/suspicious/noExplicitAny: -\ntype RemoveFirstParameter<T extends Fn> = T extends (first: any, ...rest: infer R) => any ? R : never;\n\n/**\n * Creates a function that can be used in functional programming mode.\n * This function is a wrapper around the original function, allowing you to pass the first argument as an array.\n *\n * @example\n * ```ts\n * import { fp } from './fp';\n * import { map } from './map';\n *\n * const double = (num: number) => num * 2;\n * const doubleArray = fp(map, double);\n *\n * doubleArray([1, 2, 3]) // [2, 4, 6]\n * ```\n *\n * @param callback - The function to be wrapped.\n * @param args - The arguments to be passed to the function.\n *\n * @returns A function that takes an array and applies the original function to it.\n *\n * @throws {TypeError} If the function cannot be used in functional programming mode.\n */\nexport const fp = <T, F extends Fn = Fn>(callback: F, ...args: RemoveFirstParameter<F>) => {\n assert(\n // biome-ignore lint/suspicious/noExplicitAny: -\n (callback as any).fp,\n `\"${callback.name}\" cannot be used in functional programming mode. Please use the original function.`,\n );\n return (array: T[]) => callback(array, ...args);\n};\n"],"names":["fp","callback","args","assert","array"],"mappings":"gHA4BaA,EAAK,CAAuBC,KAAgBC,KACvDC,EAAAA,OAEGF,EAAiB,GAClB,IAAIA,EAAS,IAAI,oFAAA,EAEXG,GAAeH,EAASG,EAAO,GAAGF,CAAI"}
@@ -0,0 +1,10 @@
1
+ import { assert as r } from "./assert.js";
2
+ const i = (n, ...e) => (r(
3
+ // biome-ignore lint/suspicious/noExplicitAny: -
4
+ n.fp,
5
+ `"${n.name}" cannot be used in functional programming mode. Please use the original function.`
6
+ ), (o) => n(o, ...e));
7
+ export {
8
+ i as fp
9
+ };
10
+ //# sourceMappingURL=fp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fp.js","sources":["../../src/function/fp.ts"],"sourcesContent":["import type { Fn } from '../types';\nimport { assert } from './assert';\n\n// biome-ignore lint/suspicious/noExplicitAny: -\ntype RemoveFirstParameter<T extends Fn> = T extends (first: any, ...rest: infer R) => any ? R : never;\n\n/**\n * Creates a function that can be used in functional programming mode.\n * This function is a wrapper around the original function, allowing you to pass the first argument as an array.\n *\n * @example\n * ```ts\n * import { fp } from './fp';\n * import { map } from './map';\n *\n * const double = (num: number) => num * 2;\n * const doubleArray = fp(map, double);\n *\n * doubleArray([1, 2, 3]) // [2, 4, 6]\n * ```\n *\n * @param callback - The function to be wrapped.\n * @param args - The arguments to be passed to the function.\n *\n * @returns A function that takes an array and applies the original function to it.\n *\n * @throws {TypeError} If the function cannot be used in functional programming mode.\n */\nexport const fp = <T, F extends Fn = Fn>(callback: F, ...args: RemoveFirstParameter<F>) => {\n assert(\n // biome-ignore lint/suspicious/noExplicitAny: -\n (callback as any).fp,\n `\"${callback.name}\" cannot be used in functional programming mode. Please use the original function.`,\n );\n return (array: T[]) => callback(array, ...args);\n};\n"],"names":["fp","callback","args","assert","array"],"mappings":";AA4BO,MAAMA,IAAK,CAAuBC,MAAgBC,OACvDC;AAAA;AAAA,EAEGF,EAAiB;AAAA,EAClB,IAAIA,EAAS,IAAI;AAAA,GAEZ,CAACG,MAAeH,EAASG,GAAO,GAAGF,CAAI;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function f(l,{ttl:u,maxSize:i}={}){const t=new Map,s=n=>{if(n.length===0)return"__empty__";if(n.length===1){const e=n[0],r=typeof e;if(r==="string"||r==="number"||r==="boolean")return`${r}:${e}`;if(e===null)return"null";if(e===void 0)return"undefined"}return JSON.stringify(n)};return(...n)=>{const e=s(n),r=Date.now(),o=t.get(e);if(o&&(!u||r-o.timestamp<u))return t.delete(e),t.set(e,o),o.value;const c=l(...n);return t.set(e,{timestamp:r,value:c}),i&&t.size>i&&t.delete(t.keys().next().value),c}}exports.memo=f;
2
+ //# sourceMappingURL=memo.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memo.cjs","sources":["../../src/function/memo.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noExplicitAny: - */\nimport type { Fn } from '../types';\n\ntype MemoizeOptions = {\n ttl?: number; // Time-to-live in milliseconds\n maxSize?: number; // Maximum number of items in cache\n};\n\ntype CacheEntry<T extends Fn> = {\n value: ReturnType<T>;\n timestamp: number;\n};\n\n/**\n * Creates a function that memorizes the result of the provided function.\n * Supports expiration (TTL) and limited cache size (LRU).\n *\n * @example\n * ```ts\n * const add = (x, y) => x + y;\n * const memoizedAdd = memo(add, { ttl: 5000, maxSize: 10 });\n *\n * memoizedAdd(1, 2); // 3 (caches the result)\n * memoizedAdd(1, 2); // 3 (from cache)\n * ```\n *\n * @param fn - The function to memorize.\n * @param options - Memoization options.\n * @param [options.ttl] - (optional) time-to-live (TTL) for cache expiration (in milliseconds).\n * @param [options.maxSize] - (optional) maximum cache size (LRU eviction).\n *\n * @returns A new function that memorizes the input function.\n */\nexport function memo<T extends Fn>(\n fn: T,\n { ttl, maxSize }: MemoizeOptions = {},\n): (...args: Parameters<T>) => ReturnType<T> {\n const cache = new Map<string, CacheEntry<T>>();\n\n const keyGen = (args: Parameters<T>): string => {\n if (args.length === 0) return '__empty__';\n if (args.length === 1) {\n const arg = args[0];\n const argType = typeof arg;\n if (argType === 'string' || argType === 'number' || argType === 'boolean') {\n return `${argType}:${arg}`;\n }\n if (arg === null) return 'null';\n if (arg === undefined) return 'undefined';\n }\n return JSON.stringify(args);\n };\n\n return (...args: Parameters<T>): ReturnType<T> => {\n const key = keyGen(args);\n const now = Date.now();\n const cached = cache.get(key);\n\n if (cached && (!ttl || now - cached.timestamp < ttl)) {\n cache.delete(key);\n cache.set(key, cached); // Move to end (most recently used)\n return cached.value;\n }\n\n const result = fn(...args);\n cache.set(key, { timestamp: now, value: result });\n\n if (maxSize && cache.size > maxSize) {\n cache.delete(cache.keys().next().value!); // Remove least recently used\n }\n\n return result;\n };\n}\n"],"names":["memo","fn","ttl","maxSize","cache","keyGen","args","arg","argType","key","now","cached","result"],"mappings":"gFAiCO,SAASA,EACdC,EACA,CAAE,IAAAC,EAAK,QAAAC,CAAA,EAA4B,CAAA,EACQ,CAC3C,MAAMC,MAAY,IAEZC,EAAUC,GAAgC,CAC9C,GAAIA,EAAK,SAAW,EAAG,MAAO,YAC9B,GAAIA,EAAK,SAAW,EAAG,CACrB,MAAMC,EAAMD,EAAK,CAAC,EACZE,EAAU,OAAOD,EACvB,GAAIC,IAAY,UAAYA,IAAY,UAAYA,IAAY,UAC9D,MAAO,GAAGA,CAAO,IAAID,CAAG,GAE1B,GAAIA,IAAQ,KAAM,MAAO,OACzB,GAAIA,IAAQ,OAAW,MAAO,WAChC,CACA,OAAO,KAAK,UAAUD,CAAI,CAC5B,EAEA,MAAO,IAAIA,IAAuC,CAChD,MAAMG,EAAMJ,EAAOC,CAAI,EACjBI,EAAM,KAAK,IAAA,EACXC,EAASP,EAAM,IAAIK,CAAG,EAE5B,GAAIE,IAAW,CAACT,GAAOQ,EAAMC,EAAO,UAAYT,GAC9C,OAAAE,EAAM,OAAOK,CAAG,EAChBL,EAAM,IAAIK,EAAKE,CAAM,EACdA,EAAO,MAGhB,MAAMC,EAASX,EAAG,GAAGK,CAAI,EACzB,OAAAF,EAAM,IAAIK,EAAK,CAAE,UAAWC,EAAK,MAAOE,EAAQ,EAE5CT,GAAWC,EAAM,KAAOD,GAC1BC,EAAM,OAAOA,EAAM,KAAA,EAAO,KAAA,EAAO,KAAM,EAGlCQ,CACT,CACF"}
@@ -0,0 +1,24 @@
1
+ function f(s, { ttl: u, maxSize: i } = {}) {
2
+ const t = /* @__PURE__ */ new Map(), l = (n) => {
3
+ if (n.length === 0) return "__empty__";
4
+ if (n.length === 1) {
5
+ const e = n[0], r = typeof e;
6
+ if (r === "string" || r === "number" || r === "boolean")
7
+ return `${r}:${e}`;
8
+ if (e === null) return "null";
9
+ if (e === void 0) return "undefined";
10
+ }
11
+ return JSON.stringify(n);
12
+ };
13
+ return (...n) => {
14
+ const e = l(n), r = Date.now(), o = t.get(e);
15
+ if (o && (!u || r - o.timestamp < u))
16
+ return t.delete(e), t.set(e, o), o.value;
17
+ const c = s(...n);
18
+ return t.set(e, { timestamp: r, value: c }), i && t.size > i && t.delete(t.keys().next().value), c;
19
+ };
20
+ }
21
+ export {
22
+ f as memo
23
+ };
24
+ //# sourceMappingURL=memo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memo.js","sources":["../../src/function/memo.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noExplicitAny: - */\nimport type { Fn } from '../types';\n\ntype MemoizeOptions = {\n ttl?: number; // Time-to-live in milliseconds\n maxSize?: number; // Maximum number of items in cache\n};\n\ntype CacheEntry<T extends Fn> = {\n value: ReturnType<T>;\n timestamp: number;\n};\n\n/**\n * Creates a function that memorizes the result of the provided function.\n * Supports expiration (TTL) and limited cache size (LRU).\n *\n * @example\n * ```ts\n * const add = (x, y) => x + y;\n * const memoizedAdd = memo(add, { ttl: 5000, maxSize: 10 });\n *\n * memoizedAdd(1, 2); // 3 (caches the result)\n * memoizedAdd(1, 2); // 3 (from cache)\n * ```\n *\n * @param fn - The function to memorize.\n * @param options - Memoization options.\n * @param [options.ttl] - (optional) time-to-live (TTL) for cache expiration (in milliseconds).\n * @param [options.maxSize] - (optional) maximum cache size (LRU eviction).\n *\n * @returns A new function that memorizes the input function.\n */\nexport function memo<T extends Fn>(\n fn: T,\n { ttl, maxSize }: MemoizeOptions = {},\n): (...args: Parameters<T>) => ReturnType<T> {\n const cache = new Map<string, CacheEntry<T>>();\n\n const keyGen = (args: Parameters<T>): string => {\n if (args.length === 0) return '__empty__';\n if (args.length === 1) {\n const arg = args[0];\n const argType = typeof arg;\n if (argType === 'string' || argType === 'number' || argType === 'boolean') {\n return `${argType}:${arg}`;\n }\n if (arg === null) return 'null';\n if (arg === undefined) return 'undefined';\n }\n return JSON.stringify(args);\n };\n\n return (...args: Parameters<T>): ReturnType<T> => {\n const key = keyGen(args);\n const now = Date.now();\n const cached = cache.get(key);\n\n if (cached && (!ttl || now - cached.timestamp < ttl)) {\n cache.delete(key);\n cache.set(key, cached); // Move to end (most recently used)\n return cached.value;\n }\n\n const result = fn(...args);\n cache.set(key, { timestamp: now, value: result });\n\n if (maxSize && cache.size > maxSize) {\n cache.delete(cache.keys().next().value!); // Remove least recently used\n }\n\n return result;\n };\n}\n"],"names":["memo","fn","ttl","maxSize","cache","keyGen","args","arg","argType","key","now","cached","result"],"mappings":"AAiCO,SAASA,EACdC,GACA,EAAE,KAAAC,GAAK,SAAAC,EAAA,IAA4B,CAAA,GACQ;AAC3C,QAAMC,wBAAY,IAAA,GAEZC,IAAS,CAACC,MAAgC;AAC9C,QAAIA,EAAK,WAAW,EAAG,QAAO;AAC9B,QAAIA,EAAK,WAAW,GAAG;AACrB,YAAMC,IAAMD,EAAK,CAAC,GACZE,IAAU,OAAOD;AACvB,UAAIC,MAAY,YAAYA,MAAY,YAAYA,MAAY;AAC9D,eAAO,GAAGA,CAAO,IAAID,CAAG;AAE1B,UAAIA,MAAQ,KAAM,QAAO;AACzB,UAAIA,MAAQ,OAAW,QAAO;AAAA,IAChC;AACA,WAAO,KAAK,UAAUD,CAAI;AAAA,EAC5B;AAEA,SAAO,IAAIA,MAAuC;AAChD,UAAMG,IAAMJ,EAAOC,CAAI,GACjBI,IAAM,KAAK,IAAA,GACXC,IAASP,EAAM,IAAIK,CAAG;AAE5B,QAAIE,MAAW,CAACT,KAAOQ,IAAMC,EAAO,YAAYT;AAC9C,aAAAE,EAAM,OAAOK,CAAG,GAChBL,EAAM,IAAIK,GAAKE,CAAM,GACdA,EAAO;AAGhB,UAAMC,IAASX,EAAG,GAAGK,CAAI;AACzB,WAAAF,EAAM,IAAIK,GAAK,EAAE,WAAWC,GAAK,OAAOE,GAAQ,GAE5CT,KAAWC,EAAM,OAAOD,KAC1BC,EAAM,OAAOA,EAAM,KAAA,EAAO,KAAA,EAAO,KAAM,GAGlCQ;AAAA,EACT;AACF;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=l=>{let e,t=!1;const r=((...n)=>(t||(e=l(...n),t=!0),e));return r.reset=()=>{e=void 0,t=!1},r};exports.once=o;
2
+ //# sourceMappingURL=once.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"once.cjs","sources":["../../src/function/once.ts"],"sourcesContent":["import type { Fn } from '../types';\n\n/**\n * Create a function that runs once and returns the first result.\n *\n * @example\n * ```ts\n * const onceRandom = once(() => Math.random())\n * onceRandom() // 0.3\n * onceRandom() // 0.3\n *\n * onceRandom.reset()\n *\n * onceRandom() // 0.2\n * onceRandom() // 0.2\n * ```\n *\n * @param fn - The function to wrap.\n *\n * @returns A function that can only be called once.\n */\nexport const once = <T extends Fn>(fn: T): T & { reset: () => void } => {\n let result: ReturnType<T> | undefined;\n let called = false;\n\n const wrappedFn = ((...args: Parameters<T>): ReturnType<T> => {\n if (!called) {\n result = fn(...args);\n called = true;\n }\n return result as ReturnType<T>;\n }) as T & { reset: () => void };\n\n wrappedFn.reset = () => {\n result = undefined;\n called = false;\n };\n\n return wrappedFn;\n};\n"],"names":["once","fn","result","called","wrappedFn","args"],"mappings":"gFAqBO,MAAMA,EAAsBC,GAAqC,CACtE,IAAIC,EACAC,EAAS,GAEb,MAAMC,GAAa,IAAIC,KAChBF,IACHD,EAASD,EAAG,GAAGI,CAAI,EACnBF,EAAS,IAEJD,IAGT,OAAAE,EAAU,MAAQ,IAAM,CACtBF,EAAS,OACTC,EAAS,EACX,EAEOC,CACT"}
@@ -0,0 +1,11 @@
1
+ const s = (l) => {
2
+ let e, t = !1;
3
+ const r = ((...n) => (t || (e = l(...n), t = !0), e));
4
+ return r.reset = () => {
5
+ e = void 0, t = !1;
6
+ }, r;
7
+ };
8
+ export {
9
+ s as once
10
+ };
11
+ //# sourceMappingURL=once.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"once.js","sources":["../../src/function/once.ts"],"sourcesContent":["import type { Fn } from '../types';\n\n/**\n * Create a function that runs once and returns the first result.\n *\n * @example\n * ```ts\n * const onceRandom = once(() => Math.random())\n * onceRandom() // 0.3\n * onceRandom() // 0.3\n *\n * onceRandom.reset()\n *\n * onceRandom() // 0.2\n * onceRandom() // 0.2\n * ```\n *\n * @param fn - The function to wrap.\n *\n * @returns A function that can only be called once.\n */\nexport const once = <T extends Fn>(fn: T): T & { reset: () => void } => {\n let result: ReturnType<T> | undefined;\n let called = false;\n\n const wrappedFn = ((...args: Parameters<T>): ReturnType<T> => {\n if (!called) {\n result = fn(...args);\n called = true;\n }\n return result as ReturnType<T>;\n }) as T & { reset: () => void };\n\n wrappedFn.reset = () => {\n result = undefined;\n called = false;\n };\n\n return wrappedFn;\n};\n"],"names":["once","fn","result","called","wrappedFn","args"],"mappings":"AAqBO,MAAMA,IAAO,CAAeC,MAAqC;AACtE,MAAIC,GACAC,IAAS;AAEb,QAAMC,KAAa,IAAIC,OAChBF,MACHD,IAASD,EAAG,GAAGI,CAAI,GACnBF,IAAS,KAEJD;AAGT,SAAAE,EAAU,QAAQ,MAAM;AACtB,IAAAF,IAAS,QACTC,IAAS;AAAA,EACX,GAEOC;AACT;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../typed/isPromise.cjs"),c=require("./assert.cjs");function u(...e){c.assert(e.length>0,"pipe requires at least one function",{args:{fns:e}});const s=e[0],i=e.slice(1);return((...o)=>i.reduce((t,r)=>n.isPromise(t)?t.then(r):r(t),s(...o)))}exports.pipe=u;
2
+ //# sourceMappingURL=pipe.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipe.cjs","sources":["../../src/function/pipe.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noExplicitAny: - */\n\nimport { isPromise } from '../typed/isPromise';\nimport type { FnDynamic } from '../types';\nimport { assert } from './assert';\n\ntype FirstParameters<T> = T extends [infer First extends FnDynamic, ...any] ? Parameters<First> : never;\ntype LastReturnType<T> = T extends [...any, infer Last extends FnDynamic] ? ReturnType<Last> : never;\ntype PipeReturn<T extends FnDynamic[]> = (\n ...args: FirstParameters<T>\n) => LastReturnType<T> extends Promise<any> ? Promise<Awaited<LastReturnType<T>>> : LastReturnType<T>;\n\n/**\n * Pipes multiple functions into a single function. It starts from the leftmost function and proceeds to the right.\n *\n * @example\n * ```ts\n * const add = (x) => x + 2;\n * const multiply = (x) => x * 3;\n * const subtract = (x) => x - 4;\n * const pipedFn = pipe(subtract, multiply, add);\n *\n * pipedFn(5); // ((5-4) * 3) + 2 = 5\n * ```\n *\n * @example\n * ```ts\n * const square = async (x) => x * x;\n * const add = async (x) => x + 2;\n * const pipedFn = pipe(square, add);\n *\n * await pipedFn(4); // (4 * 4) + 2 = 18\n * ```\n *\n * @param fns - List of functions to be piped.\n *\n * @returns A new function that is the pipe of the input functions.\n */\nexport function pipe<T extends FnDynamic[]>(...fns: T) {\n assert(fns.length > 0, 'pipe requires at least one function', { args: { fns } });\n\n const firstFn = fns[0];\n const restFns = fns.slice(1);\n\n return ((...args: FirstParameters<T>) =>\n restFns.reduce((prev, fn) => (isPromise(prev) ? prev.then(fn) : fn(prev)), firstFn(...args))) as PipeReturn<T>;\n}\n"],"names":["pipe","fns","assert","firstFn","restFns","args","prev","fn","isPromise"],"mappings":"oJAsCO,SAASA,KAA+BC,EAAQ,CACrDC,SAAOD,EAAI,OAAS,EAAG,sCAAuC,CAAE,KAAM,CAAE,IAAAA,CAAA,EAAO,EAE/E,MAAME,EAAUF,EAAI,CAAC,EACfG,EAAUH,EAAI,MAAM,CAAC,EAE3B,OAAQ,IAAII,IACVD,EAAQ,OAAO,CAACE,EAAMC,IAAQC,EAAAA,UAAUF,CAAI,EAAIA,EAAK,KAAKC,CAAE,EAAIA,EAAGD,CAAI,EAAIH,EAAQ,GAAGE,CAAI,CAAC,EAC/F"}
@@ -0,0 +1,11 @@
1
+ import { isPromise as n } from "../typed/isPromise.js";
2
+ import { assert as c } from "./assert.js";
3
+ function u(...t) {
4
+ c(t.length > 0, "pipe requires at least one function", { args: { fns: t } });
5
+ const i = t[0], o = t.slice(1);
6
+ return ((...s) => o.reduce((e, r) => n(e) ? e.then(r) : r(e), i(...s)));
7
+ }
8
+ export {
9
+ u as pipe
10
+ };
11
+ //# sourceMappingURL=pipe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipe.js","sources":["../../src/function/pipe.ts"],"sourcesContent":["/** biome-ignore-all lint/suspicious/noExplicitAny: - */\n\nimport { isPromise } from '../typed/isPromise';\nimport type { FnDynamic } from '../types';\nimport { assert } from './assert';\n\ntype FirstParameters<T> = T extends [infer First extends FnDynamic, ...any] ? Parameters<First> : never;\ntype LastReturnType<T> = T extends [...any, infer Last extends FnDynamic] ? ReturnType<Last> : never;\ntype PipeReturn<T extends FnDynamic[]> = (\n ...args: FirstParameters<T>\n) => LastReturnType<T> extends Promise<any> ? Promise<Awaited<LastReturnType<T>>> : LastReturnType<T>;\n\n/**\n * Pipes multiple functions into a single function. It starts from the leftmost function and proceeds to the right.\n *\n * @example\n * ```ts\n * const add = (x) => x + 2;\n * const multiply = (x) => x * 3;\n * const subtract = (x) => x - 4;\n * const pipedFn = pipe(subtract, multiply, add);\n *\n * pipedFn(5); // ((5-4) * 3) + 2 = 5\n * ```\n *\n * @example\n * ```ts\n * const square = async (x) => x * x;\n * const add = async (x) => x + 2;\n * const pipedFn = pipe(square, add);\n *\n * await pipedFn(4); // (4 * 4) + 2 = 18\n * ```\n *\n * @param fns - List of functions to be piped.\n *\n * @returns A new function that is the pipe of the input functions.\n */\nexport function pipe<T extends FnDynamic[]>(...fns: T) {\n assert(fns.length > 0, 'pipe requires at least one function', { args: { fns } });\n\n const firstFn = fns[0];\n const restFns = fns.slice(1);\n\n return ((...args: FirstParameters<T>) =>\n restFns.reduce((prev, fn) => (isPromise(prev) ? prev.then(fn) : fn(prev)), firstFn(...args))) as PipeReturn<T>;\n}\n"],"names":["pipe","fns","assert","firstFn","restFns","args","prev","fn","isPromise"],"mappings":";;AAsCO,SAASA,KAA+BC,GAAQ;AACrD,EAAAC,EAAOD,EAAI,SAAS,GAAG,uCAAuC,EAAE,MAAM,EAAE,KAAAA,EAAA,GAAO;AAE/E,QAAME,IAAUF,EAAI,CAAC,GACfG,IAAUH,EAAI,MAAM,CAAC;AAE3B,UAAQ,IAAII,MACVD,EAAQ,OAAO,CAACE,GAAMC,MAAQC,EAAUF,CAAI,IAAIA,EAAK,KAAKC,CAAE,IAAIA,EAAGD,CAAI,GAAIH,EAAQ,GAAGE,CAAI,CAAC;AAC/F;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function a(o,n={}){const{signal:t,timeout:e=7e3}=n,r=t?AbortSignal.any([AbortSignal.timeout(e),t]):AbortSignal.timeout(e);return Promise.race([o(r),new Promise((c,i)=>{r.addEventListener("abort",()=>i(new Error("Operation aborted")),{once:!0})})])}exports.predict=a;
2
+ //# sourceMappingURL=predict.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predict.cjs","sources":["../../src/function/predict.ts"],"sourcesContent":["/**\n * Creates a Promise that can be aborted using an AbortController.\n *\n * @example\n * ```ts\n * const slowFn = () => new Promise(resolve => setTimeout(() => resolve('slow'), 10000));\n * const fastFn = () => new Promise(resolve => setTimeout(() => resolve('fast'), 5000));\n *\n * predict(slowFn); // rejects after 7 seconds\n * predict(fastFn); // resolves with 'fast' after 5 seconds\n * ```\n *\n * @param fn - The function to execute, which receives an AbortSignal.\n * @param options - The options for the abortable function.\n * @param [options.signal] - The AbortSignal to use for aborting the Promise.\n * @param [options.timeout=7000] - The timeout in milliseconds after which the Promise will be aborted.\n *\n * @returns - A Promise that resolves with the result of the callback or rejects if aborted.\n */\nexport function predict<T>(\n fn: (signal: AbortSignal) => Promise<T>,\n options: { signal?: AbortSignal; timeout?: number } = {},\n): Promise<T> {\n const { signal, timeout = 7000 } = options;\n const abortSignal = signal ? AbortSignal.any([AbortSignal.timeout(timeout), signal]) : AbortSignal.timeout(timeout);\n\n return Promise.race([\n fn(abortSignal),\n new Promise<never>((_, reject) => {\n abortSignal.addEventListener('abort', () => reject(new Error('Operation aborted')), { once: true });\n }),\n ]);\n}\n"],"names":["predict","fn","options","signal","timeout","abortSignal","_","reject"],"mappings":"gFAmBO,SAASA,EACdC,EACAC,EAAsD,GAC1C,CACZ,KAAM,CAAE,OAAAC,EAAQ,QAAAC,EAAU,GAAA,EAASF,EAC7BG,EAAcF,EAAS,YAAY,IAAI,CAAC,YAAY,QAAQC,CAAO,EAAGD,CAAM,CAAC,EAAI,YAAY,QAAQC,CAAO,EAElH,OAAO,QAAQ,KAAK,CAClBH,EAAGI,CAAW,EACd,IAAI,QAAe,CAACC,EAAGC,IAAW,CAChCF,EAAY,iBAAiB,QAAS,IAAME,EAAO,IAAI,MAAM,mBAAmB,CAAC,EAAG,CAAE,KAAM,EAAA,CAAM,CACpG,CAAC,CAAA,CACF,CACH"}
@@ -0,0 +1,13 @@
1
+ function b(o, n = {}) {
2
+ const { signal: t, timeout: e = 7e3 } = n, r = t ? AbortSignal.any([AbortSignal.timeout(e), t]) : AbortSignal.timeout(e);
3
+ return Promise.race([
4
+ o(r),
5
+ new Promise((a, i) => {
6
+ r.addEventListener("abort", () => i(new Error("Operation aborted")), { once: !0 });
7
+ })
8
+ ]);
9
+ }
10
+ export {
11
+ b as predict
12
+ };
13
+ //# sourceMappingURL=predict.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predict.js","sources":["../../src/function/predict.ts"],"sourcesContent":["/**\n * Creates a Promise that can be aborted using an AbortController.\n *\n * @example\n * ```ts\n * const slowFn = () => new Promise(resolve => setTimeout(() => resolve('slow'), 10000));\n * const fastFn = () => new Promise(resolve => setTimeout(() => resolve('fast'), 5000));\n *\n * predict(slowFn); // rejects after 7 seconds\n * predict(fastFn); // resolves with 'fast' after 5 seconds\n * ```\n *\n * @param fn - The function to execute, which receives an AbortSignal.\n * @param options - The options for the abortable function.\n * @param [options.signal] - The AbortSignal to use for aborting the Promise.\n * @param [options.timeout=7000] - The timeout in milliseconds after which the Promise will be aborted.\n *\n * @returns - A Promise that resolves with the result of the callback or rejects if aborted.\n */\nexport function predict<T>(\n fn: (signal: AbortSignal) => Promise<T>,\n options: { signal?: AbortSignal; timeout?: number } = {},\n): Promise<T> {\n const { signal, timeout = 7000 } = options;\n const abortSignal = signal ? AbortSignal.any([AbortSignal.timeout(timeout), signal]) : AbortSignal.timeout(timeout);\n\n return Promise.race([\n fn(abortSignal),\n new Promise<never>((_, reject) => {\n abortSignal.addEventListener('abort', () => reject(new Error('Operation aborted')), { once: true });\n }),\n ]);\n}\n"],"names":["predict","fn","options","signal","timeout","abortSignal","_","reject"],"mappings":"AAmBO,SAASA,EACdC,GACAC,IAAsD,IAC1C;AACZ,QAAM,EAAE,QAAAC,GAAQ,SAAAC,IAAU,IAAA,IAASF,GAC7BG,IAAcF,IAAS,YAAY,IAAI,CAAC,YAAY,QAAQC,CAAO,GAAGD,CAAM,CAAC,IAAI,YAAY,QAAQC,CAAO;AAElH,SAAO,QAAQ,KAAK;AAAA,IAClBH,EAAGI,CAAW;AAAA,IACd,IAAI,QAAe,CAACC,GAAGC,MAAW;AAChC,MAAAF,EAAY,iBAAiB,SAAS,MAAME,EAAO,IAAI,MAAM,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAA,CAAM;AAAA,IACpG,CAAC;AAAA,EAAA,CACF;AACH;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../typed/isObject.cjs");function l(y,u){const{set:i,get:d,deep:b=!1,watch:s}=u,R={get(t,e,c){if(s&&!s.includes(e))return Reflect.get(t,e,c);let n=Reflect.get(t,e,c);return d&&(n=d(e,n,t)),b&&r.isObject(n)?l(n,u):n},set(t,e,c,n){if(s&&!s.includes(e))return Reflect.set(t,e,c,n);const j=t[e],f=i?i(e,c,j,t):c;return b&&r.isObject(f)?Reflect.set(t,e,l(f,u),n):Reflect.set(t,e,f,n)}};return new Proxy(y,R)}exports.proxy=l;
2
+ //# sourceMappingURL=proxy.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy.cjs","sources":["../../src/function/proxy.ts"],"sourcesContent":["import { isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\ntype ProxyOptions<T> = {\n set?: <K extends PropertyKey>(prop: K, curr: unknown, prev: unknown, target: T) => unknown;\n get?: <K extends PropertyKey>(prop: K, val: unknown, target: T) => unknown;\n deep?: boolean;\n watch?: (keyof T)[];\n};\n\n/**\n * Creates a new Proxy for the given object that invokes functions when properties are accessed or modified.\n\n * @example\n * ```ts\n * const obj = { a: 1, b: 2 };\n * const log = (prop, curr, prev, target) => console.log(`Property '${prop}' changed from ${prev} to ${curr}`);\n * const proxyObj = proxy(obj, { set: log });\n * proxyObj.a = 3; // logs 'Property 'a' changed from 1 to 3'\n * ```\n *\n * @param item - The object to observe.\n * @param options - Configuration options for the proxy.\n * @param [options.set] - A function to call when a property is set. It receives the property name, current value, previous value, and the target object.\n * @param [options.get] - A function to call when a property is accessed. It receives the property name, value, and the target object.\n * @param [options.deep] - If true, the proxy will also apply to nested objects.\n * @param [options.watch] - An array of property names to watch. If provided, only these properties will trigger the set and get functions.\n *\n * @returns A new Proxy for the given object.\n */\nexport function proxy<T extends Obj>(item: T, options: ProxyOptions<T>): T {\n const { set, get, deep = false, watch } = options;\n\n const handler: ProxyHandler<T> = {\n get(target, prop, receiver) {\n if (watch && !watch.includes(prop as keyof T)) {\n return Reflect.get(target, prop, receiver);\n }\n\n let value = Reflect.get(target, prop, receiver);\n\n if (get) {\n // biome-ignore lint/suspicious/noExplicitAny: -\n value = get(prop, value, target) as any;\n }\n\n if (deep && isObject(value)) {\n return proxy(value as T[keyof T], options);\n }\n\n return value;\n },\n set(target, prop, val, receiver) {\n if (watch && !watch.includes(prop as keyof T)) {\n return Reflect.set(target, prop, val, receiver);\n }\n\n const prev = target[prop as keyof T];\n const value = set ? set(prop, val, prev, target) : val;\n\n if (deep && isObject(value)) {\n return Reflect.set(target, prop, proxy(value as T[keyof T], options), receiver);\n }\n\n return Reflect.set(target, prop, value, receiver);\n },\n };\n\n return new Proxy(item, handler);\n}\n"],"names":["proxy","item","options","set","get","deep","watch","handler","target","prop","receiver","value","isObject","val","prev"],"mappings":"yHA8BO,SAASA,EAAqBC,EAASC,EAA6B,CACzE,KAAM,CAAE,IAAAC,EAAK,IAAAC,EAAK,KAAAC,EAAO,GAAO,MAAAC,GAAUJ,EAEpCK,EAA2B,CAC/B,IAAIC,EAAQC,EAAMC,EAAU,CAC1B,GAAIJ,GAAS,CAACA,EAAM,SAASG,CAAe,EAC1C,OAAO,QAAQ,IAAID,EAAQC,EAAMC,CAAQ,EAG3C,IAAIC,EAAQ,QAAQ,IAAIH,EAAQC,EAAMC,CAAQ,EAO9C,OALIN,IAEFO,EAAQP,EAAIK,EAAME,EAAOH,CAAM,GAG7BH,GAAQO,WAASD,CAAK,EACjBX,EAAMW,EAAqBT,CAAO,EAGpCS,CACT,EACA,IAAIH,EAAQC,EAAMI,EAAKH,EAAU,CAC/B,GAAIJ,GAAS,CAACA,EAAM,SAASG,CAAe,EAC1C,OAAO,QAAQ,IAAID,EAAQC,EAAMI,EAAKH,CAAQ,EAGhD,MAAMI,EAAON,EAAOC,CAAe,EAC7BE,EAAQR,EAAMA,EAAIM,EAAMI,EAAKC,EAAMN,CAAM,EAAIK,EAEnD,OAAIR,GAAQO,WAASD,CAAK,EACjB,QAAQ,IAAIH,EAAQC,EAAMT,EAAMW,EAAqBT,CAAO,EAAGQ,CAAQ,EAGzE,QAAQ,IAAIF,EAAQC,EAAME,EAAOD,CAAQ,CAClD,CAAA,EAGF,OAAO,IAAI,MAAMT,EAAMM,CAAO,CAChC"}
@@ -0,0 +1,22 @@
1
+ import { isObject as d } from "../typed/isObject.js";
2
+ function x(h, c) {
3
+ const { set: l, get: i, deep: R = !1, watch: u } = c, m = {
4
+ get(t, e, f) {
5
+ if (u && !u.includes(e))
6
+ return Reflect.get(t, e, f);
7
+ let n = Reflect.get(t, e, f);
8
+ return i && (n = i(e, n, t)), R && d(n) ? x(n, c) : n;
9
+ },
10
+ set(t, e, f, n) {
11
+ if (u && !u.includes(e))
12
+ return Reflect.set(t, e, f, n);
13
+ const w = t[e], s = l ? l(e, f, w, t) : f;
14
+ return R && d(s) ? Reflect.set(t, e, x(s, c), n) : Reflect.set(t, e, s, n);
15
+ }
16
+ };
17
+ return new Proxy(h, m);
18
+ }
19
+ export {
20
+ x as proxy
21
+ };
22
+ //# sourceMappingURL=proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy.js","sources":["../../src/function/proxy.ts"],"sourcesContent":["import { isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\ntype ProxyOptions<T> = {\n set?: <K extends PropertyKey>(prop: K, curr: unknown, prev: unknown, target: T) => unknown;\n get?: <K extends PropertyKey>(prop: K, val: unknown, target: T) => unknown;\n deep?: boolean;\n watch?: (keyof T)[];\n};\n\n/**\n * Creates a new Proxy for the given object that invokes functions when properties are accessed or modified.\n\n * @example\n * ```ts\n * const obj = { a: 1, b: 2 };\n * const log = (prop, curr, prev, target) => console.log(`Property '${prop}' changed from ${prev} to ${curr}`);\n * const proxyObj = proxy(obj, { set: log });\n * proxyObj.a = 3; // logs 'Property 'a' changed from 1 to 3'\n * ```\n *\n * @param item - The object to observe.\n * @param options - Configuration options for the proxy.\n * @param [options.set] - A function to call when a property is set. It receives the property name, current value, previous value, and the target object.\n * @param [options.get] - A function to call when a property is accessed. It receives the property name, value, and the target object.\n * @param [options.deep] - If true, the proxy will also apply to nested objects.\n * @param [options.watch] - An array of property names to watch. If provided, only these properties will trigger the set and get functions.\n *\n * @returns A new Proxy for the given object.\n */\nexport function proxy<T extends Obj>(item: T, options: ProxyOptions<T>): T {\n const { set, get, deep = false, watch } = options;\n\n const handler: ProxyHandler<T> = {\n get(target, prop, receiver) {\n if (watch && !watch.includes(prop as keyof T)) {\n return Reflect.get(target, prop, receiver);\n }\n\n let value = Reflect.get(target, prop, receiver);\n\n if (get) {\n // biome-ignore lint/suspicious/noExplicitAny: -\n value = get(prop, value, target) as any;\n }\n\n if (deep && isObject(value)) {\n return proxy(value as T[keyof T], options);\n }\n\n return value;\n },\n set(target, prop, val, receiver) {\n if (watch && !watch.includes(prop as keyof T)) {\n return Reflect.set(target, prop, val, receiver);\n }\n\n const prev = target[prop as keyof T];\n const value = set ? set(prop, val, prev, target) : val;\n\n if (deep && isObject(value)) {\n return Reflect.set(target, prop, proxy(value as T[keyof T], options), receiver);\n }\n\n return Reflect.set(target, prop, value, receiver);\n },\n };\n\n return new Proxy(item, handler);\n}\n"],"names":["proxy","item","options","set","get","deep","watch","handler","target","prop","receiver","value","isObject","val","prev"],"mappings":";AA8BO,SAASA,EAAqBC,GAASC,GAA6B;AACzE,QAAM,EAAE,KAAAC,GAAK,KAAAC,GAAK,MAAAC,IAAO,IAAO,OAAAC,MAAUJ,GAEpCK,IAA2B;AAAA,IAC/B,IAAIC,GAAQC,GAAMC,GAAU;AAC1B,UAAIJ,KAAS,CAACA,EAAM,SAASG,CAAe;AAC1C,eAAO,QAAQ,IAAID,GAAQC,GAAMC,CAAQ;AAG3C,UAAIC,IAAQ,QAAQ,IAAIH,GAAQC,GAAMC,CAAQ;AAO9C,aALIN,MAEFO,IAAQP,EAAIK,GAAME,GAAOH,CAAM,IAG7BH,KAAQO,EAASD,CAAK,IACjBX,EAAMW,GAAqBT,CAAO,IAGpCS;AAAA,IACT;AAAA,IACA,IAAIH,GAAQC,GAAMI,GAAKH,GAAU;AAC/B,UAAIJ,KAAS,CAACA,EAAM,SAASG,CAAe;AAC1C,eAAO,QAAQ,IAAID,GAAQC,GAAMI,GAAKH,CAAQ;AAGhD,YAAMI,IAAON,EAAOC,CAAe,GAC7BE,IAAQR,IAAMA,EAAIM,GAAMI,GAAKC,GAAMN,CAAM,IAAIK;AAEnD,aAAIR,KAAQO,EAASD,CAAK,IACjB,QAAQ,IAAIH,GAAQC,GAAMT,EAAMW,GAAqBT,CAAO,GAAGQ,CAAQ,IAGzE,QAAQ,IAAIF,GAAQC,GAAME,GAAOD,CAAQ;AAAA,IAClD;AAAA,EAAA;AAGF,SAAO,IAAI,MAAMT,GAAMM,CAAO;AAChC;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../logit/dist/logit.cjs"),c=require("./sleep.cjs");async function u(n,{times:e=3,delay:i=250,backoff:y=1,signal:l}={}){let t=i;for(let r=1;r<=e;r++){if(l?.aborted)throw a.Logit.warn(`retry() -> Aborted after ${r-1} attempts`),new Error("Retry aborted");try{return await n()}catch(o){if(r===e)throw o;a.Logit.warn(`retry() -> ${o}, attempt ${r}/${e}, retrying in ${t}ms`),t>0&&await c.sleep(t),t*=y}}throw new Error("Retry failed unexpectedly")}exports.retry=u;
2
+ //# sourceMappingURL=retry.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.cjs","sources":["../../src/function/retry.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport { sleep } from './sleep';\n\n/**\n * Retries an asynchronous function a specified number of times with delay and optional exponential backoff.\n *\n * @example\n * ```ts\n * retry(() => fetchData(), { times: 3, delay: 1000, backoff: 2, signal: abortSignal })\n * .then(result => console.log(result))\n * .catch(error => console.error(error));\n * ```\n *\n * @param fn - The asynchronous function to retry.\n * @param options - (optional) Options for retrying the function.\n * @param [options.times=3] - The number of retry attempts.\n * @param [options.delay=250] - The delay in milliseconds between retries.\n * @param [options.backoff=1] - Exponential backoff factor (default: 1 → no backoff).\n * @param [options.signal] - `AbortSignal` to allow canceling retries.\n *\n * @returns The result of the asynchronous function.\n */\nexport async function retry<T>(\n fn: () => Promise<T>,\n {\n times = 3,\n delay = 250,\n backoff = 1,\n signal,\n }: {\n times?: number;\n delay?: number;\n backoff?: number;\n signal?: AbortSignal;\n } = {},\n): Promise<T> {\n let currentDelay = delay;\n\n for (let attempt = 1; attempt <= times; attempt++) {\n if (signal?.aborted) {\n Logit.warn(`retry() -> Aborted after ${attempt - 1} attempts`);\n throw new Error('Retry aborted');\n }\n\n try {\n return await fn();\n } catch (err) {\n if (attempt === times) throw err;\n\n Logit.warn(`retry() -> ${err}, attempt ${attempt}/${times}, retrying in ${currentDelay}ms`);\n if (currentDelay > 0) await sleep(currentDelay);\n currentDelay *= backoff;\n }\n }\n\n throw new Error('Retry failed unexpectedly');\n}\n"],"names":["retry","fn","times","delay","backoff","signal","currentDelay","attempt","Logit","err","sleep"],"mappings":"oJAsBA,eAAsBA,EACpBC,EACA,CACE,MAAAC,EAAQ,EACR,MAAAC,EAAQ,IACR,QAAAC,EAAU,EACV,OAAAC,CACF,EAKI,GACQ,CACZ,IAAIC,EAAeH,EAEnB,QAASI,EAAU,EAAGA,GAAWL,EAAOK,IAAW,CACjD,GAAIF,GAAQ,QACVG,MAAAA,EAAAA,MAAM,KAAK,4BAA4BD,EAAU,CAAC,WAAW,EACvD,IAAI,MAAM,eAAe,EAGjC,GAAI,CACF,OAAO,MAAMN,EAAA,CACf,OAASQ,EAAK,CACZ,GAAIF,IAAYL,EAAO,MAAMO,EAE7BD,EAAAA,MAAM,KAAK,cAAcC,CAAG,aAAaF,CAAO,IAAIL,CAAK,iBAAiBI,CAAY,IAAI,EACtFA,EAAe,GAAG,MAAMI,EAAAA,MAAMJ,CAAY,EAC9CA,GAAgBF,CAClB,CACF,CAEA,MAAM,IAAI,MAAM,2BAA2B,CAC7C"}
@@ -0,0 +1,25 @@
1
+ import { Logit as o } from "../logit/dist/logit.js";
2
+ import { sleep as w } from "./sleep.js";
3
+ async function l(n, {
4
+ times: e = 3,
5
+ delay: i = 250,
6
+ backoff: y = 1,
7
+ signal: f
8
+ } = {}) {
9
+ let t = i;
10
+ for (let r = 1; r <= e; r++) {
11
+ if (f?.aborted)
12
+ throw o.warn(`retry() -> Aborted after ${r - 1} attempts`), new Error("Retry aborted");
13
+ try {
14
+ return await n();
15
+ } catch (a) {
16
+ if (r === e) throw a;
17
+ o.warn(`retry() -> ${a}, attempt ${r}/${e}, retrying in ${t}ms`), t > 0 && await w(t), t *= y;
18
+ }
19
+ }
20
+ throw new Error("Retry failed unexpectedly");
21
+ }
22
+ export {
23
+ l as retry
24
+ };
25
+ //# sourceMappingURL=retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.js","sources":["../../src/function/retry.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport { sleep } from './sleep';\n\n/**\n * Retries an asynchronous function a specified number of times with delay and optional exponential backoff.\n *\n * @example\n * ```ts\n * retry(() => fetchData(), { times: 3, delay: 1000, backoff: 2, signal: abortSignal })\n * .then(result => console.log(result))\n * .catch(error => console.error(error));\n * ```\n *\n * @param fn - The asynchronous function to retry.\n * @param options - (optional) Options for retrying the function.\n * @param [options.times=3] - The number of retry attempts.\n * @param [options.delay=250] - The delay in milliseconds between retries.\n * @param [options.backoff=1] - Exponential backoff factor (default: 1 → no backoff).\n * @param [options.signal] - `AbortSignal` to allow canceling retries.\n *\n * @returns The result of the asynchronous function.\n */\nexport async function retry<T>(\n fn: () => Promise<T>,\n {\n times = 3,\n delay = 250,\n backoff = 1,\n signal,\n }: {\n times?: number;\n delay?: number;\n backoff?: number;\n signal?: AbortSignal;\n } = {},\n): Promise<T> {\n let currentDelay = delay;\n\n for (let attempt = 1; attempt <= times; attempt++) {\n if (signal?.aborted) {\n Logit.warn(`retry() -> Aborted after ${attempt - 1} attempts`);\n throw new Error('Retry aborted');\n }\n\n try {\n return await fn();\n } catch (err) {\n if (attempt === times) throw err;\n\n Logit.warn(`retry() -> ${err}, attempt ${attempt}/${times}, retrying in ${currentDelay}ms`);\n if (currentDelay > 0) await sleep(currentDelay);\n currentDelay *= backoff;\n }\n }\n\n throw new Error('Retry failed unexpectedly');\n}\n"],"names":["retry","fn","times","delay","backoff","signal","currentDelay","attempt","Logit","err","sleep"],"mappings":";;AAsBA,eAAsBA,EACpBC,GACA;AAAA,EACE,OAAAC,IAAQ;AAAA,EACR,OAAAC,IAAQ;AAAA,EACR,SAAAC,IAAU;AAAA,EACV,QAAAC;AACF,IAKI,IACQ;AACZ,MAAIC,IAAeH;AAEnB,WAASI,IAAU,GAAGA,KAAWL,GAAOK,KAAW;AACjD,QAAIF,GAAQ;AACVG,YAAAA,EAAM,KAAK,4BAA4BD,IAAU,CAAC,WAAW,GACvD,IAAI,MAAM,eAAe;AAGjC,QAAI;AACF,aAAO,MAAMN,EAAA;AAAA,IACf,SAASQ,GAAK;AACZ,UAAIF,MAAYL,EAAO,OAAMO;AAE7BD,MAAAA,EAAM,KAAK,cAAcC,CAAG,aAAaF,CAAO,IAAIL,CAAK,iBAAiBI,CAAY,IAAI,GACtFA,IAAe,KAAG,MAAMI,EAAMJ,CAAY,GAC9CA,KAAgBF;AAAA,IAClB;AAAA,EACF;AAEA,QAAM,IAAI,MAAM,2BAA2B;AAC7C;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});async function n(e){return new Promise(t=>setTimeout(t,e))}exports.sleep=n;
2
+ //# sourceMappingURL=sleep.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sleep.cjs","sources":["../../src/function/sleep.ts"],"sourcesContent":["/**\n * Creates a Promise that resolves after a specified amount of time.\n *\n * @example\n * ```ts\n * sleep(1000).then(() => console.log('Hello, world!')); // logs 'Hello, world!' after 1 second\n * ```\n *\n * @param timeout - The number of milliseconds to wait before resolving the Promise.\n *\n * @returns A Promise that resolves after the specified time.\n */\nexport async function sleep(timeout: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, timeout));\n}\n"],"names":["sleep","timeout","resolve"],"mappings":"gFAYA,eAAsBA,EAAMC,EAAgC,CAC1D,OAAO,IAAI,QAASC,GAAY,WAAWA,EAASD,CAAO,CAAC,CAC9D"}
@@ -0,0 +1,7 @@
1
+ async function t(e) {
2
+ return new Promise((n) => setTimeout(n, e));
3
+ }
4
+ export {
5
+ t as sleep
6
+ };
7
+ //# sourceMappingURL=sleep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sleep.js","sources":["../../src/function/sleep.ts"],"sourcesContent":["/**\n * Creates a Promise that resolves after a specified amount of time.\n *\n * @example\n * ```ts\n * sleep(1000).then(() => console.log('Hello, world!')); // logs 'Hello, world!' after 1 second\n * ```\n *\n * @param timeout - The number of milliseconds to wait before resolving the Promise.\n *\n * @returns A Promise that resolves after the specified time.\n */\nexport async function sleep(timeout: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, timeout));\n}\n"],"names":["sleep","timeout","resolve"],"mappings":"AAYA,eAAsBA,EAAMC,GAAgC;AAC1D,SAAO,IAAI,QAAQ,CAACC,MAAY,WAAWA,GAASD,CAAO,CAAC;AAC9D;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(o,n=700){let t=0;return(...r)=>{const e=Date.now();e-t>=n&&(t=e,o(...r))}}exports.throttle=l;
2
+ //# sourceMappingURL=throttle.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throttle.cjs","sources":["../../src/function/throttle.ts"],"sourcesContent":["import type { Fn } from '../types';\n\n/**\n * Creates a throttled function that only invokes the provided function at most once per every specified milliseconds.\n *\n * @example\n * ```ts\n * const log = () => console.log('Hello, world!');\n * const throttledLog = throttle(log, 1000);\n *\n * throttledLog(); // logs 'Hello, world!' immediately\n * throttledLog(); // does nothing because less than 1 second has passed since the last invocation\n * setTimeout(throttledLog, 1000); // logs 'Hello, world!' after 1 second\n * ```\n *\n * @param fn - The function to throttle.\n * @param [delay=700] - The number of milliseconds to wait before invoking the function again.\n *\n * @returns A new function that throttles the input function.\n */\nexport function throttle<T extends Fn>(fn: T, delay = 700): (...args: Parameters<T>) => void {\n let elapsed = 0;\n\n return (...args: Parameters<T>) => {\n const now = Date.now();\n\n if (now - elapsed >= delay) {\n elapsed = now;\n fn(...args);\n }\n };\n}\n"],"names":["throttle","fn","delay","elapsed","args","now"],"mappings":"gFAoBO,SAASA,EAAuBC,EAAOC,EAAQ,IAAuC,CAC3F,IAAIC,EAAU,EAEd,MAAO,IAAIC,IAAwB,CACjC,MAAMC,EAAM,KAAK,IAAA,EAEbA,EAAMF,GAAWD,IACnBC,EAAUE,EACVJ,EAAG,GAAGG,CAAI,EAEd,CACF"}
@@ -0,0 +1,11 @@
1
+ function l(n, o = 700) {
2
+ let t = 0;
3
+ return (...r) => {
4
+ const e = Date.now();
5
+ e - t >= o && (t = e, n(...r));
6
+ };
7
+ }
8
+ export {
9
+ l as throttle
10
+ };
11
+ //# sourceMappingURL=throttle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throttle.js","sources":["../../src/function/throttle.ts"],"sourcesContent":["import type { Fn } from '../types';\n\n/**\n * Creates a throttled function that only invokes the provided function at most once per every specified milliseconds.\n *\n * @example\n * ```ts\n * const log = () => console.log('Hello, world!');\n * const throttledLog = throttle(log, 1000);\n *\n * throttledLog(); // logs 'Hello, world!' immediately\n * throttledLog(); // does nothing because less than 1 second has passed since the last invocation\n * setTimeout(throttledLog, 1000); // logs 'Hello, world!' after 1 second\n * ```\n *\n * @param fn - The function to throttle.\n * @param [delay=700] - The number of milliseconds to wait before invoking the function again.\n *\n * @returns A new function that throttles the input function.\n */\nexport function throttle<T extends Fn>(fn: T, delay = 700): (...args: Parameters<T>) => void {\n let elapsed = 0;\n\n return (...args: Parameters<T>) => {\n const now = Date.now();\n\n if (now - elapsed >= delay) {\n elapsed = now;\n fn(...args);\n }\n };\n}\n"],"names":["throttle","fn","delay","elapsed","args","now"],"mappings":"AAoBO,SAASA,EAAuBC,GAAOC,IAAQ,KAAuC;AAC3F,MAAIC,IAAU;AAEd,SAAO,IAAIC,MAAwB;AACjC,UAAMC,IAAM,KAAK,IAAA;AAEjB,IAAIA,IAAMF,KAAWD,MACnBC,IAAUE,GACVJ,EAAG,GAAGG,CAAI;AAAA,EAEd;AACF;"}
@@ -0,0 +1,14 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function p(c,n=[]){const l=c.toString(),i=`
2
+ ${n.map(s=>`importScripts('${s}');`).join(`
3
+ `)}
4
+ const callback = (${l})(self);
5
+ self.onmessage = async function(e) {
6
+ try {
7
+ const result = await callback(...e.data.args);
8
+ self.postMessage({ success: true, result });
9
+ } catch (error) {
10
+ self.postMessage({ success: false, error: error?.message || String(error) });
11
+ }
12
+ };
13
+ `,u=new Blob([i],{type:"application/javascript"}),t=URL.createObjectURL(u);return(...s)=>new Promise((g,o)=>{const r=new Worker(t),a=()=>{r.terminate(),URL.revokeObjectURL(t)};r.onmessage=e=>{a(),e.data.success?g(e.data.result):o(new Error(e.data.error))},r.onerror=e=>{a(),o(new Error(e.message||"Worker error occurred"))},r.postMessage({args:s})})}exports.worker=p;
14
+ //# sourceMappingURL=worker.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.cjs","sources":["../../src/function/worker.ts"],"sourcesContent":["/**\n * Creates a function that runs the provided callback in a web worker with specified dependencies.\n *\n * @example\n * const sum = worker(({ _ }) => (...args) => _.sum([...args]), ['https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js']);\n * await sum(1, 2); // 3\n *\n * @param callback - A function that receives the worker's `self` and performs work.\n * @param dependencies - (optional) array of URLs to scripts that the worker should import.\n *\n * @returns A function that takes the arguments for the callback and returns a promise with the result.\n */\n// biome-ignore lint/suspicious/noExplicitAny: -\nexport function worker<T extends (...args: any) => any, R = Awaited<ReturnType<T>>>(\n // biome-ignore lint/suspicious/noExplicitAny: -\n callback: (self: any) => T,\n dependencies: string[] = [],\n): (...args: Parameters<T>) => Promise<R> {\n const callbackString = callback.toString();\n const workerScript = `\n ${dependencies.map((dep) => `importScripts('${dep}');`).join('\\n')}\n const callback = (${callbackString})(self);\n self.onmessage = async function(e) {\n try {\n const result = await callback(...e.data.args);\n self.postMessage({ success: true, result });\n } catch (error) {\n self.postMessage({ success: false, error: error?.message || String(error) });\n }\n };\n `;\n const blob = new Blob([workerScript], { type: 'application/javascript' });\n const workerUrl = URL.createObjectURL(blob);\n\n return (...args: Parameters<T>): Promise<R> =>\n new Promise((resolve, reject) => {\n const workerInstance = new Worker(workerUrl);\n\n const cleanup = () => {\n workerInstance.terminate();\n URL.revokeObjectURL(workerUrl);\n };\n\n workerInstance.onmessage = (e) => {\n cleanup();\n if (e.data.success) {\n resolve(e.data.result);\n } else {\n reject(new Error(e.data.error));\n }\n };\n\n workerInstance.onerror = (err) => {\n cleanup();\n reject(new Error(err.message || 'Worker error occurred'));\n };\n\n workerInstance.postMessage({ args });\n });\n}\n"],"names":["worker","callback","dependencies","callbackString","workerScript","dep","blob","workerUrl","args","resolve","reject","workerInstance","cleanup","err"],"mappings":"gFAaO,SAASA,EAEdC,EACAC,EAAyB,GACe,CACxC,MAAMC,EAAiBF,EAAS,SAAA,EAC1BG,EAAe;AAAA,MACjBF,EAAa,IAAKG,GAAQ,kBAAkBA,CAAG,KAAK,EAAE,KAAK;AAAA,CAAI,CAAC;AAAA,wBAC9CF,CAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAU9BG,EAAO,IAAI,KAAK,CAACF,CAAY,EAAG,CAAE,KAAM,yBAA0B,EAClEG,EAAY,IAAI,gBAAgBD,CAAI,EAE1C,MAAO,IAAIE,IACT,IAAI,QAAQ,CAACC,EAASC,IAAW,CAC/B,MAAMC,EAAiB,IAAI,OAAOJ,CAAS,EAErCK,EAAU,IAAM,CACpBD,EAAe,UAAA,EACf,IAAI,gBAAgBJ,CAAS,CAC/B,EAEAI,EAAe,UAAa,GAAM,CAChCC,EAAA,EACI,EAAE,KAAK,QACTH,EAAQ,EAAE,KAAK,MAAM,EAErBC,EAAO,IAAI,MAAM,EAAE,KAAK,KAAK,CAAC,CAElC,EAEAC,EAAe,QAAWE,GAAQ,CAChCD,EAAA,EACAF,EAAO,IAAI,MAAMG,EAAI,SAAW,uBAAuB,CAAC,CAC1D,EAEAF,EAAe,YAAY,CAAE,KAAAH,EAAM,CACrC,CAAC,CACL"}
@@ -0,0 +1,29 @@
1
+ function g(c, n = []) {
2
+ const l = c.toString(), i = `
3
+ ${n.map((s) => `importScripts('${s}');`).join(`
4
+ `)}
5
+ const callback = (${l})(self);
6
+ self.onmessage = async function(e) {
7
+ try {
8
+ const result = await callback(...e.data.args);
9
+ self.postMessage({ success: true, result });
10
+ } catch (error) {
11
+ self.postMessage({ success: false, error: error?.message || String(error) });
12
+ }
13
+ };
14
+ `, p = new Blob([i], { type: "application/javascript" }), o = URL.createObjectURL(p);
15
+ return (...s) => new Promise((u, t) => {
16
+ const e = new Worker(o), a = () => {
17
+ e.terminate(), URL.revokeObjectURL(o);
18
+ };
19
+ e.onmessage = (r) => {
20
+ a(), r.data.success ? u(r.data.result) : t(new Error(r.data.error));
21
+ }, e.onerror = (r) => {
22
+ a(), t(new Error(r.message || "Worker error occurred"));
23
+ }, e.postMessage({ args: s });
24
+ });
25
+ }
26
+ export {
27
+ g as worker
28
+ };
29
+ //# sourceMappingURL=worker.js.map