@vielzeug/toolkit 1.1.3 → 2.1.0

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 (764) hide show
  1. package/README.md +325 -452
  2. package/dist/array/chunk.cjs +2 -2
  3. package/dist/array/chunk.cjs.map +1 -1
  4. package/dist/array/chunk.d.ts +29 -0
  5. package/dist/array/chunk.d.ts.map +1 -0
  6. package/dist/array/chunk.js +22 -24
  7. package/dist/array/chunk.js.map +1 -1
  8. package/dist/array/contains.cjs +2 -2
  9. package/dist/array/contains.cjs.map +1 -1
  10. package/dist/array/contains.d.ts +19 -0
  11. package/dist/array/contains.d.ts.map +1 -0
  12. package/dist/array/contains.js +12 -9
  13. package/dist/array/contains.js.map +1 -1
  14. package/dist/array/fold.cjs +2 -0
  15. package/dist/array/fold.cjs.map +1 -0
  16. package/dist/array/fold.d.ts +21 -0
  17. package/dist/array/fold.d.ts.map +1 -0
  18. package/dist/array/fold.js +19 -0
  19. package/dist/array/fold.js.map +1 -0
  20. package/dist/array/group.cjs +2 -2
  21. package/dist/array/group.cjs.map +1 -1
  22. package/dist/array/group.d.ts +19 -0
  23. package/dist/array/group.d.ts.map +1 -0
  24. package/dist/array/group.js +18 -15
  25. package/dist/array/group.js.map +1 -1
  26. package/dist/array/index.d.ts +16 -0
  27. package/dist/array/index.d.ts.map +1 -0
  28. package/dist/array/keyBy.cjs +2 -0
  29. package/dist/array/keyBy.cjs.map +1 -0
  30. package/dist/array/keyBy.d.ts +20 -0
  31. package/dist/array/keyBy.d.ts.map +1 -0
  32. package/dist/array/keyBy.js +19 -0
  33. package/dist/array/keyBy.js.map +1 -0
  34. package/dist/array/list.cjs +2 -2
  35. package/dist/array/list.cjs.map +1 -1
  36. package/dist/array/list.d.ts +58 -0
  37. package/dist/array/list.d.ts.map +1 -0
  38. package/dist/array/list.js +103 -106
  39. package/dist/array/list.js.map +1 -1
  40. package/dist/array/pick.cjs +2 -2
  41. package/dist/array/pick.cjs.map +1 -1
  42. package/dist/array/pick.d.ts +19 -0
  43. package/dist/array/pick.d.ts.map +1 -0
  44. package/dist/array/pick.js +15 -14
  45. package/dist/array/pick.js.map +1 -1
  46. package/dist/array/remoteList.cjs +2 -2
  47. package/dist/array/remoteList.cjs.map +1 -1
  48. package/dist/array/remoteList.d.ts +64 -0
  49. package/dist/array/remoteList.d.ts.map +1 -0
  50. package/dist/array/remoteList.js +121 -122
  51. package/dist/array/remoteList.js.map +1 -1
  52. package/dist/array/replace.cjs +2 -0
  53. package/dist/array/replace.cjs.map +1 -0
  54. package/dist/array/replace.d.ts +20 -0
  55. package/dist/array/replace.d.ts.map +1 -0
  56. package/dist/array/replace.js +19 -0
  57. package/dist/array/replace.js.map +1 -0
  58. package/dist/array/rotate.cjs +2 -0
  59. package/dist/array/rotate.cjs.map +1 -0
  60. package/dist/array/rotate.d.ts +22 -0
  61. package/dist/array/rotate.d.ts.map +1 -0
  62. package/dist/array/rotate.js +19 -0
  63. package/dist/array/rotate.js.map +1 -0
  64. package/dist/array/search.cjs +2 -2
  65. package/dist/array/search.cjs.map +1 -1
  66. package/dist/array/search.d.ts +19 -0
  67. package/dist/array/search.d.ts.map +1 -0
  68. package/dist/array/search.js +23 -13
  69. package/dist/array/search.js.map +1 -1
  70. package/dist/array/select.cjs +2 -2
  71. package/dist/array/select.cjs.map +1 -1
  72. package/dist/array/select.d.ts +21 -0
  73. package/dist/array/select.d.ts.map +1 -0
  74. package/dist/array/select.js +16 -15
  75. package/dist/array/select.js.map +1 -1
  76. package/dist/array/sort.cjs +2 -2
  77. package/dist/array/sort.cjs.map +1 -1
  78. package/dist/array/sort.d.ts +26 -0
  79. package/dist/array/sort.d.ts.map +1 -0
  80. package/dist/array/sort.js +18 -12
  81. package/dist/array/sort.js.map +1 -1
  82. package/dist/array/toggle.cjs +2 -0
  83. package/dist/array/toggle.cjs.map +1 -0
  84. package/dist/array/toggle.d.ts +29 -0
  85. package/dist/array/toggle.d.ts.map +1 -0
  86. package/dist/array/toggle.js +9 -0
  87. package/dist/array/toggle.js.map +1 -0
  88. package/dist/array/uniq.cjs +2 -2
  89. package/dist/array/uniq.cjs.map +1 -1
  90. package/dist/array/uniq.d.ts +21 -0
  91. package/dist/array/uniq.d.ts.map +1 -0
  92. package/dist/array/uniq.js +15 -17
  93. package/dist/array/uniq.js.map +1 -1
  94. package/dist/async/attempt.cjs +2 -2
  95. package/dist/async/attempt.cjs.map +1 -1
  96. package/dist/async/attempt.d.ts +40 -0
  97. package/dist/async/attempt.d.ts.map +1 -0
  98. package/dist/async/attempt.js +19 -14
  99. package/dist/async/attempt.js.map +1 -1
  100. package/dist/async/defer.cjs +2 -2
  101. package/dist/async/defer.cjs.map +1 -1
  102. package/dist/async/defer.d.ts +23 -0
  103. package/dist/async/defer.d.ts.map +1 -0
  104. package/dist/async/defer.js +12 -9
  105. package/dist/async/defer.js.map +1 -1
  106. package/dist/async/index.d.ts +12 -0
  107. package/dist/async/index.d.ts.map +1 -0
  108. package/dist/async/parallel.cjs +2 -2
  109. package/dist/async/parallel.cjs.map +1 -1
  110. package/dist/async/parallel.d.ts +31 -0
  111. package/dist/async/parallel.d.ts.map +1 -0
  112. package/dist/async/parallel.js +26 -27
  113. package/dist/async/parallel.js.map +1 -1
  114. package/dist/async/pool.cjs +2 -2
  115. package/dist/async/pool.cjs.map +1 -1
  116. package/dist/async/pool.d.ts +21 -0
  117. package/dist/async/pool.d.ts.map +1 -0
  118. package/dist/async/pool.js +23 -21
  119. package/dist/async/pool.js.map +1 -1
  120. package/dist/async/predict.cjs +2 -2
  121. package/dist/async/predict.cjs.map +1 -1
  122. package/dist/async/predict.d.ts +24 -0
  123. package/dist/async/predict.d.ts.map +1 -0
  124. package/dist/async/predict.js +10 -12
  125. package/dist/async/predict.js.map +1 -1
  126. package/dist/async/queue.cjs +2 -2
  127. package/dist/async/queue.cjs.map +1 -1
  128. package/dist/async/queue.d.ts +43 -0
  129. package/dist/async/queue.d.ts.map +1 -0
  130. package/dist/async/queue.js +52 -56
  131. package/dist/async/queue.js.map +1 -1
  132. package/dist/async/race.cjs +2 -2
  133. package/dist/async/race.cjs.map +1 -1
  134. package/dist/async/race.d.ts +16 -0
  135. package/dist/async/race.d.ts.map +1 -0
  136. package/dist/async/race.js +8 -7
  137. package/dist/async/race.js.map +1 -1
  138. package/dist/async/retry.cjs +2 -2
  139. package/dist/async/retry.cjs.map +1 -1
  140. package/dist/async/retry.d.ts +32 -0
  141. package/dist/async/retry.d.ts.map +1 -0
  142. package/dist/async/retry.js +19 -24
  143. package/dist/async/retry.js.map +1 -1
  144. package/dist/async/scheduler.cjs +2 -0
  145. package/dist/async/scheduler.cjs.map +1 -0
  146. package/dist/async/scheduler.d.ts +51 -0
  147. package/dist/async/scheduler.d.ts.map +1 -0
  148. package/dist/async/scheduler.js +43 -0
  149. package/dist/async/scheduler.js.map +1 -0
  150. package/dist/async/sleep.cjs +2 -2
  151. package/dist/async/sleep.cjs.map +1 -1
  152. package/dist/async/sleep.d.ts +16 -0
  153. package/dist/async/sleep.d.ts.map +1 -0
  154. package/dist/async/sleep.js +11 -11
  155. package/dist/async/sleep.js.map +1 -1
  156. package/dist/async/waitFor.cjs +2 -2
  157. package/dist/async/waitFor.cjs.map +1 -1
  158. package/dist/async/waitFor.d.ts +33 -0
  159. package/dist/async/waitFor.d.ts.map +1 -0
  160. package/dist/async/waitFor.js +29 -36
  161. package/dist/async/waitFor.js.map +1 -1
  162. package/dist/date/expires.cjs +2 -2
  163. package/dist/date/expires.cjs.map +1 -1
  164. package/dist/date/expires.d.ts +15 -0
  165. package/dist/date/expires.d.ts.map +1 -0
  166. package/dist/date/expires.js +11 -10
  167. package/dist/date/expires.js.map +1 -1
  168. package/dist/date/index.d.ts +4 -0
  169. package/dist/date/index.d.ts.map +1 -0
  170. package/dist/date/interval.cjs +2 -2
  171. package/dist/date/interval.cjs.map +1 -1
  172. package/dist/date/interval.d.ts +25 -0
  173. package/dist/date/interval.d.ts.map +1 -0
  174. package/dist/date/interval.js +31 -37
  175. package/dist/date/interval.js.map +1 -1
  176. package/dist/date/timeDiff.cjs +2 -2
  177. package/dist/date/timeDiff.cjs.map +1 -1
  178. package/dist/date/timeDiff.d.ts +24 -0
  179. package/dist/date/timeDiff.d.ts.map +1 -0
  180. package/dist/date/timeDiff.js +58 -25
  181. package/dist/date/timeDiff.js.map +1 -1
  182. package/dist/function/assert.cjs +2 -3
  183. package/dist/function/assert.cjs.map +1 -1
  184. package/dist/function/assert.d.ts +38 -0
  185. package/dist/function/assert.d.ts.map +1 -0
  186. package/dist/function/assert.js +13 -11
  187. package/dist/function/assert.js.map +1 -1
  188. package/dist/function/assertParams.cjs +2 -2
  189. package/dist/function/assertParams.cjs.map +1 -1
  190. package/dist/function/assertParams.d.ts +24 -0
  191. package/dist/function/assertParams.d.ts.map +1 -0
  192. package/dist/function/assertParams.js +13 -12
  193. package/dist/function/assertParams.js.map +1 -1
  194. package/dist/function/compare.cjs +2 -2
  195. package/dist/function/compare.cjs.map +1 -1
  196. package/dist/function/compare.d.ts +23 -0
  197. package/dist/function/compare.d.ts.map +1 -0
  198. package/dist/function/compare.js +22 -21
  199. package/dist/function/compare.js.map +1 -1
  200. package/dist/function/compareBy.cjs +2 -2
  201. package/dist/function/compareBy.cjs.map +1 -1
  202. package/dist/function/compareBy.d.ts +24 -0
  203. package/dist/function/compareBy.d.ts.map +1 -0
  204. package/dist/function/compareBy.js +15 -14
  205. package/dist/function/compareBy.js.map +1 -1
  206. package/dist/function/compose.cjs +2 -2
  207. package/dist/function/compose.cjs.map +1 -1
  208. package/dist/function/compose.d.ts +22 -0
  209. package/dist/function/compose.d.ts.map +1 -0
  210. package/dist/function/compose.js +10 -13
  211. package/dist/function/compose.js.map +1 -1
  212. package/dist/function/curry.cjs +2 -2
  213. package/dist/function/curry.cjs.map +1 -1
  214. package/dist/function/curry.d.ts +21 -0
  215. package/dist/function/curry.d.ts.map +1 -0
  216. package/dist/function/curry.js +8 -7
  217. package/dist/function/curry.js.map +1 -1
  218. package/dist/function/debounce.cjs +2 -2
  219. package/dist/function/debounce.cjs.map +1 -1
  220. package/dist/function/debounce.d.ts +12 -0
  221. package/dist/function/debounce.d.ts.map +1 -0
  222. package/dist/function/debounce.js +34 -26
  223. package/dist/function/debounce.js.map +1 -1
  224. package/dist/function/fp.cjs +2 -2
  225. package/dist/function/fp.cjs.map +1 -1
  226. package/dist/function/fp.d.ts +24 -0
  227. package/dist/function/fp.d.ts.map +1 -0
  228. package/dist/function/fp.js +6 -10
  229. package/dist/function/fp.js.map +1 -1
  230. package/dist/function/index.d.ts +13 -0
  231. package/dist/function/index.d.ts.map +1 -0
  232. package/dist/function/memo.cjs +2 -2
  233. package/dist/function/memo.cjs.map +1 -1
  234. package/dist/function/memo.d.ts +30 -0
  235. package/dist/function/memo.d.ts.map +1 -0
  236. package/dist/function/memo.js +16 -24
  237. package/dist/function/memo.js.map +1 -1
  238. package/dist/function/once.cjs +2 -2
  239. package/dist/function/once.cjs.map +1 -1
  240. package/dist/function/once.d.ts +24 -0
  241. package/dist/function/once.d.ts.map +1 -0
  242. package/dist/function/once.js +10 -10
  243. package/dist/function/once.js.map +1 -1
  244. package/dist/function/pipe.cjs +2 -2
  245. package/dist/function/pipe.cjs.map +1 -1
  246. package/dist/function/pipe.d.ts +23 -0
  247. package/dist/function/pipe.d.ts.map +1 -0
  248. package/dist/function/pipe.js +10 -10
  249. package/dist/function/pipe.js.map +1 -1
  250. package/dist/function/throttle.cjs +2 -2
  251. package/dist/function/throttle.cjs.map +1 -1
  252. package/dist/function/throttle.d.ts +21 -0
  253. package/dist/function/throttle.d.ts.map +1 -0
  254. package/dist/function/throttle.js +45 -37
  255. package/dist/function/throttle.js.map +1 -1
  256. package/dist/index.cjs +1 -2
  257. package/dist/index.d.ts +77 -2813
  258. package/dist/index.d.ts.map +1 -0
  259. package/dist/index.js +75 -253
  260. package/dist/math/abs.cjs +2 -2
  261. package/dist/math/abs.cjs.map +1 -1
  262. package/dist/math/abs.d.ts +17 -0
  263. package/dist/math/abs.d.ts.map +1 -0
  264. package/dist/math/abs.js +7 -6
  265. package/dist/math/abs.js.map +1 -1
  266. package/dist/math/allocate.cjs +2 -2
  267. package/dist/math/allocate.cjs.map +1 -1
  268. package/dist/math/allocate.d.ts +24 -0
  269. package/dist/math/allocate.d.ts.map +1 -0
  270. package/dist/math/allocate.js +20 -28
  271. package/dist/math/allocate.js.map +1 -1
  272. package/dist/math/average.cjs +2 -2
  273. package/dist/math/average.cjs.map +1 -1
  274. package/dist/math/average.d.ts +16 -0
  275. package/dist/math/average.d.ts.map +1 -0
  276. package/dist/math/average.js +13 -24
  277. package/dist/math/average.js.map +1 -1
  278. package/dist/math/clamp.cjs +2 -2
  279. package/dist/math/clamp.cjs.map +1 -1
  280. package/dist/math/clamp.d.ts +18 -0
  281. package/dist/math/clamp.d.ts.map +1 -0
  282. package/dist/math/clamp.js +7 -6
  283. package/dist/math/clamp.js.map +1 -1
  284. package/dist/math/distribute.cjs +2 -2
  285. package/dist/math/distribute.cjs.map +1 -1
  286. package/dist/math/distribute.d.ts +24 -0
  287. package/dist/math/distribute.d.ts.map +1 -0
  288. package/dist/math/distribute.js +14 -17
  289. package/dist/math/distribute.js.map +1 -1
  290. package/dist/math/index.d.ts +14 -0
  291. package/dist/math/index.d.ts.map +1 -0
  292. package/dist/math/linspace.cjs +2 -0
  293. package/dist/math/linspace.cjs.map +1 -0
  294. package/dist/math/linspace.d.ts +19 -0
  295. package/dist/math/linspace.d.ts.map +1 -0
  296. package/dist/math/linspace.js +11 -0
  297. package/dist/math/linspace.js.map +1 -0
  298. package/dist/math/max.cjs +2 -2
  299. package/dist/math/max.cjs.map +1 -1
  300. package/dist/math/max.d.ts +23 -0
  301. package/dist/math/max.d.ts.map +1 -0
  302. package/dist/math/max.js +10 -11
  303. package/dist/math/max.js.map +1 -1
  304. package/dist/math/median.cjs +2 -2
  305. package/dist/math/median.cjs.map +1 -1
  306. package/dist/math/median.d.ts +17 -0
  307. package/dist/math/median.d.ts.map +1 -0
  308. package/dist/math/median.js +11 -10
  309. package/dist/math/median.js.map +1 -1
  310. package/dist/math/min.cjs +2 -2
  311. package/dist/math/min.cjs.map +1 -1
  312. package/dist/math/min.d.ts +23 -0
  313. package/dist/math/min.d.ts.map +1 -0
  314. package/dist/math/min.js +10 -11
  315. package/dist/math/min.js.map +1 -1
  316. package/dist/math/percent.cjs +2 -0
  317. package/dist/math/percent.cjs.map +1 -0
  318. package/dist/math/percent.d.ts +19 -0
  319. package/dist/math/percent.d.ts.map +1 -0
  320. package/dist/math/percent.js +8 -0
  321. package/dist/math/percent.js.map +1 -0
  322. package/dist/math/range.cjs +2 -2
  323. package/dist/math/range.cjs.map +1 -1
  324. package/dist/math/range.d.ts +23 -0
  325. package/dist/math/range.d.ts.map +1 -0
  326. package/dist/math/range.js +28 -17
  327. package/dist/math/range.js.map +1 -1
  328. package/dist/math/round.cjs +2 -2
  329. package/dist/math/round.cjs.map +1 -1
  330. package/dist/math/round.d.ts +21 -0
  331. package/dist/math/round.d.ts.map +1 -0
  332. package/dist/math/round.js +9 -8
  333. package/dist/math/round.js.map +1 -1
  334. package/dist/math/sum.cjs +2 -2
  335. package/dist/math/sum.cjs.map +1 -1
  336. package/dist/math/sum.d.ts +17 -0
  337. package/dist/math/sum.d.ts.map +1 -0
  338. package/dist/math/sum.js +11 -14
  339. package/dist/math/sum.js.map +1 -1
  340. package/dist/money/currency.cjs +2 -2
  341. package/dist/money/currency.cjs.map +1 -1
  342. package/dist/money/currency.d.ts +30 -0
  343. package/dist/money/currency.d.ts.map +1 -0
  344. package/dist/money/currency.js +19 -47
  345. package/dist/money/currency.js.map +1 -1
  346. package/dist/money/exchange.cjs +2 -2
  347. package/dist/money/exchange.cjs.map +1 -1
  348. package/dist/money/exchange.d.ts +29 -0
  349. package/dist/money/exchange.d.ts.map +1 -0
  350. package/dist/money/exchange.js +12 -12
  351. package/dist/money/exchange.js.map +1 -1
  352. package/dist/money/index.d.ts +4 -0
  353. package/dist/money/index.d.ts.map +1 -0
  354. package/dist/money/types.d.ts +9 -0
  355. package/dist/money/types.d.ts.map +1 -0
  356. package/dist/object/diff.cjs +2 -2
  357. package/dist/object/diff.cjs.map +1 -1
  358. package/dist/object/diff.d.ts +26 -0
  359. package/dist/object/diff.d.ts.map +1 -0
  360. package/dist/object/diff.js +19 -17
  361. package/dist/object/diff.js.map +1 -1
  362. package/dist/object/index.d.ts +9 -0
  363. package/dist/object/index.d.ts.map +1 -0
  364. package/dist/object/merge.cjs +2 -2
  365. package/dist/object/merge.cjs.map +1 -1
  366. package/dist/object/merge.d.ts +44 -0
  367. package/dist/object/merge.d.ts.map +1 -0
  368. package/dist/object/merge.js +27 -21
  369. package/dist/object/merge.js.map +1 -1
  370. package/dist/object/parseJSON.cjs +2 -2
  371. package/dist/object/parseJSON.cjs.map +1 -1
  372. package/dist/object/parseJSON.d.ts +32 -0
  373. package/dist/object/parseJSON.d.ts.map +1 -0
  374. package/dist/object/parseJSON.js +17 -18
  375. package/dist/object/parseJSON.js.map +1 -1
  376. package/dist/object/path.cjs +2 -2
  377. package/dist/object/path.cjs.map +1 -1
  378. package/dist/object/path.d.ts +32 -0
  379. package/dist/object/path.d.ts.map +1 -0
  380. package/dist/object/path.js +25 -23
  381. package/dist/object/path.js.map +1 -1
  382. package/dist/object/proxy.cjs +2 -0
  383. package/dist/object/proxy.cjs.map +1 -0
  384. package/dist/object/proxy.d.ts +30 -0
  385. package/dist/object/proxy.d.ts.map +1 -0
  386. package/dist/object/proxy.js +21 -0
  387. package/dist/object/proxy.js.map +1 -0
  388. package/dist/object/prune.cjs +2 -0
  389. package/dist/object/prune.cjs.map +1 -0
  390. package/dist/object/prune.d.ts +21 -0
  391. package/dist/object/prune.d.ts.map +1 -0
  392. package/dist/object/prune.js +31 -0
  393. package/dist/object/prune.js.map +1 -0
  394. package/dist/object/seek.cjs +2 -2
  395. package/dist/object/seek.cjs.map +1 -1
  396. package/dist/object/seek.d.ts +2 -0
  397. package/dist/object/seek.d.ts.map +1 -0
  398. package/dist/object/seek.js +25 -12
  399. package/dist/object/seek.js.map +1 -1
  400. package/dist/object/stash.cjs +2 -0
  401. package/dist/object/stash.cjs.map +1 -0
  402. package/dist/object/stash.d.ts +45 -0
  403. package/dist/object/stash.d.ts.map +1 -0
  404. package/dist/object/stash.js +99 -0
  405. package/dist/object/stash.js.map +1 -0
  406. package/dist/random/draw.cjs +2 -2
  407. package/dist/random/draw.cjs.map +1 -1
  408. package/dist/random/draw.d.ts +16 -0
  409. package/dist/random/draw.d.ts.map +1 -0
  410. package/dist/random/draw.js +13 -10
  411. package/dist/random/draw.js.map +1 -1
  412. package/dist/random/index.d.ts +5 -0
  413. package/dist/random/index.d.ts.map +1 -0
  414. package/dist/random/random.cjs +2 -2
  415. package/dist/random/random.cjs.map +1 -1
  416. package/dist/random/random.d.ts +14 -0
  417. package/dist/random/random.d.ts.map +1 -0
  418. package/dist/random/random.js +16 -9
  419. package/dist/random/random.js.map +1 -1
  420. package/dist/random/shuffle.cjs +2 -2
  421. package/dist/random/shuffle.cjs.map +1 -1
  422. package/dist/random/shuffle.d.ts +17 -0
  423. package/dist/random/shuffle.d.ts.map +1 -0
  424. package/dist/random/shuffle.js +18 -14
  425. package/dist/random/shuffle.js.map +1 -1
  426. package/dist/random/uuid.cjs +2 -2
  427. package/dist/random/uuid.cjs.map +1 -1
  428. package/dist/random/uuid.d.ts +12 -0
  429. package/dist/random/uuid.d.ts.map +1 -0
  430. package/dist/random/uuid.js +7 -9
  431. package/dist/random/uuid.js.map +1 -1
  432. package/dist/string/_caseUtils.cjs +2 -2
  433. package/dist/string/_caseUtils.cjs.map +1 -1
  434. package/dist/string/_caseUtils.d.ts +13 -0
  435. package/dist/string/_caseUtils.d.ts.map +1 -0
  436. package/dist/string/_caseUtils.js +8 -8
  437. package/dist/string/_caseUtils.js.map +1 -1
  438. package/dist/string/camelCase.cjs +2 -2
  439. package/dist/string/camelCase.cjs.map +1 -1
  440. package/dist/string/camelCase.d.ts +14 -0
  441. package/dist/string/camelCase.d.ts.map +1 -0
  442. package/dist/string/camelCase.js +8 -7
  443. package/dist/string/camelCase.js.map +1 -1
  444. package/dist/string/index.d.ts +7 -0
  445. package/dist/string/index.d.ts.map +1 -0
  446. package/dist/string/kebabCase.cjs +2 -2
  447. package/dist/string/kebabCase.cjs.map +1 -1
  448. package/dist/string/kebabCase.d.ts +15 -0
  449. package/dist/string/kebabCase.d.ts.map +1 -0
  450. package/dist/string/kebabCase.js +8 -7
  451. package/dist/string/kebabCase.js.map +1 -1
  452. package/dist/string/pascalCase.cjs +2 -2
  453. package/dist/string/pascalCase.cjs.map +1 -1
  454. package/dist/string/pascalCase.d.ts +15 -0
  455. package/dist/string/pascalCase.d.ts.map +1 -0
  456. package/dist/string/pascalCase.js +8 -7
  457. package/dist/string/pascalCase.js.map +1 -1
  458. package/dist/string/similarity.cjs +2 -2
  459. package/dist/string/similarity.cjs.map +1 -1
  460. package/dist/string/similarity.d.ts +20 -0
  461. package/dist/string/similarity.d.ts.map +1 -0
  462. package/dist/string/similarity.js +20 -36
  463. package/dist/string/similarity.js.map +1 -1
  464. package/dist/string/snakeCase.cjs +2 -2
  465. package/dist/string/snakeCase.cjs.map +1 -1
  466. package/dist/string/snakeCase.d.ts +15 -0
  467. package/dist/string/snakeCase.d.ts.map +1 -0
  468. package/dist/string/snakeCase.js +8 -7
  469. package/dist/string/snakeCase.js.map +1 -1
  470. package/dist/string/truncate.cjs +2 -2
  471. package/dist/string/truncate.cjs.map +1 -1
  472. package/dist/string/truncate.d.ts +28 -0
  473. package/dist/string/truncate.d.ts.map +1 -0
  474. package/dist/string/truncate.js +20 -17
  475. package/dist/string/truncate.js.map +1 -1
  476. package/dist/toolkit.cjs +2 -0
  477. package/dist/toolkit.cjs.map +1 -0
  478. package/dist/toolkit.js +1523 -0
  479. package/dist/toolkit.js.map +1 -0
  480. package/dist/typed/index.d.ts +24 -0
  481. package/dist/typed/index.d.ts.map +1 -0
  482. package/dist/typed/is.cjs +2 -2
  483. package/dist/typed/is.cjs.map +1 -1
  484. package/dist/typed/is.d.ts +95 -0
  485. package/dist/typed/is.d.ts.map +1 -0
  486. package/dist/typed/is.js +54 -42
  487. package/dist/typed/is.js.map +1 -1
  488. package/dist/typed/isArray.cjs +2 -2
  489. package/dist/typed/isArray.cjs.map +1 -1
  490. package/dist/typed/isArray.d.ts +16 -0
  491. package/dist/typed/isArray.d.ts.map +1 -0
  492. package/dist/typed/isArray.js +8 -8
  493. package/dist/typed/isArray.js.map +1 -1
  494. package/dist/typed/isBoolean.cjs +2 -2
  495. package/dist/typed/isBoolean.cjs.map +1 -1
  496. package/dist/typed/isBoolean.d.ts +23 -0
  497. package/dist/typed/isBoolean.d.ts.map +1 -0
  498. package/dist/typed/isBoolean.js +7 -6
  499. package/dist/typed/isBoolean.js.map +1 -1
  500. package/dist/typed/isDate.cjs +2 -2
  501. package/dist/typed/isDate.cjs.map +1 -1
  502. package/dist/typed/isDate.d.ts +16 -0
  503. package/dist/typed/isDate.d.ts.map +1 -0
  504. package/dist/typed/isDate.js +7 -8
  505. package/dist/typed/isDate.js.map +1 -1
  506. package/dist/typed/isDefined.cjs +2 -2
  507. package/dist/typed/isDefined.cjs.map +1 -1
  508. package/dist/typed/isDefined.d.ts +19 -0
  509. package/dist/typed/isDefined.d.ts.map +1 -0
  510. package/dist/typed/isDefined.js +7 -6
  511. package/dist/typed/isDefined.js.map +1 -1
  512. package/dist/typed/isEmpty.cjs +2 -2
  513. package/dist/typed/isEmpty.cjs.map +1 -1
  514. package/dist/typed/isEmpty.d.ts +24 -0
  515. package/dist/typed/isEmpty.d.ts.map +1 -0
  516. package/dist/typed/isEmpty.js +8 -9
  517. package/dist/typed/isEmpty.js.map +1 -1
  518. package/dist/typed/isEqual.cjs +2 -2
  519. package/dist/typed/isEqual.cjs.map +1 -1
  520. package/dist/typed/isEqual.d.ts +24 -0
  521. package/dist/typed/isEqual.d.ts.map +1 -0
  522. package/dist/typed/isEqual.js +27 -28
  523. package/dist/typed/isEqual.js.map +1 -1
  524. package/dist/typed/isEven.cjs +2 -2
  525. package/dist/typed/isEven.cjs.map +1 -1
  526. package/dist/typed/isEven.d.ts +9 -0
  527. package/dist/typed/isEven.d.ts.map +1 -0
  528. package/dist/typed/isEven.js +7 -6
  529. package/dist/typed/isEven.js.map +1 -1
  530. package/dist/typed/isFunction.cjs +2 -2
  531. package/dist/typed/isFunction.cjs.map +1 -1
  532. package/dist/typed/isFunction.d.ts +16 -0
  533. package/dist/typed/isFunction.d.ts.map +1 -0
  534. package/dist/typed/isFunction.js +7 -8
  535. package/dist/typed/isFunction.js.map +1 -1
  536. package/dist/typed/isMatch.cjs +2 -2
  537. package/dist/typed/isMatch.cjs.map +1 -1
  538. package/dist/typed/isMatch.d.ts +23 -0
  539. package/dist/typed/isMatch.d.ts.map +1 -0
  540. package/dist/typed/isMatch.js +16 -18
  541. package/dist/typed/isMatch.js.map +1 -1
  542. package/dist/typed/isNegative.cjs +2 -2
  543. package/dist/typed/isNegative.cjs.map +1 -1
  544. package/dist/typed/isNegative.d.ts +26 -0
  545. package/dist/typed/isNegative.d.ts.map +1 -0
  546. package/dist/typed/isNegative.js +7 -6
  547. package/dist/typed/isNegative.js.map +1 -1
  548. package/dist/typed/isNil.cjs +2 -2
  549. package/dist/typed/isNil.cjs.map +1 -1
  550. package/dist/typed/isNil.d.ts +17 -0
  551. package/dist/typed/isNil.d.ts.map +1 -0
  552. package/dist/typed/isNil.js +7 -8
  553. package/dist/typed/isNil.js.map +1 -1
  554. package/dist/typed/isNumber.cjs +2 -2
  555. package/dist/typed/isNumber.cjs.map +1 -1
  556. package/dist/typed/isNumber.d.ts +16 -0
  557. package/dist/typed/isNumber.d.ts.map +1 -0
  558. package/dist/typed/isNumber.js +8 -8
  559. package/dist/typed/isNumber.js.map +1 -1
  560. package/dist/typed/isObject.cjs +2 -2
  561. package/dist/typed/isObject.cjs.map +1 -1
  562. package/dist/typed/isObject.d.ts +19 -0
  563. package/dist/typed/isObject.d.ts.map +1 -0
  564. package/dist/typed/isObject.js +8 -8
  565. package/dist/typed/isObject.js.map +1 -1
  566. package/dist/typed/isOdd.cjs +2 -2
  567. package/dist/typed/isOdd.cjs.map +1 -1
  568. package/dist/typed/isOdd.d.ts +9 -0
  569. package/dist/typed/isOdd.d.ts.map +1 -0
  570. package/dist/typed/isOdd.js +7 -6
  571. package/dist/typed/isOdd.js.map +1 -1
  572. package/dist/typed/isPositive.cjs +2 -2
  573. package/dist/typed/isPositive.cjs.map +1 -1
  574. package/dist/typed/isPositive.d.ts +26 -0
  575. package/dist/typed/isPositive.d.ts.map +1 -0
  576. package/dist/typed/isPositive.js +7 -6
  577. package/dist/typed/isPositive.js.map +1 -1
  578. package/dist/typed/isPrimitive.cjs +2 -2
  579. package/dist/typed/isPrimitive.cjs.map +1 -1
  580. package/dist/typed/isPrimitive.d.ts +18 -0
  581. package/dist/typed/isPrimitive.d.ts.map +1 -0
  582. package/dist/typed/isPrimitive.js +8 -9
  583. package/dist/typed/isPrimitive.js.map +1 -1
  584. package/dist/typed/isPromise.cjs +2 -2
  585. package/dist/typed/isPromise.cjs.map +1 -1
  586. package/dist/typed/isPromise.d.ts +17 -0
  587. package/dist/typed/isPromise.d.ts.map +1 -0
  588. package/dist/typed/isPromise.js +7 -9
  589. package/dist/typed/isPromise.js.map +1 -1
  590. package/dist/typed/isRegex.cjs +2 -2
  591. package/dist/typed/isRegex.cjs.map +1 -1
  592. package/dist/typed/isRegex.d.ts +21 -0
  593. package/dist/typed/isRegex.d.ts.map +1 -0
  594. package/dist/typed/isRegex.js +7 -6
  595. package/dist/typed/isRegex.js.map +1 -1
  596. package/dist/typed/isString.cjs +2 -2
  597. package/dist/typed/isString.cjs.map +1 -1
  598. package/dist/typed/isString.d.ts +16 -0
  599. package/dist/typed/isString.d.ts.map +1 -0
  600. package/dist/typed/isString.js +8 -8
  601. package/dist/typed/isString.js.map +1 -1
  602. package/dist/typed/isWithin.cjs +2 -2
  603. package/dist/typed/isWithin.cjs.map +1 -1
  604. package/dist/typed/isWithin.d.ts +20 -0
  605. package/dist/typed/isWithin.d.ts.map +1 -0
  606. package/dist/typed/isWithin.js +9 -9
  607. package/dist/typed/isWithin.js.map +1 -1
  608. package/dist/typed/isZero.cjs +2 -2
  609. package/dist/typed/isZero.cjs.map +1 -1
  610. package/dist/typed/isZero.d.ts +25 -0
  611. package/dist/typed/isZero.d.ts.map +1 -0
  612. package/dist/typed/isZero.js +7 -6
  613. package/dist/typed/isZero.js.map +1 -1
  614. package/dist/typed/typeOf.cjs +2 -2
  615. package/dist/typed/typeOf.cjs.map +1 -1
  616. package/dist/typed/typeOf.d.ts +30 -0
  617. package/dist/typed/typeOf.d.ts.map +1 -0
  618. package/dist/typed/typeOf.js +11 -13
  619. package/dist/typed/typeOf.js.map +1 -1
  620. package/dist/types.d.ts +9 -0
  621. package/dist/types.d.ts.map +1 -0
  622. package/package.json +77 -12
  623. package/dist/array/aggregate.cjs +0 -2
  624. package/dist/array/aggregate.cjs.map +0 -1
  625. package/dist/array/aggregate.js +0 -16
  626. package/dist/array/aggregate.js.map +0 -1
  627. package/dist/array/alternate.cjs +0 -2
  628. package/dist/array/alternate.cjs.map +0 -1
  629. package/dist/array/alternate.js +0 -9
  630. package/dist/array/alternate.js.map +0 -1
  631. package/dist/array/arrange.cjs +0 -2
  632. package/dist/array/arrange.cjs.map +0 -1
  633. package/dist/array/arrange.js +0 -6
  634. package/dist/array/arrange.js.map +0 -1
  635. package/dist/array/compact.cjs +0 -2
  636. package/dist/array/compact.cjs.map +0 -1
  637. package/dist/array/compact.js +0 -9
  638. package/dist/array/compact.js.map +0 -1
  639. package/dist/array/every.cjs +0 -2
  640. package/dist/array/every.cjs.map +0 -1
  641. package/dist/array/every.js +0 -14
  642. package/dist/array/every.js.map +0 -1
  643. package/dist/array/filter.cjs +0 -2
  644. package/dist/array/filter.cjs.map +0 -1
  645. package/dist/array/filter.js +0 -14
  646. package/dist/array/filter.js.map +0 -1
  647. package/dist/array/find.cjs +0 -2
  648. package/dist/array/find.cjs.map +0 -1
  649. package/dist/array/find.js +0 -14
  650. package/dist/array/find.js.map +0 -1
  651. package/dist/array/findIndex.cjs +0 -2
  652. package/dist/array/findIndex.cjs.map +0 -1
  653. package/dist/array/findIndex.js +0 -14
  654. package/dist/array/findIndex.js.map +0 -1
  655. package/dist/array/findLast.cjs +0 -2
  656. package/dist/array/findLast.cjs.map +0 -1
  657. package/dist/array/findLast.js +0 -14
  658. package/dist/array/findLast.js.map +0 -1
  659. package/dist/array/flatten.cjs +0 -2
  660. package/dist/array/flatten.cjs.map +0 -1
  661. package/dist/array/flatten.js +0 -7
  662. package/dist/array/flatten.js.map +0 -1
  663. package/dist/array/map.cjs +0 -2
  664. package/dist/array/map.cjs.map +0 -1
  665. package/dist/array/map.js +0 -18
  666. package/dist/array/map.js.map +0 -1
  667. package/dist/array/reduce.cjs +0 -2
  668. package/dist/array/reduce.cjs.map +0 -1
  669. package/dist/array/reduce.js +0 -16
  670. package/dist/array/reduce.js.map +0 -1
  671. package/dist/array/shift.cjs +0 -2
  672. package/dist/array/shift.cjs.map +0 -1
  673. package/dist/array/shift.js +0 -13
  674. package/dist/array/shift.js.map +0 -1
  675. package/dist/array/some.cjs +0 -2
  676. package/dist/array/some.cjs.map +0 -1
  677. package/dist/array/some.js +0 -14
  678. package/dist/array/some.js.map +0 -1
  679. package/dist/array/substitute.cjs +0 -2
  680. package/dist/array/substitute.cjs.map +0 -1
  681. package/dist/array/substitute.js +0 -13
  682. package/dist/array/substitute.js.map +0 -1
  683. package/dist/async/delay.cjs +0 -2
  684. package/dist/async/delay.cjs.map +0 -1
  685. package/dist/async/delay.js +0 -8
  686. package/dist/async/delay.js.map +0 -1
  687. package/dist/function/proxy.cjs +0 -2
  688. package/dist/function/proxy.cjs.map +0 -1
  689. package/dist/function/proxy.js +0 -22
  690. package/dist/function/proxy.js.map +0 -1
  691. package/dist/function/prune.cjs +0 -2
  692. package/dist/function/prune.cjs.map +0 -1
  693. package/dist/function/prune.js +0 -30
  694. package/dist/function/prune.js.map +0 -1
  695. package/dist/function/worker.cjs +0 -14
  696. package/dist/function/worker.cjs.map +0 -1
  697. package/dist/function/worker.js +0 -29
  698. package/dist/function/worker.js.map +0 -1
  699. package/dist/index.cjs.map +0 -1
  700. package/dist/index.js.map +0 -1
  701. package/dist/logit/dist/logit.cjs +0 -2
  702. package/dist/logit/dist/logit.cjs.map +0 -1
  703. package/dist/logit/dist/logit.js +0 -263
  704. package/dist/logit/dist/logit.js.map +0 -1
  705. package/dist/math/add.cjs +0 -2
  706. package/dist/math/add.cjs.map +0 -1
  707. package/dist/math/add.js +0 -9
  708. package/dist/math/add.js.map +0 -1
  709. package/dist/math/boil.cjs +0 -2
  710. package/dist/math/boil.cjs.map +0 -1
  711. package/dist/math/boil.js +0 -17
  712. package/dist/math/boil.js.map +0 -1
  713. package/dist/math/divide.cjs +0 -2
  714. package/dist/math/divide.cjs.map +0 -1
  715. package/dist/math/divide.js +0 -11
  716. package/dist/math/divide.js.map +0 -1
  717. package/dist/math/multiply.cjs +0 -2
  718. package/dist/math/multiply.cjs.map +0 -1
  719. package/dist/math/multiply.js +0 -9
  720. package/dist/math/multiply.js.map +0 -1
  721. package/dist/math/rate.cjs +0 -2
  722. package/dist/math/rate.cjs.map +0 -1
  723. package/dist/math/rate.js +0 -9
  724. package/dist/math/rate.js.map +0 -1
  725. package/dist/math/subtract.cjs +0 -2
  726. package/dist/math/subtract.cjs.map +0 -1
  727. package/dist/math/subtract.js +0 -9
  728. package/dist/math/subtract.js.map +0 -1
  729. package/dist/object/cache.cjs +0 -2
  730. package/dist/object/cache.cjs.map +0 -1
  731. package/dist/object/cache.js +0 -63
  732. package/dist/object/cache.js.map +0 -1
  733. package/dist/object/clone.cjs +0 -2
  734. package/dist/object/clone.cjs.map +0 -1
  735. package/dist/object/clone.js +0 -17
  736. package/dist/object/clone.js.map +0 -1
  737. package/dist/object/entries.cjs +0 -2
  738. package/dist/object/entries.cjs.map +0 -1
  739. package/dist/object/entries.js +0 -9
  740. package/dist/object/entries.js.map +0 -1
  741. package/dist/object/keys.cjs +0 -2
  742. package/dist/object/keys.cjs.map +0 -1
  743. package/dist/object/keys.js +0 -9
  744. package/dist/object/keys.js.map +0 -1
  745. package/dist/object/values.cjs +0 -2
  746. package/dist/object/values.cjs.map +0 -1
  747. package/dist/object/values.js +0 -9
  748. package/dist/object/values.js.map +0 -1
  749. package/dist/typed/ge.cjs +0 -2
  750. package/dist/typed/ge.cjs.map +0 -1
  751. package/dist/typed/ge.js +0 -7
  752. package/dist/typed/ge.js.map +0 -1
  753. package/dist/typed/gt.cjs +0 -2
  754. package/dist/typed/gt.cjs.map +0 -1
  755. package/dist/typed/gt.js +0 -7
  756. package/dist/typed/gt.js.map +0 -1
  757. package/dist/typed/le.cjs +0 -2
  758. package/dist/typed/le.cjs.map +0 -1
  759. package/dist/typed/le.js +0 -7
  760. package/dist/typed/le.js.map +0 -1
  761. package/dist/typed/lt.cjs +0 -2
  762. package/dist/typed/lt.cjs.map +0 -1
  763. package/dist/typed/lt.js +0 -7
  764. package/dist/typed/lt.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"interval.cjs","sources":["../../src/date/interval.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { isDate } from '../typed/isDate';\n\n// #region IntervalTypes\ntype IntervalType = 'D' | 'W' | 'M' | 'MS' | 'ME' | 'Y' | 'YS' | 'YE';\ntype IntervalOptions = {\n interval?: IntervalType;\n steps?: number;\n latest?: boolean;\n};\n// #endregion IntervalTypes\n\n/**\n * Generates an array of dates between a start and end date, with a specified interval and step size.\n *\n * @example\n * ```ts\n * const options = { interval: 'D', steps: 1, latest: false };\n *\n * interval('2022-01-01', '2022-01-31', options); // Returns an array of dates for every day in January 2022\n * ```\n *\n * @param start - The start date (Date object or ISO string).\n * @param end - The end date (Date object or ISO string).\n * @param options - Options for an interval and steps.\n *\n * @returns An array of generated dates.\n */\nexport function interval(\n start: Date | string,\n end: Date | string,\n { interval = 'D', steps = 1, latest = false }: IntervalOptions = {},\n): Date[] {\n const startDate = new Date(start);\n const endDate = new Date(end);\n\n assert([isDate(startDate), isDate(endDate)], 'Invalid date format. Use a valid Date object or ISO string.', {\n args: { end, start },\n type: TypeError,\n });\n\n const dateArray: Date[] = [];\n let currentDate = new Date(incrementDate(startDate, interval, 0));\n\n while (currentDate <= endDate) {\n dateArray.push(currentDate);\n currentDate = new Date(incrementDate(currentDate, interval, steps));\n }\n\n if (latest && dateArray.length > 0 && dateArray[dateArray.length - 1] < endDate) {\n dateArray.push(endDate);\n }\n\n return dateArray;\n}\n\nfunction incrementDate(date: Date, interval: IntervalType, steps: number): Date {\n const year = date.getFullYear();\n const month = date.getMonth();\n const day = date.getDate();\n\n switch (interval) {\n case 'D':\n return new Date(Date.UTC(year, month, day + steps));\n case 'W':\n return new Date(Date.UTC(year, month, day + 7 * steps));\n case 'M':\n return new Date(Date.UTC(year, month + steps, day));\n case 'MS':\n return new Date(Date.UTC(year, month + steps, 1));\n case 'ME':\n return new Date(Date.UTC(year, month + steps + 1, 0));\n case 'Y':\n return new Date(Date.UTC(year + steps, month, day));\n case 'YS':\n return new Date(Date.UTC(year + steps, 0, 1));\n case 'YE':\n return new Date(Date.UTC(year + steps, 11, 31));\n }\n}\n"],"names":["interval","start","end","steps","latest","startDate","endDate","assert","isDate","dateArray","currentDate","incrementDate","date","year","month","day"],"mappings":"2JA4BO,SAASA,EACdC,EACAC,EACA,CAAE,SAAAF,EAAW,IAAK,MAAAG,EAAQ,EAAG,OAAAC,EAAS,EAAA,EAA2B,CAAA,EACzD,CACR,MAAMC,EAAY,IAAI,KAAKJ,CAAK,EAC1BK,EAAU,IAAI,KAAKJ,CAAG,EAE5BK,EAAAA,OAAO,CAACC,EAAAA,OAAOH,CAAS,EAAGG,EAAAA,OAAOF,CAAO,CAAC,EAAG,8DAA+D,CAC1G,KAAM,CAAE,IAAAJ,EAAK,MAAAD,CAAA,EACb,KAAM,SAAA,CACP,EAED,MAAMQ,EAAoB,CAAA,EAC1B,IAAIC,EAAc,IAAI,KAAKC,EAAcN,EAAWL,EAAU,CAAC,CAAC,EAEhE,KAAOU,GAAeJ,GACpBG,EAAU,KAAKC,CAAW,EAC1BA,EAAc,IAAI,KAAKC,EAAcD,EAAaV,EAAUG,CAAK,CAAC,EAGpE,OAAIC,GAAUK,EAAU,OAAS,GAAKA,EAAUA,EAAU,OAAS,CAAC,EAAIH,GACtEG,EAAU,KAAKH,CAAO,EAGjBG,CACT,CAEA,SAASE,EAAcC,EAAYZ,EAAwBG,EAAqB,CAC9E,MAAMU,EAAOD,EAAK,YAAA,EACZE,EAAQF,EAAK,SAAA,EACbG,EAAMH,EAAK,QAAA,EAEjB,OAAQZ,EAAAA,CACN,IAAK,IACH,OAAO,IAAI,KAAK,KAAK,IAAIa,EAAMC,EAAOC,EAAMZ,CAAK,CAAC,EACpD,IAAK,IACH,OAAO,IAAI,KAAK,KAAK,IAAIU,EAAMC,EAAOC,EAAM,EAAIZ,CAAK,CAAC,EACxD,IAAK,IACH,OAAO,IAAI,KAAK,KAAK,IAAIU,EAAMC,EAAQX,EAAOY,CAAG,CAAC,EACpD,IAAK,KACH,OAAO,IAAI,KAAK,KAAK,IAAIF,EAAMC,EAAQX,EAAO,CAAC,CAAC,EAClD,IAAK,KACH,OAAO,IAAI,KAAK,KAAK,IAAIU,EAAMC,EAAQX,EAAQ,EAAG,CAAC,CAAC,EACtD,IAAK,IACH,OAAO,IAAI,KAAK,KAAK,IAAIU,EAAOV,EAAOW,EAAOC,CAAG,CAAC,EACpD,IAAK,KACH,OAAO,IAAI,KAAK,KAAK,IAAIF,EAAOV,EAAO,EAAG,CAAC,CAAC,EAC9C,IAAK,KACH,OAAO,IAAI,KAAK,KAAK,IAAIU,EAAOV,EAAO,GAAI,EAAE,CAAC,CAAA,CAEpD"}
1
+ {"version":3,"file":"interval.cjs","names":[],"sources":["../../src/date/interval.ts"],"sourcesContent":["import { assertAll } from '../function/assert';\nimport { isDate } from '../typed/isDate';\n\n// #region IntervalTypes\ntype IntervalType = 'day' | 'week' | 'month' | 'monthStart' | 'monthEnd' | 'year' | 'yearStart' | 'yearEnd';\ntype IntervalOptions = {\n interval?: IntervalType;\n latest?: boolean;\n steps?: number;\n};\n// #endregion IntervalTypes\n\n/**\n * Generates an array of dates between a start and end date, with a specified interval and step size.\n *\n * @example\n * ```ts\n * const options = { interval: 'day', steps: 1, latest: false };\n *\n * interval('2022-01-01', '2022-01-31', options); // Returns an array of dates for every day in January 2022\n * ```\n *\n * @param start - The start date (Date object or ISO string).\n * @param end - The end date (Date object or ISO string).\n * @param options - Options for an interval and steps.\n *\n * @returns An array of generated dates.\n */\nexport function interval(\n start: Date | string,\n end: Date | string,\n { interval = 'day', latest = false, steps = 1 }: IntervalOptions = {},\n): Date[] {\n const startDate = new Date(start);\n const endDate = new Date(end);\n\n assertAll([isDate(startDate), isDate(endDate)], 'Invalid date format. Use a valid Date object or ISO string.', {\n args: { end, start },\n type: TypeError,\n });\n\n const dateArray: Date[] = [];\n let currentDate = new Date(incrementDate(startDate, interval, 0));\n\n while (currentDate <= endDate) {\n dateArray.push(currentDate);\n currentDate = new Date(incrementDate(currentDate, interval, steps));\n }\n\n if (latest && dateArray.length > 0 && dateArray[dateArray.length - 1] < endDate) {\n dateArray.push(endDate);\n }\n\n return dateArray;\n}\n\nfunction incrementDate(date: Date, interval: IntervalType, steps: number): Date {\n const year = date.getFullYear();\n const month = date.getMonth();\n const day = date.getDate();\n\n switch (interval) {\n case 'day':\n return new Date(Date.UTC(year, month, day + steps));\n case 'month':\n return new Date(Date.UTC(year, month + steps, day));\n case 'monthEnd':\n return new Date(Date.UTC(year, month + steps + 1, 0));\n case 'monthStart':\n return new Date(Date.UTC(year, month + steps, 1));\n case 'week':\n return new Date(Date.UTC(year, month, day + 7 * steps));\n case 'year':\n return new Date(Date.UTC(year + steps, month, day));\n case 'yearEnd':\n return new Date(Date.UTC(year + steps, 11, 31));\n case 'yearStart':\n return new Date(Date.UTC(year + steps, 0, 1));\n }\n}\n"],"mappings":"2EA4BA,SAAgB,EACd,EACA,EACA,CAAE,WAAW,MAAO,SAAS,GAAO,QAAQ,GAAuB,EAAE,CAC7D,CACR,IAAM,EAAY,IAAI,KAAK,EAAM,CAC3B,EAAU,IAAI,KAAK,EAAI,CAE7B,EAAA,UAAU,CAAC,EAAA,OAAO,EAAU,CAAE,EAAA,OAAO,EAAQ,CAAC,CAAE,8DAA+D,CAC7G,KAAM,CAAE,MAAK,QAAO,CACpB,KAAM,UACP,CAAC,CAEF,IAAM,EAAoB,EAAE,CACxB,EAAc,IAAI,KAAK,EAAc,EAAW,EAAU,EAAE,CAAC,CAEjE,KAAO,GAAe,GACpB,EAAU,KAAK,EAAY,CAC3B,EAAc,IAAI,KAAK,EAAc,EAAa,EAAU,EAAM,CAAC,CAOrE,OAJI,GAAU,EAAU,OAAS,GAAK,EAAU,EAAU,OAAS,GAAK,GACtE,EAAU,KAAK,EAAQ,CAGlB,EAGT,SAAS,EAAc,EAAY,EAAwB,EAAqB,CAC9E,IAAM,EAAO,EAAK,aAAa,CACzB,EAAQ,EAAK,UAAU,CACvB,EAAM,EAAK,SAAS,CAE1B,OAAQ,EAAR,CACE,IAAK,MACH,OAAO,IAAI,KAAK,KAAK,IAAI,EAAM,EAAO,EAAM,EAAM,CAAC,CACrD,IAAK,QACH,OAAO,IAAI,KAAK,KAAK,IAAI,EAAM,EAAQ,EAAO,EAAI,CAAC,CACrD,IAAK,WACH,OAAO,IAAI,KAAK,KAAK,IAAI,EAAM,EAAQ,EAAQ,EAAG,EAAE,CAAC,CACvD,IAAK,aACH,OAAO,IAAI,KAAK,KAAK,IAAI,EAAM,EAAQ,EAAO,EAAE,CAAC,CACnD,IAAK,OACH,OAAO,IAAI,KAAK,KAAK,IAAI,EAAM,EAAO,EAAM,EAAI,EAAM,CAAC,CACzD,IAAK,OACH,OAAO,IAAI,KAAK,KAAK,IAAI,EAAO,EAAO,EAAO,EAAI,CAAC,CACrD,IAAK,UACH,OAAO,IAAI,KAAK,KAAK,IAAI,EAAO,EAAO,GAAI,GAAG,CAAC,CACjD,IAAK,YACH,OAAO,IAAI,KAAK,KAAK,IAAI,EAAO,EAAO,EAAG,EAAE,CAAC"}
@@ -0,0 +1,25 @@
1
+ type IntervalType = 'day' | 'week' | 'month' | 'monthStart' | 'monthEnd' | 'year' | 'yearStart' | 'yearEnd';
2
+ type IntervalOptions = {
3
+ interval?: IntervalType;
4
+ latest?: boolean;
5
+ steps?: number;
6
+ };
7
+ /**
8
+ * Generates an array of dates between a start and end date, with a specified interval and step size.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const options = { interval: 'day', steps: 1, latest: false };
13
+ *
14
+ * interval('2022-01-01', '2022-01-31', options); // Returns an array of dates for every day in January 2022
15
+ * ```
16
+ *
17
+ * @param start - The start date (Date object or ISO string).
18
+ * @param end - The end date (Date object or ISO string).
19
+ * @param options - Options for an interval and steps.
20
+ *
21
+ * @returns An array of generated dates.
22
+ */
23
+ export declare function interval(start: Date | string, end: Date | string, { interval, latest, steps }?: IntervalOptions): Date[];
24
+ export {};
25
+ //# sourceMappingURL=interval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interval.d.ts","sourceRoot":"","sources":["../../src/date/interval.ts"],"names":[],"mappings":"AAIA,KAAK,YAAY,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,YAAY,GAAG,UAAU,GAAG,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;AAC5G,KAAK,eAAe,GAAG;IACrB,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAGF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,IAAI,GAAG,MAAM,EACpB,GAAG,EAAE,IAAI,GAAG,MAAM,EAClB,EAAE,QAAgB,EAAE,MAAc,EAAE,KAAS,EAAE,GAAE,eAAoB,GACpE,IAAI,EAAE,CAsBR"}
@@ -1,39 +1,33 @@
1
- import { assert as l } from "../function/assert.js";
2
- import { isDate as w } from "../typed/isDate.js";
3
- function U(r, c, { interval: e = "D", steps: t = 1, latest: a = !1 } = {}) {
4
- const n = new Date(r), o = new Date(c);
5
- l([w(n), w(o)], "Invalid date format. Use a valid Date object or ISO string.", {
6
- args: { end: c, start: r },
7
- type: TypeError
8
- });
9
- const D = [];
10
- let u = new Date(i(n, e, 0));
11
- for (; u <= o; )
12
- D.push(u), u = new Date(i(u, e, t));
13
- return a && D.length > 0 && D[D.length - 1] < o && D.push(o), D;
1
+ import { assertAll as e } from "../function/assert.js";
2
+ import { isDate as t } from "../typed/isDate.js";
3
+ //#region src/date/interval.ts
4
+ function n(n, i, { interval: a = "day", latest: o = !1, steps: s = 1 } = {}) {
5
+ let c = new Date(n), l = new Date(i);
6
+ e([t(c), t(l)], "Invalid date format. Use a valid Date object or ISO string.", {
7
+ args: {
8
+ end: i,
9
+ start: n
10
+ },
11
+ type: TypeError
12
+ });
13
+ let u = [], d = new Date(r(c, a, 0));
14
+ for (; d <= l;) u.push(d), d = new Date(r(d, a, s));
15
+ return o && u.length > 0 && u[u.length - 1] < l && u.push(l), u;
14
16
  }
15
- function i(r, c, e) {
16
- const t = r.getFullYear(), a = r.getMonth(), n = r.getDate();
17
- switch (c) {
18
- case "D":
19
- return new Date(Date.UTC(t, a, n + e));
20
- case "W":
21
- return new Date(Date.UTC(t, a, n + 7 * e));
22
- case "M":
23
- return new Date(Date.UTC(t, a + e, n));
24
- case "MS":
25
- return new Date(Date.UTC(t, a + e, 1));
26
- case "ME":
27
- return new Date(Date.UTC(t, a + e + 1, 0));
28
- case "Y":
29
- return new Date(Date.UTC(t + e, a, n));
30
- case "YS":
31
- return new Date(Date.UTC(t + e, 0, 1));
32
- case "YE":
33
- return new Date(Date.UTC(t + e, 11, 31));
34
- }
17
+ function r(e, t, n) {
18
+ let r = e.getFullYear(), i = e.getMonth(), a = e.getDate();
19
+ switch (t) {
20
+ case "day": return new Date(Date.UTC(r, i, a + n));
21
+ case "month": return new Date(Date.UTC(r, i + n, a));
22
+ case "monthEnd": return new Date(Date.UTC(r, i + n + 1, 0));
23
+ case "monthStart": return new Date(Date.UTC(r, i + n, 1));
24
+ case "week": return new Date(Date.UTC(r, i, a + 7 * n));
25
+ case "year": return new Date(Date.UTC(r + n, i, a));
26
+ case "yearEnd": return new Date(Date.UTC(r + n, 11, 31));
27
+ case "yearStart": return new Date(Date.UTC(r + n, 0, 1));
28
+ }
35
29
  }
36
- export {
37
- U as interval
38
- };
39
- //# sourceMappingURL=interval.js.map
30
+ //#endregion
31
+ export { n as interval };
32
+
33
+ //# sourceMappingURL=interval.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interval.js","sources":["../../src/date/interval.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { isDate } from '../typed/isDate';\n\n// #region IntervalTypes\ntype IntervalType = 'D' | 'W' | 'M' | 'MS' | 'ME' | 'Y' | 'YS' | 'YE';\ntype IntervalOptions = {\n interval?: IntervalType;\n steps?: number;\n latest?: boolean;\n};\n// #endregion IntervalTypes\n\n/**\n * Generates an array of dates between a start and end date, with a specified interval and step size.\n *\n * @example\n * ```ts\n * const options = { interval: 'D', steps: 1, latest: false };\n *\n * interval('2022-01-01', '2022-01-31', options); // Returns an array of dates for every day in January 2022\n * ```\n *\n * @param start - The start date (Date object or ISO string).\n * @param end - The end date (Date object or ISO string).\n * @param options - Options for an interval and steps.\n *\n * @returns An array of generated dates.\n */\nexport function interval(\n start: Date | string,\n end: Date | string,\n { interval = 'D', steps = 1, latest = false }: IntervalOptions = {},\n): Date[] {\n const startDate = new Date(start);\n const endDate = new Date(end);\n\n assert([isDate(startDate), isDate(endDate)], 'Invalid date format. Use a valid Date object or ISO string.', {\n args: { end, start },\n type: TypeError,\n });\n\n const dateArray: Date[] = [];\n let currentDate = new Date(incrementDate(startDate, interval, 0));\n\n while (currentDate <= endDate) {\n dateArray.push(currentDate);\n currentDate = new Date(incrementDate(currentDate, interval, steps));\n }\n\n if (latest && dateArray.length > 0 && dateArray[dateArray.length - 1] < endDate) {\n dateArray.push(endDate);\n }\n\n return dateArray;\n}\n\nfunction incrementDate(date: Date, interval: IntervalType, steps: number): Date {\n const year = date.getFullYear();\n const month = date.getMonth();\n const day = date.getDate();\n\n switch (interval) {\n case 'D':\n return new Date(Date.UTC(year, month, day + steps));\n case 'W':\n return new Date(Date.UTC(year, month, day + 7 * steps));\n case 'M':\n return new Date(Date.UTC(year, month + steps, day));\n case 'MS':\n return new Date(Date.UTC(year, month + steps, 1));\n case 'ME':\n return new Date(Date.UTC(year, month + steps + 1, 0));\n case 'Y':\n return new Date(Date.UTC(year + steps, month, day));\n case 'YS':\n return new Date(Date.UTC(year + steps, 0, 1));\n case 'YE':\n return new Date(Date.UTC(year + steps, 11, 31));\n }\n}\n"],"names":["interval","start","end","steps","latest","startDate","endDate","assert","isDate","dateArray","currentDate","incrementDate","date","year","month","day"],"mappings":";;AA4BO,SAASA,EACdC,GACAC,GACA,EAAE,UAAAF,IAAW,KAAK,OAAAG,IAAQ,GAAG,QAAAC,IAAS,GAAA,IAA2B,CAAA,GACzD;AACR,QAAMC,IAAY,IAAI,KAAKJ,CAAK,GAC1BK,IAAU,IAAI,KAAKJ,CAAG;AAE5B,EAAAK,EAAO,CAACC,EAAOH,CAAS,GAAGG,EAAOF,CAAO,CAAC,GAAG,+DAA+D;AAAA,IAC1G,MAAM,EAAE,KAAAJ,GAAK,OAAAD,EAAA;AAAA,IACb,MAAM;AAAA,EAAA,CACP;AAED,QAAMQ,IAAoB,CAAA;AAC1B,MAAIC,IAAc,IAAI,KAAKC,EAAcN,GAAWL,GAAU,CAAC,CAAC;AAEhE,SAAOU,KAAeJ;AACpB,IAAAG,EAAU,KAAKC,CAAW,GAC1BA,IAAc,IAAI,KAAKC,EAAcD,GAAaV,GAAUG,CAAK,CAAC;AAGpE,SAAIC,KAAUK,EAAU,SAAS,KAAKA,EAAUA,EAAU,SAAS,CAAC,IAAIH,KACtEG,EAAU,KAAKH,CAAO,GAGjBG;AACT;AAEA,SAASE,EAAcC,GAAYZ,GAAwBG,GAAqB;AAC9E,QAAMU,IAAOD,EAAK,YAAA,GACZE,IAAQF,EAAK,SAAA,GACbG,IAAMH,EAAK,QAAA;AAEjB,UAAQZ,GAAAA;AAAAA,IACN,KAAK;AACH,aAAO,IAAI,KAAK,KAAK,IAAIa,GAAMC,GAAOC,IAAMZ,CAAK,CAAC;AAAA,IACpD,KAAK;AACH,aAAO,IAAI,KAAK,KAAK,IAAIU,GAAMC,GAAOC,IAAM,IAAIZ,CAAK,CAAC;AAAA,IACxD,KAAK;AACH,aAAO,IAAI,KAAK,KAAK,IAAIU,GAAMC,IAAQX,GAAOY,CAAG,CAAC;AAAA,IACpD,KAAK;AACH,aAAO,IAAI,KAAK,KAAK,IAAIF,GAAMC,IAAQX,GAAO,CAAC,CAAC;AAAA,IAClD,KAAK;AACH,aAAO,IAAI,KAAK,KAAK,IAAIU,GAAMC,IAAQX,IAAQ,GAAG,CAAC,CAAC;AAAA,IACtD,KAAK;AACH,aAAO,IAAI,KAAK,KAAK,IAAIU,IAAOV,GAAOW,GAAOC,CAAG,CAAC;AAAA,IACpD,KAAK;AACH,aAAO,IAAI,KAAK,KAAK,IAAIF,IAAOV,GAAO,GAAG,CAAC,CAAC;AAAA,IAC9C,KAAK;AACH,aAAO,IAAI,KAAK,KAAK,IAAIU,IAAOV,GAAO,IAAI,EAAE,CAAC;AAAA,EAAA;AAEpD;"}
1
+ {"version":3,"file":"interval.js","names":[],"sources":["../../src/date/interval.ts"],"sourcesContent":["import { assertAll } from '../function/assert';\nimport { isDate } from '../typed/isDate';\n\n// #region IntervalTypes\ntype IntervalType = 'day' | 'week' | 'month' | 'monthStart' | 'monthEnd' | 'year' | 'yearStart' | 'yearEnd';\ntype IntervalOptions = {\n interval?: IntervalType;\n latest?: boolean;\n steps?: number;\n};\n// #endregion IntervalTypes\n\n/**\n * Generates an array of dates between a start and end date, with a specified interval and step size.\n *\n * @example\n * ```ts\n * const options = { interval: 'day', steps: 1, latest: false };\n *\n * interval('2022-01-01', '2022-01-31', options); // Returns an array of dates for every day in January 2022\n * ```\n *\n * @param start - The start date (Date object or ISO string).\n * @param end - The end date (Date object or ISO string).\n * @param options - Options for an interval and steps.\n *\n * @returns An array of generated dates.\n */\nexport function interval(\n start: Date | string,\n end: Date | string,\n { interval = 'day', latest = false, steps = 1 }: IntervalOptions = {},\n): Date[] {\n const startDate = new Date(start);\n const endDate = new Date(end);\n\n assertAll([isDate(startDate), isDate(endDate)], 'Invalid date format. Use a valid Date object or ISO string.', {\n args: { end, start },\n type: TypeError,\n });\n\n const dateArray: Date[] = [];\n let currentDate = new Date(incrementDate(startDate, interval, 0));\n\n while (currentDate <= endDate) {\n dateArray.push(currentDate);\n currentDate = new Date(incrementDate(currentDate, interval, steps));\n }\n\n if (latest && dateArray.length > 0 && dateArray[dateArray.length - 1] < endDate) {\n dateArray.push(endDate);\n }\n\n return dateArray;\n}\n\nfunction incrementDate(date: Date, interval: IntervalType, steps: number): Date {\n const year = date.getFullYear();\n const month = date.getMonth();\n const day = date.getDate();\n\n switch (interval) {\n case 'day':\n return new Date(Date.UTC(year, month, day + steps));\n case 'month':\n return new Date(Date.UTC(year, month + steps, day));\n case 'monthEnd':\n return new Date(Date.UTC(year, month + steps + 1, 0));\n case 'monthStart':\n return new Date(Date.UTC(year, month + steps, 1));\n case 'week':\n return new Date(Date.UTC(year, month, day + 7 * steps));\n case 'year':\n return new Date(Date.UTC(year + steps, month, day));\n case 'yearEnd':\n return new Date(Date.UTC(year + steps, 11, 31));\n case 'yearStart':\n return new Date(Date.UTC(year + steps, 0, 1));\n }\n}\n"],"mappings":";;;AA4BA,SAAgB,EACd,GACA,GACA,EAAE,cAAW,OAAO,YAAS,IAAO,WAAQ,MAAuB,EAAE,EAC7D;CACR,IAAM,IAAY,IAAI,KAAK,EAAM,EAC3B,IAAU,IAAI,KAAK,EAAI;AAE7B,GAAU,CAAC,EAAO,EAAU,EAAE,EAAO,EAAQ,CAAC,EAAE,+DAA+D;EAC7G,MAAM;GAAE;GAAK;GAAO;EACpB,MAAM;EACP,CAAC;CAEF,IAAM,IAAoB,EAAE,EACxB,IAAc,IAAI,KAAK,EAAc,GAAW,GAAU,EAAE,CAAC;AAEjE,QAAO,KAAe,GAEpB,CADA,EAAU,KAAK,EAAY,EAC3B,IAAc,IAAI,KAAK,EAAc,GAAa,GAAU,EAAM,CAAC;AAOrE,QAJI,KAAU,EAAU,SAAS,KAAK,EAAU,EAAU,SAAS,KAAK,KACtE,EAAU,KAAK,EAAQ,EAGlB;;AAGT,SAAS,EAAc,GAAY,GAAwB,GAAqB;CAC9E,IAAM,IAAO,EAAK,aAAa,EACzB,IAAQ,EAAK,UAAU,EACvB,IAAM,EAAK,SAAS;AAE1B,SAAQ,GAAR;EACE,KAAK,MACH,QAAO,IAAI,KAAK,KAAK,IAAI,GAAM,GAAO,IAAM,EAAM,CAAC;EACrD,KAAK,QACH,QAAO,IAAI,KAAK,KAAK,IAAI,GAAM,IAAQ,GAAO,EAAI,CAAC;EACrD,KAAK,WACH,QAAO,IAAI,KAAK,KAAK,IAAI,GAAM,IAAQ,IAAQ,GAAG,EAAE,CAAC;EACvD,KAAK,aACH,QAAO,IAAI,KAAK,KAAK,IAAI,GAAM,IAAQ,GAAO,EAAE,CAAC;EACnD,KAAK,OACH,QAAO,IAAI,KAAK,KAAK,IAAI,GAAM,GAAO,IAAM,IAAI,EAAM,CAAC;EACzD,KAAK,OACH,QAAO,IAAI,KAAK,KAAK,IAAI,IAAO,GAAO,GAAO,EAAI,CAAC;EACrD,KAAK,UACH,QAAO,IAAI,KAAK,KAAK,IAAI,IAAO,GAAO,IAAI,GAAG,CAAC;EACjD,KAAK,YACH,QAAO,IAAI,KAAK,KAAK,IAAI,IAAO,GAAO,GAAG,EAAE,CAAC"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let c=["YEAR","MONTH","WEEK","DAY","HOUR","MINUTE","SECOND"];const f=1e3,N=60*f,m=60*N,n=24*m,D=7*n,_=30*n,S=365*n,R=[{ms:S,unit:"YEAR"},{ms:_,unit:"MONTH"},{ms:D,unit:"WEEK"},{ms:n,unit:"DAY"},{ms:m,unit:"HOUR"},{ms:N,unit:"MINUTE"},{ms:f,unit:"SECOND"}];function M(t,e=new Date,l=c){const o=typeof t=="string"?Date.parse(t):t.getTime(),a=typeof e=="string"?Date.parse(e):e.getTime();if(Number.isNaN(o)||Number.isNaN(a))return{unit:"INVALID_DATE",value:0};const i=R.filter(E=>l.includes(E.unit)),s=Math.abs(o-a),r=i[i.length-1]?.unit??"SECOND";if(s<=0)return{unit:r,value:0};const u=i.find(E=>s>=E.ms);return u?{unit:u.unit,value:Math.floor(s/u.ms)}:{unit:r,value:0}}M.defaultUnits=t=>{c=t};exports.timeDiff=M;
2
- //# sourceMappingURL=timeDiff.cjs.map
1
+ var e=[`year`,`month`,`week`,`day`,`hour`,`minute`,`second`],t=1e3,n=60*t,r=60*n,i=24*r,a=7*i,o=30*i,s=[{ms:365*i,unit:`year`},{ms:o,unit:`month`},{ms:a,unit:`week`},{ms:i,unit:`day`},{ms:r,unit:`hour`},{ms:n,unit:`minute`},{ms:t,unit:`second`}];function c(t,n=new Date,r=e){let i=typeof t==`string`?Date.parse(t):t.getTime(),a=typeof n==`string`?Date.parse(n):n.getTime();if(Number.isNaN(i)||Number.isNaN(a))return;let o=s.filter(e=>r.includes(e.unit)),c=Math.abs(i-a),l=o[o.length-1]?.unit??`second`;if(c<=0)return{unit:l,value:0};let u=o.find(e=>c>=e.ms);return u?{unit:u.unit,value:Math.floor(c/u.ms)}:{unit:l,value:0}}exports.timeDiff=c;
2
+ //# sourceMappingURL=timeDiff.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"timeDiff.cjs","sources":["../../src/date/timeDiff.ts"],"sourcesContent":["// #region TimeDiffTypes\nexport type TimeUnit = 'YEAR' | 'MONTH' | 'WEEK' | 'DAY' | 'HOUR' | 'MINUTE' | 'SECOND' | 'INVALID_DATE';\nexport type TimeDirection = 'FUTURE' | 'PAST';\nexport type TimeResult = { unit: TimeUnit; value: number };\n// #endregion TimeDiffTypes\n\nlet defaultUnits: TimeUnit[] = ['YEAR', 'MONTH', 'WEEK', 'DAY', 'HOUR', 'MINUTE', 'SECOND'];\n\nconst MS_PER_SECOND = 1000;\nconst MS_PER_MINUTE = 60 * MS_PER_SECOND;\nconst MS_PER_HOUR = 60 * MS_PER_MINUTE;\nconst MS_PER_DAY = 24 * MS_PER_HOUR;\nconst MS_PER_WEEK = 7 * MS_PER_DAY;\nconst MS_PER_MONTH = 30 * MS_PER_DAY;\nconst MS_PER_YEAR = 365 * MS_PER_DAY;\n\nconst TIME_UNITS = [\n { ms: MS_PER_YEAR, unit: 'YEAR' as const },\n { ms: MS_PER_MONTH, unit: 'MONTH' as const },\n { ms: MS_PER_WEEK, unit: 'WEEK' as const },\n { ms: MS_PER_DAY, unit: 'DAY' as const },\n { ms: MS_PER_HOUR, unit: 'HOUR' as const },\n { ms: MS_PER_MINUTE, unit: 'MINUTE' as const },\n { ms: MS_PER_SECOND, unit: 'SECOND' as const },\n];\n\n/**\n * Calculates the remaining time until a target date.\n *\n * @example\n * ```ts\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 5)); // { value: 5, unit: 'DAY' }\n * timeDiff(new Date(Date.now() - 1000 * 60 * 60 * 24 * 3), 'past'); // { value: 3, unit: 'DAY' }\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 31)); // { value: 1, unit: 'MONTH' }\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 365)); // { value: 1, unit: 'YEAR' }\n * ```\n *\n * @param a - The target date (Date object or ISO string).\n * @param b - The target date (Date object or ISO string).\n * @param allowedUnits - (optional) array of units to filter the result. If provided, only these units will be considered.\n *\n * @returns An object containing the remaining time and its unit ('DAY', 'HOUR', or 'MINUTE').\n */\nexport function timeDiff(\n a: Date | string,\n b: Date | string = new Date(),\n allowedUnits: TimeUnit[] = defaultUnits,\n): TimeResult {\n const aDate = typeof a === 'string' ? Date.parse(a) : a.getTime();\n const bDate = typeof b === 'string' ? Date.parse(b) : b.getTime();\n\n if (Number.isNaN(aDate) || Number.isNaN(bDate)) {\n return { unit: 'INVALID_DATE', value: 0 };\n }\n\n const units = TIME_UNITS.filter((u) => allowedUnits.includes(u.unit));\n const diff = Math.abs(aDate - bDate);\n const smallestUnit = units[units.length - 1]?.unit ?? 'SECOND';\n\n if (diff <= 0) {\n return { unit: smallestUnit, value: 0 };\n }\n\n // Find the largest unit that fits\n const bestUnit = units.find((u) => diff >= u.ms);\n\n if (bestUnit) {\n return { unit: bestUnit.unit, value: Math.floor(diff / bestUnit.ms) };\n }\n\n return { unit: smallestUnit, value: 0 };\n}\n\ntimeDiff.defaultUnits = (units: TimeUnit[]) => {\n defaultUnits = units;\n};\n"],"names":["defaultUnits","MS_PER_SECOND","MS_PER_MINUTE","MS_PER_HOUR","MS_PER_DAY","MS_PER_WEEK","MS_PER_MONTH","MS_PER_YEAR","TIME_UNITS","timeDiff","a","b","allowedUnits","aDate","bDate","units","u","diff","smallestUnit","bestUnit"],"mappings":"gFAMA,IAAIA,EAA2B,CAAC,OAAQ,QAAS,OAAQ,MAAO,OAAQ,SAAU,QAAQ,EAE1F,MAAMC,EAAgB,IAChBC,EAAgB,GAAKD,EACrBE,EAAc,GAAKD,EACnBE,EAAa,GAAKD,EAClBE,EAAc,EAAID,EAClBE,EAAe,GAAKF,EACpBG,EAAc,IAAMH,EAEpBI,EAAa,CACjB,CAAE,GAAID,EAAa,KAAM,MAAA,EACzB,CAAE,GAAID,EAAc,KAAM,OAAA,EAC1B,CAAE,GAAID,EAAa,KAAM,MAAA,EACzB,CAAE,GAAID,EAAY,KAAM,KAAA,EACxB,CAAE,GAAID,EAAa,KAAM,MAAA,EACzB,CAAE,GAAID,EAAe,KAAM,QAAA,EAC3B,CAAE,GAAID,EAAe,KAAM,QAAA,CAC7B,EAmBO,SAASQ,EACdC,EACAC,MAAuB,KACvBC,EAA2BZ,EACf,CACZ,MAAMa,EAAQ,OAAOH,GAAM,SAAW,KAAK,MAAMA,CAAC,EAAIA,EAAE,QAAA,EAClDI,EAAQ,OAAOH,GAAM,SAAW,KAAK,MAAMA,CAAC,EAAIA,EAAE,QAAA,EAExD,GAAI,OAAO,MAAME,CAAK,GAAK,OAAO,MAAMC,CAAK,EAC3C,MAAO,CAAE,KAAM,eAAgB,MAAO,CAAA,EAGxC,MAAMC,EAAQP,EAAW,OAAQQ,GAAMJ,EAAa,SAASI,EAAE,IAAI,CAAC,EAC9DC,EAAO,KAAK,IAAIJ,EAAQC,CAAK,EAC7BI,EAAeH,EAAMA,EAAM,OAAS,CAAC,GAAG,MAAQ,SAEtD,GAAIE,GAAQ,EACV,MAAO,CAAE,KAAMC,EAAc,MAAO,CAAA,EAItC,MAAMC,EAAWJ,EAAM,KAAMC,GAAMC,GAAQD,EAAE,EAAE,EAE/C,OAAIG,EACK,CAAE,KAAMA,EAAS,KAAM,MAAO,KAAK,MAAMF,EAAOE,EAAS,EAAE,CAAA,EAG7D,CAAE,KAAMD,EAAc,MAAO,CAAA,CACtC,CAEAT,EAAS,aAAgBM,GAAsB,CAC7Cf,EAAee,CACjB"}
1
+ {"version":3,"file":"timeDiff.cjs","names":[],"sources":["../../src/date/timeDiff.ts"],"sourcesContent":["// #region TimeDiffTypes\nexport type TimeUnit = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';\nexport type TimeResult = { unit: TimeUnit; value: number };\n// #endregion TimeDiffTypes\n\nconst ALL_UNITS: TimeUnit[] = ['year', 'month', 'week', 'day', 'hour', 'minute', 'second'];\n\nconst MS_PER_SECOND = 1000;\nconst MS_PER_MINUTE = 60 * MS_PER_SECOND;\nconst MS_PER_HOUR = 60 * MS_PER_MINUTE;\nconst MS_PER_DAY = 24 * MS_PER_HOUR;\nconst MS_PER_WEEK = 7 * MS_PER_DAY;\nconst MS_PER_MONTH = 30 * MS_PER_DAY;\nconst MS_PER_YEAR = 365 * MS_PER_DAY;\n\nconst TIME_UNITS = [\n { ms: MS_PER_YEAR, unit: 'year' as const },\n { ms: MS_PER_MONTH, unit: 'month' as const },\n { ms: MS_PER_WEEK, unit: 'week' as const },\n { ms: MS_PER_DAY, unit: 'day' as const },\n { ms: MS_PER_HOUR, unit: 'hour' as const },\n { ms: MS_PER_MINUTE, unit: 'minute' as const },\n { ms: MS_PER_SECOND, unit: 'second' as const },\n];\n\n/**\n * Calculates the remaining time until a target date.\n *\n * @example\n * ```ts\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 5)); // { value: 5, unit: 'day' }\n * timeDiff(new Date(Date.now() - 1000 * 60 * 60 * 24 * 3), 'past'); // { value: 3, unit: 'day' }\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 31)); // { value: 1, unit: 'month' }\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 365)); // { value: 1, unit: 'year' }\n * ```\n *\n * @param a - The target date (Date object or ISO string).\n * @param b - The target date (Date object or ISO string).\n * @param allowedUnits - (optional) array of units to filter the result. If provided, only these units will be considered.\n *\n * @returns An object containing the remaining time and its unit ('DAY', 'HOUR', or 'MINUTE').\n */\nexport function timeDiff(\n a: Date | string,\n b: Date | string = new Date(),\n allowedUnits: TimeUnit[] = ALL_UNITS,\n): TimeResult | undefined {\n const aDate = typeof a === 'string' ? Date.parse(a) : a.getTime();\n const bDate = typeof b === 'string' ? Date.parse(b) : b.getTime();\n\n if (Number.isNaN(aDate) || Number.isNaN(bDate)) {\n return undefined;\n }\n\n const units = TIME_UNITS.filter((u) => allowedUnits.includes(u.unit));\n const diff = Math.abs(aDate - bDate);\n const smallestUnit = units[units.length - 1]?.unit ?? 'second';\n\n if (diff <= 0) {\n return { unit: smallestUnit, value: 0 };\n }\n\n // Find the largest unit that fits\n const bestUnit = units.find((u) => diff >= u.ms);\n\n if (bestUnit) {\n return { unit: bestUnit.unit, value: Math.floor(diff / bestUnit.ms) };\n }\n\n return { unit: smallestUnit, value: 0 };\n}\n"],"mappings":"AAKA,IAAM,EAAwB,CAAC,OAAQ,QAAS,OAAQ,MAAO,OAAQ,SAAU,SAAS,CAEpF,EAAgB,IAChB,EAAgB,GAAK,EACrB,EAAc,GAAK,EACnB,EAAa,GAAK,EAClB,EAAc,EAAI,EAClB,EAAe,GAAK,EAGpB,EAAa,CACjB,CAAE,GAHgB,IAAM,EAGL,KAAM,OAAiB,CAC1C,CAAE,GAAI,EAAc,KAAM,QAAkB,CAC5C,CAAE,GAAI,EAAa,KAAM,OAAiB,CAC1C,CAAE,GAAI,EAAY,KAAM,MAAgB,CACxC,CAAE,GAAI,EAAa,KAAM,OAAiB,CAC1C,CAAE,GAAI,EAAe,KAAM,SAAmB,CAC9C,CAAE,GAAI,EAAe,KAAM,SAAmB,CAC/C,CAmBD,SAAgB,EACd,EACA,EAAmB,IAAI,KACvB,EAA2B,EACH,CACxB,IAAM,EAAQ,OAAO,GAAM,SAAW,KAAK,MAAM,EAAE,CAAG,EAAE,SAAS,CAC3D,EAAQ,OAAO,GAAM,SAAW,KAAK,MAAM,EAAE,CAAG,EAAE,SAAS,CAEjE,GAAI,OAAO,MAAM,EAAM,EAAI,OAAO,MAAM,EAAM,CAC5C,OAGF,IAAM,EAAQ,EAAW,OAAQ,GAAM,EAAa,SAAS,EAAE,KAAK,CAAC,CAC/D,EAAO,KAAK,IAAI,EAAQ,EAAM,CAC9B,EAAe,EAAM,EAAM,OAAS,IAAI,MAAQ,SAEtD,GAAI,GAAQ,EACV,MAAO,CAAE,KAAM,EAAc,MAAO,EAAG,CAIzC,IAAM,EAAW,EAAM,KAAM,GAAM,GAAQ,EAAE,GAAG,CAMhD,OAJI,EACK,CAAE,KAAM,EAAS,KAAM,MAAO,KAAK,MAAM,EAAO,EAAS,GAAG,CAAE,CAGhE,CAAE,KAAM,EAAc,MAAO,EAAG"}
@@ -0,0 +1,24 @@
1
+ export type TimeUnit = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';
2
+ export type TimeResult = {
3
+ unit: TimeUnit;
4
+ value: number;
5
+ };
6
+ /**
7
+ * Calculates the remaining time until a target date.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 5)); // { value: 5, unit: 'day' }
12
+ * timeDiff(new Date(Date.now() - 1000 * 60 * 60 * 24 * 3), 'past'); // { value: 3, unit: 'day' }
13
+ * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 31)); // { value: 1, unit: 'month' }
14
+ * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 365)); // { value: 1, unit: 'year' }
15
+ * ```
16
+ *
17
+ * @param a - The target date (Date object or ISO string).
18
+ * @param b - The target date (Date object or ISO string).
19
+ * @param allowedUnits - (optional) array of units to filter the result. If provided, only these units will be considered.
20
+ *
21
+ * @returns An object containing the remaining time and its unit ('DAY', 'HOUR', or 'MINUTE').
22
+ */
23
+ export declare function timeDiff(a: Date | string, b?: Date | string, allowedUnits?: TimeUnit[]): TimeResult | undefined;
24
+ //# sourceMappingURL=timeDiff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeDiff.d.ts","sourceRoot":"","sources":["../../src/date/timeDiff.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;AACxF,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAuB3D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CACtB,CAAC,EAAE,IAAI,GAAG,MAAM,EAChB,CAAC,GAAE,IAAI,GAAG,MAAmB,EAC7B,YAAY,GAAE,QAAQ,EAAc,GACnC,UAAU,GAAG,SAAS,CAwBxB"}
@@ -1,27 +1,60 @@
1
- let R = ["YEAR", "MONTH", "WEEK", "DAY", "HOUR", "MINUTE", "SECOND"];
2
- const N = [
3
- { ms: 31536e6, unit: "YEAR" },
4
- { ms: 2592e6, unit: "MONTH" },
5
- { ms: 6048e5, unit: "WEEK" },
6
- { ms: 864e5, unit: "DAY" },
7
- { ms: 36e5, unit: "HOUR" },
8
- { ms: 6e4, unit: "MINUTE" },
9
- { ms: 1e3, unit: "SECOND" }
1
+ //#region src/date/timeDiff.ts
2
+ var e = [
3
+ "year",
4
+ "month",
5
+ "week",
6
+ "day",
7
+ "hour",
8
+ "minute",
9
+ "second"
10
+ ], t = 1e3, n = 60 * t, r = 60 * n, i = 24 * r, a = 7 * i, o = 30 * i, s = [
11
+ {
12
+ ms: 365 * i,
13
+ unit: "year"
14
+ },
15
+ {
16
+ ms: o,
17
+ unit: "month"
18
+ },
19
+ {
20
+ ms: a,
21
+ unit: "week"
22
+ },
23
+ {
24
+ ms: i,
25
+ unit: "day"
26
+ },
27
+ {
28
+ ms: r,
29
+ unit: "hour"
30
+ },
31
+ {
32
+ ms: n,
33
+ unit: "minute"
34
+ },
35
+ {
36
+ ms: t,
37
+ unit: "second"
38
+ }
10
39
  ];
11
- function D(t, n = /* @__PURE__ */ new Date(), S = R) {
12
- const i = typeof t == "string" ? Date.parse(t) : t.getTime(), M = typeof n == "string" ? Date.parse(n) : n.getTime();
13
- if (Number.isNaN(i) || Number.isNaN(M))
14
- return { unit: "INVALID_DATE", value: 0 };
15
- const E = N.filter((e) => S.includes(e.unit)), _ = Math.abs(i - M), u = E[E.length - 1]?.unit ?? "SECOND";
16
- if (_ <= 0)
17
- return { unit: u, value: 0 };
18
- const s = E.find((e) => _ >= e.ms);
19
- return s ? { unit: s.unit, value: Math.floor(_ / s.ms) } : { unit: u, value: 0 };
40
+ function c(t, n = /* @__PURE__ */ new Date(), r = e) {
41
+ let i = typeof t == "string" ? Date.parse(t) : t.getTime(), a = typeof n == "string" ? Date.parse(n) : n.getTime();
42
+ if (Number.isNaN(i) || Number.isNaN(a)) return;
43
+ let o = s.filter((e) => r.includes(e.unit)), c = Math.abs(i - a), l = o[o.length - 1]?.unit ?? "second";
44
+ if (c <= 0) return {
45
+ unit: l,
46
+ value: 0
47
+ };
48
+ let u = o.find((e) => c >= e.ms);
49
+ return u ? {
50
+ unit: u.unit,
51
+ value: Math.floor(c / u.ms)
52
+ } : {
53
+ unit: l,
54
+ value: 0
55
+ };
20
56
  }
21
- D.defaultUnits = (t) => {
22
- R = t;
23
- };
24
- export {
25
- D as timeDiff
26
- };
27
- //# sourceMappingURL=timeDiff.js.map
57
+ //#endregion
58
+ export { c as timeDiff };
59
+
60
+ //# sourceMappingURL=timeDiff.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"timeDiff.js","sources":["../../src/date/timeDiff.ts"],"sourcesContent":["// #region TimeDiffTypes\nexport type TimeUnit = 'YEAR' | 'MONTH' | 'WEEK' | 'DAY' | 'HOUR' | 'MINUTE' | 'SECOND' | 'INVALID_DATE';\nexport type TimeDirection = 'FUTURE' | 'PAST';\nexport type TimeResult = { unit: TimeUnit; value: number };\n// #endregion TimeDiffTypes\n\nlet defaultUnits: TimeUnit[] = ['YEAR', 'MONTH', 'WEEK', 'DAY', 'HOUR', 'MINUTE', 'SECOND'];\n\nconst MS_PER_SECOND = 1000;\nconst MS_PER_MINUTE = 60 * MS_PER_SECOND;\nconst MS_PER_HOUR = 60 * MS_PER_MINUTE;\nconst MS_PER_DAY = 24 * MS_PER_HOUR;\nconst MS_PER_WEEK = 7 * MS_PER_DAY;\nconst MS_PER_MONTH = 30 * MS_PER_DAY;\nconst MS_PER_YEAR = 365 * MS_PER_DAY;\n\nconst TIME_UNITS = [\n { ms: MS_PER_YEAR, unit: 'YEAR' as const },\n { ms: MS_PER_MONTH, unit: 'MONTH' as const },\n { ms: MS_PER_WEEK, unit: 'WEEK' as const },\n { ms: MS_PER_DAY, unit: 'DAY' as const },\n { ms: MS_PER_HOUR, unit: 'HOUR' as const },\n { ms: MS_PER_MINUTE, unit: 'MINUTE' as const },\n { ms: MS_PER_SECOND, unit: 'SECOND' as const },\n];\n\n/**\n * Calculates the remaining time until a target date.\n *\n * @example\n * ```ts\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 5)); // { value: 5, unit: 'DAY' }\n * timeDiff(new Date(Date.now() - 1000 * 60 * 60 * 24 * 3), 'past'); // { value: 3, unit: 'DAY' }\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 31)); // { value: 1, unit: 'MONTH' }\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 365)); // { value: 1, unit: 'YEAR' }\n * ```\n *\n * @param a - The target date (Date object or ISO string).\n * @param b - The target date (Date object or ISO string).\n * @param allowedUnits - (optional) array of units to filter the result. If provided, only these units will be considered.\n *\n * @returns An object containing the remaining time and its unit ('DAY', 'HOUR', or 'MINUTE').\n */\nexport function timeDiff(\n a: Date | string,\n b: Date | string = new Date(),\n allowedUnits: TimeUnit[] = defaultUnits,\n): TimeResult {\n const aDate = typeof a === 'string' ? Date.parse(a) : a.getTime();\n const bDate = typeof b === 'string' ? Date.parse(b) : b.getTime();\n\n if (Number.isNaN(aDate) || Number.isNaN(bDate)) {\n return { unit: 'INVALID_DATE', value: 0 };\n }\n\n const units = TIME_UNITS.filter((u) => allowedUnits.includes(u.unit));\n const diff = Math.abs(aDate - bDate);\n const smallestUnit = units[units.length - 1]?.unit ?? 'SECOND';\n\n if (diff <= 0) {\n return { unit: smallestUnit, value: 0 };\n }\n\n // Find the largest unit that fits\n const bestUnit = units.find((u) => diff >= u.ms);\n\n if (bestUnit) {\n return { unit: bestUnit.unit, value: Math.floor(diff / bestUnit.ms) };\n }\n\n return { unit: smallestUnit, value: 0 };\n}\n\ntimeDiff.defaultUnits = (units: TimeUnit[]) => {\n defaultUnits = units;\n};\n"],"names":["defaultUnits","TIME_UNITS","timeDiff","a","b","allowedUnits","aDate","bDate","units","u","diff","smallestUnit","bestUnit"],"mappings":"AAMA,IAAIA,IAA2B,CAAC,QAAQ,SAAS,QAAQ,OAAO,QAAQ,UAAU,QAAQ;AAU1F,MAAMC,IAAa;AAAA,EACjB,EAAE,IAAI,SAAa,MAAM,OAAA;AAAA,EACzB,EAAE,IAAI,QAAc,MAAM,QAAA;AAAA,EAC1B,EAAE,IAAI,QAAa,MAAM,OAAA;AAAA,EACzB,EAAE,IAAI,OAAY,MAAM,MAAA;AAAA,EACxB,EAAE,IAAI,MAAa,MAAM,OAAA;AAAA,EACzB,EAAE,IAAI,KAAe,MAAM,SAAA;AAAA,EAC3B,EAAE,IAAI,KAAe,MAAM,SAAA;AAC7B;AAmBO,SAASC,EACdC,GACAC,wBAAuB,KAAA,GACvBC,IAA2BL,GACf;AACZ,QAAMM,IAAQ,OAAOH,KAAM,WAAW,KAAK,MAAMA,CAAC,IAAIA,EAAE,QAAA,GAClDI,IAAQ,OAAOH,KAAM,WAAW,KAAK,MAAMA,CAAC,IAAIA,EAAE,QAAA;AAExD,MAAI,OAAO,MAAME,CAAK,KAAK,OAAO,MAAMC,CAAK;AAC3C,WAAO,EAAE,MAAM,gBAAgB,OAAO,EAAA;AAGxC,QAAMC,IAAQP,EAAW,OAAO,CAACQ,MAAMJ,EAAa,SAASI,EAAE,IAAI,CAAC,GAC9DC,IAAO,KAAK,IAAIJ,IAAQC,CAAK,GAC7BI,IAAeH,EAAMA,EAAM,SAAS,CAAC,GAAG,QAAQ;AAEtD,MAAIE,KAAQ;AACV,WAAO,EAAE,MAAMC,GAAc,OAAO,EAAA;AAItC,QAAMC,IAAWJ,EAAM,KAAK,CAACC,MAAMC,KAAQD,EAAE,EAAE;AAE/C,SAAIG,IACK,EAAE,MAAMA,EAAS,MAAM,OAAO,KAAK,MAAMF,IAAOE,EAAS,EAAE,EAAA,IAG7D,EAAE,MAAMD,GAAc,OAAO,EAAA;AACtC;AAEAT,EAAS,eAAe,CAACM,MAAsB;AAC7C,EAAAR,IAAeQ;AACjB;"}
1
+ {"version":3,"file":"timeDiff.js","names":[],"sources":["../../src/date/timeDiff.ts"],"sourcesContent":["// #region TimeDiffTypes\nexport type TimeUnit = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';\nexport type TimeResult = { unit: TimeUnit; value: number };\n// #endregion TimeDiffTypes\n\nconst ALL_UNITS: TimeUnit[] = ['year', 'month', 'week', 'day', 'hour', 'minute', 'second'];\n\nconst MS_PER_SECOND = 1000;\nconst MS_PER_MINUTE = 60 * MS_PER_SECOND;\nconst MS_PER_HOUR = 60 * MS_PER_MINUTE;\nconst MS_PER_DAY = 24 * MS_PER_HOUR;\nconst MS_PER_WEEK = 7 * MS_PER_DAY;\nconst MS_PER_MONTH = 30 * MS_PER_DAY;\nconst MS_PER_YEAR = 365 * MS_PER_DAY;\n\nconst TIME_UNITS = [\n { ms: MS_PER_YEAR, unit: 'year' as const },\n { ms: MS_PER_MONTH, unit: 'month' as const },\n { ms: MS_PER_WEEK, unit: 'week' as const },\n { ms: MS_PER_DAY, unit: 'day' as const },\n { ms: MS_PER_HOUR, unit: 'hour' as const },\n { ms: MS_PER_MINUTE, unit: 'minute' as const },\n { ms: MS_PER_SECOND, unit: 'second' as const },\n];\n\n/**\n * Calculates the remaining time until a target date.\n *\n * @example\n * ```ts\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 5)); // { value: 5, unit: 'day' }\n * timeDiff(new Date(Date.now() - 1000 * 60 * 60 * 24 * 3), 'past'); // { value: 3, unit: 'day' }\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 31)); // { value: 1, unit: 'month' }\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 365)); // { value: 1, unit: 'year' }\n * ```\n *\n * @param a - The target date (Date object or ISO string).\n * @param b - The target date (Date object or ISO string).\n * @param allowedUnits - (optional) array of units to filter the result. If provided, only these units will be considered.\n *\n * @returns An object containing the remaining time and its unit ('DAY', 'HOUR', or 'MINUTE').\n */\nexport function timeDiff(\n a: Date | string,\n b: Date | string = new Date(),\n allowedUnits: TimeUnit[] = ALL_UNITS,\n): TimeResult | undefined {\n const aDate = typeof a === 'string' ? Date.parse(a) : a.getTime();\n const bDate = typeof b === 'string' ? Date.parse(b) : b.getTime();\n\n if (Number.isNaN(aDate) || Number.isNaN(bDate)) {\n return undefined;\n }\n\n const units = TIME_UNITS.filter((u) => allowedUnits.includes(u.unit));\n const diff = Math.abs(aDate - bDate);\n const smallestUnit = units[units.length - 1]?.unit ?? 'second';\n\n if (diff <= 0) {\n return { unit: smallestUnit, value: 0 };\n }\n\n // Find the largest unit that fits\n const bestUnit = units.find((u) => diff >= u.ms);\n\n if (bestUnit) {\n return { unit: bestUnit.unit, value: Math.floor(diff / bestUnit.ms) };\n }\n\n return { unit: smallestUnit, value: 0 };\n}\n"],"mappings":";AAKA,IAAM,IAAwB;CAAC;CAAQ;CAAS;CAAQ;CAAO;CAAQ;CAAU;CAAS,EAEpF,IAAgB,KAChB,IAAgB,KAAK,GACrB,IAAc,KAAK,GACnB,IAAa,KAAK,GAClB,IAAc,IAAI,GAClB,IAAe,KAAK,GAGpB,IAAa;CACjB;EAAE,IAHgB,MAAM;EAGL,MAAM;EAAiB;CAC1C;EAAE,IAAI;EAAc,MAAM;EAAkB;CAC5C;EAAE,IAAI;EAAa,MAAM;EAAiB;CAC1C;EAAE,IAAI;EAAY,MAAM;EAAgB;CACxC;EAAE,IAAI;EAAa,MAAM;EAAiB;CAC1C;EAAE,IAAI;EAAe,MAAM;EAAmB;CAC9C;EAAE,IAAI;EAAe,MAAM;EAAmB;CAC/C;AAmBD,SAAgB,EACd,GACA,oBAAmB,IAAI,MAAM,EAC7B,IAA2B,GACH;CACxB,IAAM,IAAQ,OAAO,KAAM,WAAW,KAAK,MAAM,EAAE,GAAG,EAAE,SAAS,EAC3D,IAAQ,OAAO,KAAM,WAAW,KAAK,MAAM,EAAE,GAAG,EAAE,SAAS;AAEjE,KAAI,OAAO,MAAM,EAAM,IAAI,OAAO,MAAM,EAAM,CAC5C;CAGF,IAAM,IAAQ,EAAW,QAAQ,MAAM,EAAa,SAAS,EAAE,KAAK,CAAC,EAC/D,IAAO,KAAK,IAAI,IAAQ,EAAM,EAC9B,IAAe,EAAM,EAAM,SAAS,IAAI,QAAQ;AAEtD,KAAI,KAAQ,EACV,QAAO;EAAE,MAAM;EAAc,OAAO;EAAG;CAIzC,IAAM,IAAW,EAAM,MAAM,MAAM,KAAQ,EAAE,GAAG;AAMhD,QAJI,IACK;EAAE,MAAM,EAAS;EAAM,OAAO,KAAK,MAAM,IAAO,EAAS,GAAG;EAAE,GAGhE;EAAE,MAAM;EAAc,OAAO;EAAG"}
@@ -1,3 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../logit/dist/logit.cjs");function f(e,t="Assertion failed",{type:l=Error,args:r,bypass:i=!1}={}){if(!(Array.isArray(e)?e.some(o=>!o):!e))return;const a=r?`
2
- Arguments: ${JSON.stringify(r,null,2)}`:"",s=`${t}${a}`;if(i)n.Logit.warn(s);else throw new l(s)}exports.assert=f;
3
- //# sourceMappingURL=assert.cjs.map
1
+ function e(e,t=`Assertion failed`,{args:n,bypass:r=!1,type:i=Error}={}){if(e)return;let a=`${t}${n?`\nArguments: ${JSON.stringify(n,null,2)}`:``}`;if(r)console.warn(a);else throw new i(a)}function t(t,n=`Assertion failed`,r={}){e(t.every(Boolean),n,r)}exports.assert=e,exports.assertAll=t;
2
+ //# sourceMappingURL=assert.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"assert.cjs","sources":["../../src/function/assert.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport type { Obj } from '../types';\n\n/**\n * Asserts that the condition is true. If the condition is false, it throws an error\n * with the provided message or logs a warning in soft mode.\n *\n * @example\n * ```ts\n * assert(Array.isArray([])); // Does nothing\n * assert(typeof foo === 'string', 'This is an error message'); // Throws an error\n * assert(x > 0, 'x must be positive', { args: { x } }); // Throws with argument details\n * ```\n *\n * @param condition - The condition to assert, or an array of conditions.\n * @param [message] - The error message to throw. Default is 'Assertion failed'.\n * @param options - Assertion options.\n * @param [options.type] - The error class to throw (default: `Error`).\n * @param [options.args] - Additional debugging information (e.g., variable values).\n * @param [options.bypass] - If `true`, logs a warning instead of throwing an error.\n *\n * @throws {Error} If the condition is false and `bypass` is not set to `true`.\n */\nexport function assert(\n condition: boolean | boolean[],\n message = 'Assertion failed',\n { type = Error, args, bypass = false }: { type?: ErrorConstructor; args?: Obj; bypass?: boolean } = {},\n): void {\n const failed = Array.isArray(condition) ? condition.some((cond) => !cond) : !condition;\n if (!failed) return;\n\n const errorDetails = args ? `\\nArguments: ${JSON.stringify(args, null, 2)}` : '';\n const fullMessage = `${message}${errorDetails}`;\n\n if (bypass) Logit.warn(fullMessage);\n else throw new type(fullMessage);\n}\n"],"names":["assert","condition","message","type","args","bypass","cond","errorDetails","fullMessage","Logit"],"mappings":"2HAuBO,SAASA,EACdC,EACAC,EAAU,mBACV,CAAE,KAAAC,EAAO,MAAO,KAAAC,EAAM,OAAAC,EAAS,EAAA,EAAqE,CAAA,EAC9F,CAEN,GAAI,EADW,MAAM,QAAQJ,CAAS,EAAIA,EAAU,KAAMK,GAAS,CAACA,CAAI,EAAI,CAACL,GAChE,OAEb,MAAMM,EAAeH,EAAO;AAAA,aAAgB,KAAK,UAAUA,EAAM,KAAM,CAAC,CAAC,GAAK,GACxEI,EAAc,GAAGN,CAAO,GAAGK,CAAY,GAE7C,GAAIF,EAAQI,EAAAA,MAAM,KAAKD,CAAW,MAC7B,OAAM,IAAIL,EAAKK,CAAW,CACjC"}
1
+ {"version":3,"file":"assert.cjs","names":[],"sources":["../../src/function/assert.ts"],"sourcesContent":["import type { Obj } from '../types';\n\ntype AssertOptions = { args?: Obj; bypass?: boolean; type?: ErrorConstructor };\n\n/**\n * Asserts that a condition is true. Throws (or warns, with `bypass`) otherwise.\n *\n * @example\n * ```ts\n * assert(Array.isArray([])); // ok\n * assert(x > 0, 'x must be positive'); // throws if false\n * assert(x > 0, 'x must be positive', { args: { x } });\n * assert(ok, 'not ok', { bypass: true }); // logs warning instead of throwing\n * assertAll([cond1, cond2], 'One failed'); // throws if any is false\n * ```\n *\n * @param condition - The boolean condition to assert.\n * @param [message] - Error message (default: `'Assertion failed'`).\n * @param [options.type] - Error class to throw (default: `Error`).\n * @param [options.args] - Debugging info appended to the message.\n * @param [options.bypass] - Log a warning instead of throwing.\n *\n * @throws {Error} If `condition` is false and `bypass` is not set.\n */\nexport function assert(\n condition: boolean,\n message = 'Assertion failed',\n { args, bypass = false, type = Error }: AssertOptions = {},\n): void {\n if (condition) return;\n\n const errorDetails = args ? `\\nArguments: ${JSON.stringify(args, null, 2)}` : '';\n const fullMessage = `${message}${errorDetails}`;\n\n if (bypass) console.warn(fullMessage);\n else throw new type(fullMessage);\n}\n\n/**\n * Asserts that every condition in the array is true.\n *\n * @example\n * ```ts\n * assertAll([cond1, cond2, cond3], 'One or more conditions failed');\n * ```\n */\nexport function assertAll(conditions: boolean[], message = 'Assertion failed', options: AssertOptions = {}): void {\n assert(conditions.every(Boolean), message, options);\n}\n"],"mappings":"AAwBA,SAAgB,EACd,EACA,EAAU,mBACV,CAAE,OAAM,SAAS,GAAO,OAAO,OAAyB,EAAE,CACpD,CACN,GAAI,EAAW,OAGf,IAAM,EAAc,GAAG,IADF,EAAO,gBAAgB,KAAK,UAAU,EAAM,KAAM,EAAE,GAAK,KAG9E,GAAI,EAAQ,QAAQ,KAAK,EAAY,MAChC,MAAM,IAAI,EAAK,EAAY,CAWlC,SAAgB,EAAU,EAAuB,EAAU,mBAAoB,EAAyB,EAAE,CAAQ,CAChH,EAAO,EAAW,MAAM,QAAQ,CAAE,EAAS,EAAQ"}
@@ -0,0 +1,38 @@
1
+ import type { Obj } from '../types';
2
+ type AssertOptions = {
3
+ args?: Obj;
4
+ bypass?: boolean;
5
+ type?: ErrorConstructor;
6
+ };
7
+ /**
8
+ * Asserts that a condition is true. Throws (or warns, with `bypass`) otherwise.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * assert(Array.isArray([])); // ok
13
+ * assert(x > 0, 'x must be positive'); // throws if false
14
+ * assert(x > 0, 'x must be positive', { args: { x } });
15
+ * assert(ok, 'not ok', { bypass: true }); // logs warning instead of throwing
16
+ * assertAll([cond1, cond2], 'One failed'); // throws if any is false
17
+ * ```
18
+ *
19
+ * @param condition - The boolean condition to assert.
20
+ * @param [message] - Error message (default: `'Assertion failed'`).
21
+ * @param [options.type] - Error class to throw (default: `Error`).
22
+ * @param [options.args] - Debugging info appended to the message.
23
+ * @param [options.bypass] - Log a warning instead of throwing.
24
+ *
25
+ * @throws {Error} If `condition` is false and `bypass` is not set.
26
+ */
27
+ export declare function assert(condition: boolean, message?: string, { args, bypass, type }?: AssertOptions): void;
28
+ /**
29
+ * Asserts that every condition in the array is true.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * assertAll([cond1, cond2, cond3], 'One or more conditions failed');
34
+ * ```
35
+ */
36
+ export declare function assertAll(conditions: boolean[], message?: string, options?: AssertOptions): void;
37
+ export {};
38
+ //# sourceMappingURL=assert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/function/assert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,KAAK,aAAa,GAAG;IAAE,IAAI,CAAC,EAAE,GAAG,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CACpB,SAAS,EAAE,OAAO,EAClB,OAAO,SAAqB,EAC5B,EAAE,IAAI,EAAE,MAAc,EAAE,IAAY,EAAE,GAAE,aAAkB,GACzD,IAAI,CAQN;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,OAAO,SAAqB,EAAE,OAAO,GAAE,aAAkB,GAAG,IAAI,CAEhH"}
@@ -1,12 +1,14 @@
1
- import { Logit as o } from "../logit/dist/logit.js";
2
- function m(r, t = "Assertion failed", { type: a = Error, args: e, bypass: f = !1 } = {}) {
3
- if (!(Array.isArray(r) ? r.some((i) => !i) : !r)) return;
4
- const l = e ? `
5
- Arguments: ${JSON.stringify(e, null, 2)}` : "", s = `${t}${l}`;
6
- if (f) o.warn(s);
7
- else throw new a(s);
1
+ //#region src/function/assert.ts
2
+ function e(e, t = "Assertion failed", { args: n, bypass: r = !1, type: i = Error } = {}) {
3
+ if (e) return;
4
+ let a = `${t}${n ? `\nArguments: ${JSON.stringify(n, null, 2)}` : ""}`;
5
+ if (r) console.warn(a);
6
+ else throw new i(a);
8
7
  }
9
- export {
10
- m as assert
11
- };
12
- //# sourceMappingURL=assert.js.map
8
+ function t(t, n = "Assertion failed", r = {}) {
9
+ e(t.every(Boolean), n, r);
10
+ }
11
+ //#endregion
12
+ export { e as assert, t as assertAll };
13
+
14
+ //# sourceMappingURL=assert.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"assert.js","sources":["../../src/function/assert.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport type { Obj } from '../types';\n\n/**\n * Asserts that the condition is true. If the condition is false, it throws an error\n * with the provided message or logs a warning in soft mode.\n *\n * @example\n * ```ts\n * assert(Array.isArray([])); // Does nothing\n * assert(typeof foo === 'string', 'This is an error message'); // Throws an error\n * assert(x > 0, 'x must be positive', { args: { x } }); // Throws with argument details\n * ```\n *\n * @param condition - The condition to assert, or an array of conditions.\n * @param [message] - The error message to throw. Default is 'Assertion failed'.\n * @param options - Assertion options.\n * @param [options.type] - The error class to throw (default: `Error`).\n * @param [options.args] - Additional debugging information (e.g., variable values).\n * @param [options.bypass] - If `true`, logs a warning instead of throwing an error.\n *\n * @throws {Error} If the condition is false and `bypass` is not set to `true`.\n */\nexport function assert(\n condition: boolean | boolean[],\n message = 'Assertion failed',\n { type = Error, args, bypass = false }: { type?: ErrorConstructor; args?: Obj; bypass?: boolean } = {},\n): void {\n const failed = Array.isArray(condition) ? condition.some((cond) => !cond) : !condition;\n if (!failed) return;\n\n const errorDetails = args ? `\\nArguments: ${JSON.stringify(args, null, 2)}` : '';\n const fullMessage = `${message}${errorDetails}`;\n\n if (bypass) Logit.warn(fullMessage);\n else throw new type(fullMessage);\n}\n"],"names":["assert","condition","message","type","args","bypass","cond","errorDetails","fullMessage","Logit"],"mappings":";AAuBO,SAASA,EACdC,GACAC,IAAU,oBACV,EAAE,MAAAC,IAAO,OAAO,MAAAC,GAAM,QAAAC,IAAS,GAAA,IAAqE,CAAA,GAC9F;AAEN,MAAI,EADW,MAAM,QAAQJ,CAAS,IAAIA,EAAU,KAAK,CAACK,MAAS,CAACA,CAAI,IAAI,CAACL,GAChE;AAEb,QAAMM,IAAeH,IAAO;AAAA,aAAgB,KAAK,UAAUA,GAAM,MAAM,CAAC,CAAC,KAAK,IACxEI,IAAc,GAAGN,CAAO,GAAGK,CAAY;AAE7C,MAAIF,EAAQI,CAAAA,EAAM,KAAKD,CAAW;AAAA,MAC7B,OAAM,IAAIL,EAAKK,CAAW;AACjC;"}
1
+ {"version":3,"file":"assert.js","names":[],"sources":["../../src/function/assert.ts"],"sourcesContent":["import type { Obj } from '../types';\n\ntype AssertOptions = { args?: Obj; bypass?: boolean; type?: ErrorConstructor };\n\n/**\n * Asserts that a condition is true. Throws (or warns, with `bypass`) otherwise.\n *\n * @example\n * ```ts\n * assert(Array.isArray([])); // ok\n * assert(x > 0, 'x must be positive'); // throws if false\n * assert(x > 0, 'x must be positive', { args: { x } });\n * assert(ok, 'not ok', { bypass: true }); // logs warning instead of throwing\n * assertAll([cond1, cond2], 'One failed'); // throws if any is false\n * ```\n *\n * @param condition - The boolean condition to assert.\n * @param [message] - Error message (default: `'Assertion failed'`).\n * @param [options.type] - Error class to throw (default: `Error`).\n * @param [options.args] - Debugging info appended to the message.\n * @param [options.bypass] - Log a warning instead of throwing.\n *\n * @throws {Error} If `condition` is false and `bypass` is not set.\n */\nexport function assert(\n condition: boolean,\n message = 'Assertion failed',\n { args, bypass = false, type = Error }: AssertOptions = {},\n): void {\n if (condition) return;\n\n const errorDetails = args ? `\\nArguments: ${JSON.stringify(args, null, 2)}` : '';\n const fullMessage = `${message}${errorDetails}`;\n\n if (bypass) console.warn(fullMessage);\n else throw new type(fullMessage);\n}\n\n/**\n * Asserts that every condition in the array is true.\n *\n * @example\n * ```ts\n * assertAll([cond1, cond2, cond3], 'One or more conditions failed');\n * ```\n */\nexport function assertAll(conditions: boolean[], message = 'Assertion failed', options: AssertOptions = {}): void {\n assert(conditions.every(Boolean), message, options);\n}\n"],"mappings":";AAwBA,SAAgB,EACd,GACA,IAAU,oBACV,EAAE,SAAM,YAAS,IAAO,UAAO,UAAyB,EAAE,EACpD;AACN,KAAI,EAAW;CAGf,IAAM,IAAc,GAAG,IADF,IAAO,gBAAgB,KAAK,UAAU,GAAM,MAAM,EAAE,KAAK;AAG9E,KAAI,EAAQ,SAAQ,KAAK,EAAY;KAChC,OAAM,IAAI,EAAK,EAAY;;AAWlC,SAAgB,EAAU,GAAuB,IAAU,oBAAoB,IAAyB,EAAE,EAAQ;AAChH,GAAO,EAAW,MAAM,QAAQ,EAAE,GAAS,EAAQ"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./assert.cjs");function l(e,o,r,i={}){n.assert(!!e,"Missing parameters object",i);const t=o.filter(s=>e[s]===void 0||e[s]===null||e[s]==="");if(t.length>0){const s=r?` in "${r}"`:"",a=t.map(g=>`"${String(g)}"`).join(", "),c=`Missing required parameter${t.length>1?"s":""}: ${a}${s}`;n.assert(!1,c,i)}}exports.assertParams=l;
2
- //# sourceMappingURL=assertParams.cjs.map
1
+ const e=require(`./assert.cjs`);function t(t,n,r,i={}){e.assert(!!t,`Missing parameters object`,i);let a=n.filter(e=>t[e]===void 0||t[e]===null);if(a.length>0){let t=r?` in "${r}"`:``,n=a.map(e=>`"${String(e)}"`).join(`, `);e.assert(!1,`Missing required parameter${a.length>1?`s`:``}: ${n}${t}`,i)}}exports.assertParams=t;
2
+ //# sourceMappingURL=assertParams.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"assertParams.cjs","sources":["../../src/function/assertParams.ts"],"sourcesContent":["import { assert } from './assert';\n\n/**\n * Asserts that the specified keys are present in the params object and are not empty strings.\n *\n * @example\n * ```ts\n * const params = { id: '123', name: '' };\n * assertParams(params, ['id']); // Does nothing\n * assertParams(params, ['id', 'name'], 'UserUpdate'); // Throws: Missing required parameter: \"name\" in \"UserUpdate\"\n * ```\n *\n * @param params - The object containing the parameters to check.\n * @param keys - An array of keys that must be present and non-empty in the params object.\n * @param [name] - An optional name for the context of the assertion (e.g., function name).\n * @param [options] - Assertion options.\n * @param [options.type] - The error class to throw (default: `Error`).\n * @param [options.bypass] - If `true`, logs a warning instead of throwing an error.\n *\n * @throws {Error} If any of the required keys are missing or are empty strings.\n */\nexport function assertParams<T extends object, K extends keyof T>(\n params: T,\n keys: K[],\n name?: string,\n options: { type?: ErrorConstructor; bypass?: boolean } = {},\n): asserts params is T & Required<Pick<T, K>> {\n assert(!!params, 'Missing parameters object', options);\n\n const missing = keys.filter((key) => params[key] === undefined || params[key] === null || params[key] === '');\n\n if (missing.length > 0) {\n const context = name ? ` in \"${name}\"` : '';\n const keysStr = missing.map((key) => `\"${String(key)}\"`).join(', ');\n const message = `Missing required parameter${missing.length > 1 ? 's' : ''}: ${keysStr}${context}`;\n\n assert(false, message, options);\n }\n}\n"],"names":["assertParams","params","keys","name","options","assert","missing","key","context","keysStr","message"],"mappings":"gHAqBO,SAASA,EACdC,EACAC,EACAC,EACAC,EAAyD,CAAA,EACb,CAC5CC,EAAAA,OAAO,CAAC,CAACJ,EAAQ,4BAA6BG,CAAO,EAErD,MAAME,EAAUJ,EAAK,OAAQK,GAAQN,EAAOM,CAAG,IAAM,QAAaN,EAAOM,CAAG,IAAM,MAAQN,EAAOM,CAAG,IAAM,EAAE,EAE5G,GAAID,EAAQ,OAAS,EAAG,CACtB,MAAME,EAAUL,EAAO,QAAQA,CAAI,IAAM,GACnCM,EAAUH,EAAQ,IAAKC,GAAQ,IAAI,OAAOA,CAAG,CAAC,GAAG,EAAE,KAAK,IAAI,EAC5DG,EAAU,6BAA6BJ,EAAQ,OAAS,EAAI,IAAM,EAAE,KAAKG,CAAO,GAAGD,CAAO,GAEhGH,SAAO,GAAOK,EAASN,CAAO,CAChC,CACF"}
1
+ {"version":3,"file":"assertParams.cjs","names":[],"sources":["../../src/function/assertParams.ts"],"sourcesContent":["import { assert } from './assert';\n\n/**\n * Asserts that the specified keys are present and non-null in the params object.\n *\n * @example\n * ```ts\n * const params = { id: '123', name: undefined };\n * assertParams(params, ['id']); // Does nothing\n * assertParams(params, ['id', 'name'], 'UserUpdate'); // Throws: Missing required parameter: \"name\" in \"UserUpdate\"\n * ```\n *\n * @param params - The object containing the parameters to check.\n * @param keys - An array of keys that must be present (not null or undefined) in the params object.\n * @param [name] - An optional name for the context of the assertion (e.g., function name).\n * @param [options] - Assertion options.\n * @param [options.type] - The error class to throw (default: `Error`).\n * @param [options.bypass] - If `true`, logs a warning instead of throwing an error.\n *\n * @throws {Error} If any of the required keys are missing.\n */\nexport function assertParams<T extends object, K extends keyof T>(\n params: T,\n keys: K[],\n name?: string,\n options: { bypass?: boolean; type?: ErrorConstructor } = {},\n): asserts params is T & Required<Pick<T, K>> {\n assert(!!params, 'Missing parameters object', options);\n\n const missing = keys.filter((key) => params[key] === undefined || params[key] === null);\n\n if (missing.length > 0) {\n const context = name ? ` in \"${name}\"` : '';\n const keysStr = missing.map((key) => `\"${String(key)}\"`).join(', ');\n const message = `Missing required parameter${missing.length > 1 ? 's' : ''}: ${keysStr}${context}`;\n\n assert(false, message, options);\n }\n}\n"],"mappings":"gCAqBA,SAAgB,EACd,EACA,EACA,EACA,EAAyD,EAAE,CACf,CAC5C,EAAA,OAAO,CAAC,CAAC,EAAQ,4BAA6B,EAAQ,CAEtD,IAAM,EAAU,EAAK,OAAQ,GAAQ,EAAO,KAAS,IAAA,IAAa,EAAO,KAAS,KAAK,CAEvF,GAAI,EAAQ,OAAS,EAAG,CACtB,IAAM,EAAU,EAAO,QAAQ,EAAK,GAAK,GACnC,EAAU,EAAQ,IAAK,GAAQ,IAAI,OAAO,EAAI,CAAC,GAAG,CAAC,KAAK,KAAK,CAGnE,EAAA,OAAO,GAFS,6BAA6B,EAAQ,OAAS,EAAI,IAAM,GAAG,IAAI,IAAU,IAElE,EAAQ"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Asserts that the specified keys are present and non-null in the params object.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * const params = { id: '123', name: undefined };
7
+ * assertParams(params, ['id']); // Does nothing
8
+ * assertParams(params, ['id', 'name'], 'UserUpdate'); // Throws: Missing required parameter: "name" in "UserUpdate"
9
+ * ```
10
+ *
11
+ * @param params - The object containing the parameters to check.
12
+ * @param keys - An array of keys that must be present (not null or undefined) in the params object.
13
+ * @param [name] - An optional name for the context of the assertion (e.g., function name).
14
+ * @param [options] - Assertion options.
15
+ * @param [options.type] - The error class to throw (default: `Error`).
16
+ * @param [options.bypass] - If `true`, logs a warning instead of throwing an error.
17
+ *
18
+ * @throws {Error} If any of the required keys are missing.
19
+ */
20
+ export declare function assertParams<T extends object, K extends keyof T>(params: T, keys: K[], name?: string, options?: {
21
+ bypass?: boolean;
22
+ type?: ErrorConstructor;
23
+ }): asserts params is T & Required<Pick<T, K>>;
24
+ //# sourceMappingURL=assertParams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertParams.d.ts","sourceRoot":"","sources":["../../src/function/assertParams.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAC9D,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,CAAC,EAAE,EACT,IAAI,CAAC,EAAE,MAAM,EACb,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,gBAAgB,CAAA;CAAO,GAC1D,OAAO,CAAC,MAAM,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAY5C"}
@@ -1,13 +1,14 @@
1
- import { assert as r } from "./assert.js";
2
- function $(s, o, i, n = {}) {
3
- r(!!s, "Missing parameters object", n);
4
- const e = o.filter((t) => s[t] === void 0 || s[t] === null || s[t] === "");
5
- if (e.length > 0) {
6
- const t = i ? ` in "${i}"` : "", c = e.map((l) => `"${String(l)}"`).join(", "), g = `Missing required parameter${e.length > 1 ? "s" : ""}: ${c}${t}`;
7
- r(!1, g, n);
8
- }
1
+ import { assert as e } from "./assert.js";
2
+ //#region src/function/assertParams.ts
3
+ function t(t, n, r, i = {}) {
4
+ e(!!t, "Missing parameters object", i);
5
+ let a = n.filter((e) => t[e] === void 0 || t[e] === null);
6
+ if (a.length > 0) {
7
+ let t = r ? ` in "${r}"` : "", n = a.map((e) => `"${String(e)}"`).join(", ");
8
+ e(!1, `Missing required parameter${a.length > 1 ? "s" : ""}: ${n}${t}`, i);
9
+ }
9
10
  }
10
- export {
11
- $ as assertParams
12
- };
13
- //# sourceMappingURL=assertParams.js.map
11
+ //#endregion
12
+ export { t as assertParams };
13
+
14
+ //# sourceMappingURL=assertParams.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"assertParams.js","sources":["../../src/function/assertParams.ts"],"sourcesContent":["import { assert } from './assert';\n\n/**\n * Asserts that the specified keys are present in the params object and are not empty strings.\n *\n * @example\n * ```ts\n * const params = { id: '123', name: '' };\n * assertParams(params, ['id']); // Does nothing\n * assertParams(params, ['id', 'name'], 'UserUpdate'); // Throws: Missing required parameter: \"name\" in \"UserUpdate\"\n * ```\n *\n * @param params - The object containing the parameters to check.\n * @param keys - An array of keys that must be present and non-empty in the params object.\n * @param [name] - An optional name for the context of the assertion (e.g., function name).\n * @param [options] - Assertion options.\n * @param [options.type] - The error class to throw (default: `Error`).\n * @param [options.bypass] - If `true`, logs a warning instead of throwing an error.\n *\n * @throws {Error} If any of the required keys are missing or are empty strings.\n */\nexport function assertParams<T extends object, K extends keyof T>(\n params: T,\n keys: K[],\n name?: string,\n options: { type?: ErrorConstructor; bypass?: boolean } = {},\n): asserts params is T & Required<Pick<T, K>> {\n assert(!!params, 'Missing parameters object', options);\n\n const missing = keys.filter((key) => params[key] === undefined || params[key] === null || params[key] === '');\n\n if (missing.length > 0) {\n const context = name ? ` in \"${name}\"` : '';\n const keysStr = missing.map((key) => `\"${String(key)}\"`).join(', ');\n const message = `Missing required parameter${missing.length > 1 ? 's' : ''}: ${keysStr}${context}`;\n\n assert(false, message, options);\n }\n}\n"],"names":["assertParams","params","keys","name","options","assert","missing","key","context","keysStr","message"],"mappings":";AAqBO,SAASA,EACdC,GACAC,GACAC,GACAC,IAAyD,CAAA,GACb;AAC5C,EAAAC,EAAO,CAAC,CAACJ,GAAQ,6BAA6BG,CAAO;AAErD,QAAME,IAAUJ,EAAK,OAAO,CAACK,MAAQN,EAAOM,CAAG,MAAM,UAAaN,EAAOM,CAAG,MAAM,QAAQN,EAAOM,CAAG,MAAM,EAAE;AAE5G,MAAID,EAAQ,SAAS,GAAG;AACtB,UAAME,IAAUL,IAAO,QAAQA,CAAI,MAAM,IACnCM,IAAUH,EAAQ,IAAI,CAACC,MAAQ,IAAI,OAAOA,CAAG,CAAC,GAAG,EAAE,KAAK,IAAI,GAC5DG,IAAU,6BAA6BJ,EAAQ,SAAS,IAAI,MAAM,EAAE,KAAKG,CAAO,GAAGD,CAAO;AAEhG,IAAAH,EAAO,IAAOK,GAASN,CAAO;AAAA,EAChC;AACF;"}
1
+ {"version":3,"file":"assertParams.js","names":[],"sources":["../../src/function/assertParams.ts"],"sourcesContent":["import { assert } from './assert';\n\n/**\n * Asserts that the specified keys are present and non-null in the params object.\n *\n * @example\n * ```ts\n * const params = { id: '123', name: undefined };\n * assertParams(params, ['id']); // Does nothing\n * assertParams(params, ['id', 'name'], 'UserUpdate'); // Throws: Missing required parameter: \"name\" in \"UserUpdate\"\n * ```\n *\n * @param params - The object containing the parameters to check.\n * @param keys - An array of keys that must be present (not null or undefined) in the params object.\n * @param [name] - An optional name for the context of the assertion (e.g., function name).\n * @param [options] - Assertion options.\n * @param [options.type] - The error class to throw (default: `Error`).\n * @param [options.bypass] - If `true`, logs a warning instead of throwing an error.\n *\n * @throws {Error} If any of the required keys are missing.\n */\nexport function assertParams<T extends object, K extends keyof T>(\n params: T,\n keys: K[],\n name?: string,\n options: { bypass?: boolean; type?: ErrorConstructor } = {},\n): asserts params is T & Required<Pick<T, K>> {\n assert(!!params, 'Missing parameters object', options);\n\n const missing = keys.filter((key) => params[key] === undefined || params[key] === null);\n\n if (missing.length > 0) {\n const context = name ? ` in \"${name}\"` : '';\n const keysStr = missing.map((key) => `\"${String(key)}\"`).join(', ');\n const message = `Missing required parameter${missing.length > 1 ? 's' : ''}: ${keysStr}${context}`;\n\n assert(false, message, options);\n }\n}\n"],"mappings":";;AAqBA,SAAgB,EACd,GACA,GACA,GACA,IAAyD,EAAE,EACf;AAC5C,GAAO,CAAC,CAAC,GAAQ,6BAA6B,EAAQ;CAEtD,IAAM,IAAU,EAAK,QAAQ,MAAQ,EAAO,OAAS,KAAA,KAAa,EAAO,OAAS,KAAK;AAEvF,KAAI,EAAQ,SAAS,GAAG;EACtB,IAAM,IAAU,IAAO,QAAQ,EAAK,KAAK,IACnC,IAAU,EAAQ,KAAK,MAAQ,IAAI,OAAO,EAAI,CAAC,GAAG,CAAC,KAAK,KAAK;AAGnE,IAAO,IAFS,6BAA6B,EAAQ,SAAS,IAAI,MAAM,GAAG,IAAI,IAAU,KAElE,EAAQ"}
@@ -1,2 +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
1
+ var e=(e,t)=>{if(e===t)return 0;if(e===void 0)return 1;if(t===void 0)return-1;if(e===null)return t===null?0:-1;if(t===null)return 1;if(typeof e==`string`&&typeof t==`string`)return e.localeCompare(t);if(typeof e==`number`&&typeof t==`number`)return e===t?0:e>t?1:-1;if(e instanceof Date&&t instanceof Date){let n=e.getTime(),r=t.getTime();return n===r?0:n>r?1:-1}if(typeof e==`object`&&typeof t==`object`){let n=JSON.stringify(e),r=JSON.stringify(t);return n.localeCompare(r)}return String(e).localeCompare(String(t))};exports.compare=e;
2
+ //# sourceMappingURL=compare.cjs.map