litus 1.3.1 → 1.5.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 (385) hide show
  1. package/README.md +17 -17
  2. package/dist/index.cjs.js +1206 -0
  3. package/dist/index.cjs.js.map +1 -0
  4. package/dist/index.d.ts +779 -0
  5. package/dist/index.esm.js +1132 -0
  6. package/dist/index.esm.js.map +1 -0
  7. package/package.json +16 -8
  8. package/dist/cjs/arr/chunk.d.ts +0 -1
  9. package/dist/cjs/arr/chunk.js +0 -12
  10. package/dist/cjs/arr/chunk.js.map +0 -1
  11. package/dist/cjs/arr/fill.d.ts +0 -1
  12. package/dist/cjs/arr/fill.js +0 -9
  13. package/dist/cjs/arr/fill.js.map +0 -1
  14. package/dist/cjs/arr/find.d.ts +0 -2
  15. package/dist/cjs/arr/find.js +0 -9
  16. package/dist/cjs/arr/find.js.map +0 -1
  17. package/dist/cjs/arr/findAll.d.ts +0 -2
  18. package/dist/cjs/arr/findAll.js +0 -9
  19. package/dist/cjs/arr/findAll.js.map +0 -1
  20. package/dist/cjs/arr/findAllIdx.d.ts +0 -2
  21. package/dist/cjs/arr/findAllIdx.js +0 -17
  22. package/dist/cjs/arr/findAllIdx.js.map +0 -1
  23. package/dist/cjs/arr/findIdx.d.ts +0 -2
  24. package/dist/cjs/arr/findIdx.js +0 -13
  25. package/dist/cjs/arr/findIdx.js.map +0 -1
  26. package/dist/cjs/arr/from.d.ts +0 -1
  27. package/dist/cjs/arr/from.js +0 -13
  28. package/dist/cjs/arr/from.js.map +0 -1
  29. package/dist/cjs/arr/group.d.ts +0 -1
  30. package/dist/cjs/arr/group.js +0 -16
  31. package/dist/cjs/arr/group.js.map +0 -1
  32. package/dist/cjs/arr/groupBy.d.ts +0 -1
  33. package/dist/cjs/arr/groupBy.js +0 -9
  34. package/dist/cjs/arr/groupBy.js.map +0 -1
  35. package/dist/cjs/arr/index.d.ts +0 -17
  36. package/dist/cjs/arr/index.js +0 -34
  37. package/dist/cjs/arr/index.js.map +0 -1
  38. package/dist/cjs/arr/max.d.ts +0 -1
  39. package/dist/cjs/arr/max.js +0 -15
  40. package/dist/cjs/arr/max.js.map +0 -1
  41. package/dist/cjs/arr/min.d.ts +0 -1
  42. package/dist/cjs/arr/min.js +0 -9
  43. package/dist/cjs/arr/min.js.map +0 -1
  44. package/dist/cjs/arr/range.d.ts +0 -1
  45. package/dist/cjs/arr/range.js +0 -13
  46. package/dist/cjs/arr/range.js.map +0 -1
  47. package/dist/cjs/arr/sort.d.ts +0 -1
  48. package/dist/cjs/arr/sort.js +0 -21
  49. package/dist/cjs/arr/sort.js.map +0 -1
  50. package/dist/cjs/arr/transpose.d.ts +0 -2
  51. package/dist/cjs/arr/transpose.js +0 -12
  52. package/dist/cjs/arr/transpose.js.map +0 -1
  53. package/dist/cjs/arr/types.d.ts +0 -11
  54. package/dist/cjs/arr/types.js +0 -3
  55. package/dist/cjs/arr/types.js.map +0 -1
  56. package/dist/cjs/arr/union.d.ts +0 -1
  57. package/dist/cjs/arr/union.js +0 -8
  58. package/dist/cjs/arr/union.js.map +0 -1
  59. package/dist/cjs/arr/unique.d.ts +0 -2
  60. package/dist/cjs/arr/unique.js +0 -10
  61. package/dist/cjs/arr/unique.js.map +0 -1
  62. package/dist/cjs/arr/zip.d.ts +0 -1
  63. package/dist/cjs/arr/zip.js +0 -7
  64. package/dist/cjs/arr/zip.js.map +0 -1
  65. package/dist/cjs/func/apply.d.ts +0 -1
  66. package/dist/cjs/func/apply.js +0 -8
  67. package/dist/cjs/func/apply.js.map +0 -1
  68. package/dist/cjs/func/curry.d.ts +0 -2
  69. package/dist/cjs/func/curry.js +0 -17
  70. package/dist/cjs/func/curry.js.map +0 -1
  71. package/dist/cjs/func/debounce.d.ts +0 -1
  72. package/dist/cjs/func/debounce.js +0 -15
  73. package/dist/cjs/func/debounce.js.map +0 -1
  74. package/dist/cjs/func/index.d.ts +0 -6
  75. package/dist/cjs/func/index.js +0 -23
  76. package/dist/cjs/func/index.js.map +0 -1
  77. package/dist/cjs/func/memo.d.ts +0 -2
  78. package/dist/cjs/func/memo.js +0 -22
  79. package/dist/cjs/func/memo.js.map +0 -1
  80. package/dist/cjs/func/throttle.d.ts +0 -1
  81. package/dist/cjs/func/throttle.js +0 -19
  82. package/dist/cjs/func/throttle.js.map +0 -1
  83. package/dist/cjs/func/types.d.ts +0 -8
  84. package/dist/cjs/func/types.js +0 -3
  85. package/dist/cjs/func/types.js.map +0 -1
  86. package/dist/cjs/func/unapply.d.ts +0 -1
  87. package/dist/cjs/func/unapply.js +0 -8
  88. package/dist/cjs/func/unapply.js.map +0 -1
  89. package/dist/cjs/index.d.ts +0 -13
  90. package/dist/cjs/index.js +0 -43
  91. package/dist/cjs/index.js.map +0 -1
  92. package/dist/cjs/math/add.d.ts +0 -1
  93. package/dist/cjs/math/add.js +0 -8
  94. package/dist/cjs/math/add.js.map +0 -1
  95. package/dist/cjs/math/aprox.d.ts +0 -1
  96. package/dist/cjs/math/aprox.js +0 -9
  97. package/dist/cjs/math/aprox.js.map +0 -1
  98. package/dist/cjs/math/calc.d.ts +0 -5
  99. package/dist/cjs/math/calc.js +0 -23
  100. package/dist/cjs/math/calc.js.map +0 -1
  101. package/dist/cjs/math/cumsum.d.ts +0 -1
  102. package/dist/cjs/math/cumsum.js +0 -13
  103. package/dist/cjs/math/cumsum.js.map +0 -1
  104. package/dist/cjs/math/divide.d.ts +0 -1
  105. package/dist/cjs/math/divide.js +0 -6
  106. package/dist/cjs/math/divide.js.map +0 -1
  107. package/dist/cjs/math/inRange.d.ts +0 -1
  108. package/dist/cjs/math/inRange.js +0 -11
  109. package/dist/cjs/math/inRange.js.map +0 -1
  110. package/dist/cjs/math/index.d.ts +0 -16
  111. package/dist/cjs/math/index.js +0 -33
  112. package/dist/cjs/math/index.js.map +0 -1
  113. package/dist/cjs/math/interp.d.ts +0 -1
  114. package/dist/cjs/math/interp.js +0 -22
  115. package/dist/cjs/math/interp.js.map +0 -1
  116. package/dist/cjs/math/mean.d.ts +0 -1
  117. package/dist/cjs/math/mean.js +0 -16
  118. package/dist/cjs/math/mean.js.map +0 -1
  119. package/dist/cjs/math/median.d.ts +0 -1
  120. package/dist/cjs/math/median.js +0 -9
  121. package/dist/cjs/math/median.js.map +0 -1
  122. package/dist/cjs/math/mod.d.ts +0 -1
  123. package/dist/cjs/math/mod.js +0 -8
  124. package/dist/cjs/math/mod.js.map +0 -1
  125. package/dist/cjs/math/multiply.d.ts +0 -1
  126. package/dist/cjs/math/multiply.js +0 -7
  127. package/dist/cjs/math/multiply.js.map +0 -1
  128. package/dist/cjs/math/percentile.d.ts +0 -2
  129. package/dist/cjs/math/percentile.js +0 -49
  130. package/dist/cjs/math/percentile.js.map +0 -1
  131. package/dist/cjs/math/pow.d.ts +0 -1
  132. package/dist/cjs/math/pow.js +0 -8
  133. package/dist/cjs/math/pow.js.map +0 -1
  134. package/dist/cjs/math/round.d.ts +0 -2
  135. package/dist/cjs/math/round.js +0 -15
  136. package/dist/cjs/math/round.js.map +0 -1
  137. package/dist/cjs/math/subtract.d.ts +0 -1
  138. package/dist/cjs/math/subtract.js +0 -6
  139. package/dist/cjs/math/subtract.js.map +0 -1
  140. package/dist/cjs/math/sum.d.ts +0 -1
  141. package/dist/cjs/math/sum.js +0 -8
  142. package/dist/cjs/math/sum.js.map +0 -1
  143. package/dist/cjs/math/types.d.ts +0 -4
  144. package/dist/cjs/math/types.js +0 -3
  145. package/dist/cjs/math/types.js.map +0 -1
  146. package/dist/cjs/obj/copy.d.ts +0 -1
  147. package/dist/cjs/obj/copy.js +0 -16
  148. package/dist/cjs/obj/copy.js.map +0 -1
  149. package/dist/cjs/obj/entries.d.ts +0 -2
  150. package/dist/cjs/obj/entries.js +0 -5
  151. package/dist/cjs/obj/entries.js.map +0 -1
  152. package/dist/cjs/obj/equal.d.ts +0 -1
  153. package/dist/cjs/obj/equal.js +0 -30
  154. package/dist/cjs/obj/equal.js.map +0 -1
  155. package/dist/cjs/obj/get.d.ts +0 -1
  156. package/dist/cjs/obj/get.js +0 -19
  157. package/dist/cjs/obj/get.js.map +0 -1
  158. package/dist/cjs/obj/has.d.ts +0 -1
  159. package/dist/cjs/obj/has.js +0 -8
  160. package/dist/cjs/obj/has.js.map +0 -1
  161. package/dist/cjs/obj/index.d.ts +0 -11
  162. package/dist/cjs/obj/index.js +0 -28
  163. package/dist/cjs/obj/index.js.map +0 -1
  164. package/dist/cjs/obj/isObj.d.ts +0 -1
  165. package/dist/cjs/obj/isObj.js +0 -8
  166. package/dist/cjs/obj/isObj.js.map +0 -1
  167. package/dist/cjs/obj/keys.d.ts +0 -2
  168. package/dist/cjs/obj/keys.js +0 -5
  169. package/dist/cjs/obj/keys.js.map +0 -1
  170. package/dist/cjs/obj/merge.d.ts +0 -1
  171. package/dist/cjs/obj/merge.js +0 -9
  172. package/dist/cjs/obj/merge.js.map +0 -1
  173. package/dist/cjs/obj/omit.d.ts +0 -1
  174. package/dist/cjs/obj/omit.js +0 -13
  175. package/dist/cjs/obj/omit.js.map +0 -1
  176. package/dist/cjs/obj/pick.d.ts +0 -1
  177. package/dist/cjs/obj/pick.js +0 -13
  178. package/dist/cjs/obj/pick.js.map +0 -1
  179. package/dist/cjs/obj/types.d.ts +0 -4
  180. package/dist/cjs/obj/types.js +0 -3
  181. package/dist/cjs/obj/types.js.map +0 -1
  182. package/dist/cjs/obj/vals.d.ts +0 -2
  183. package/dist/cjs/obj/vals.js +0 -5
  184. package/dist/cjs/obj/vals.js.map +0 -1
  185. package/dist/cjs/time/index.d.ts +0 -16
  186. package/dist/cjs/time/index.js +0 -59
  187. package/dist/cjs/time/index.js.map +0 -1
  188. package/dist/cjs/time/types.d.ts +0 -4
  189. package/dist/cjs/time/types.js +0 -3
  190. package/dist/cjs/time/types.js.map +0 -1
  191. package/dist/cjs/types/index.d.ts +0 -1
  192. package/dist/cjs/types/index.js +0 -18
  193. package/dist/cjs/types/index.js.map +0 -1
  194. package/dist/cjs/types/primitives.d.ts +0 -4
  195. package/dist/cjs/types/primitives.js +0 -3
  196. package/dist/cjs/types/primitives.js.map +0 -1
  197. package/dist/esm/arr/chunk.d.ts +0 -1
  198. package/dist/esm/arr/chunk.js +0 -8
  199. package/dist/esm/arr/chunk.js.map +0 -1
  200. package/dist/esm/arr/fill.d.ts +0 -1
  201. package/dist/esm/arr/fill.js +0 -5
  202. package/dist/esm/arr/fill.js.map +0 -1
  203. package/dist/esm/arr/find.d.ts +0 -2
  204. package/dist/esm/arr/find.js +0 -5
  205. package/dist/esm/arr/find.js.map +0 -1
  206. package/dist/esm/arr/findAll.d.ts +0 -2
  207. package/dist/esm/arr/findAll.js +0 -5
  208. package/dist/esm/arr/findAll.js.map +0 -1
  209. package/dist/esm/arr/findAllIdx.d.ts +0 -2
  210. package/dist/esm/arr/findAllIdx.js +0 -13
  211. package/dist/esm/arr/findAllIdx.js.map +0 -1
  212. package/dist/esm/arr/findIdx.d.ts +0 -2
  213. package/dist/esm/arr/findIdx.js +0 -9
  214. package/dist/esm/arr/findIdx.js.map +0 -1
  215. package/dist/esm/arr/from.d.ts +0 -1
  216. package/dist/esm/arr/from.js +0 -9
  217. package/dist/esm/arr/from.js.map +0 -1
  218. package/dist/esm/arr/group.d.ts +0 -1
  219. package/dist/esm/arr/group.js +0 -12
  220. package/dist/esm/arr/group.js.map +0 -1
  221. package/dist/esm/arr/groupBy.d.ts +0 -1
  222. package/dist/esm/arr/groupBy.js +0 -5
  223. package/dist/esm/arr/groupBy.js.map +0 -1
  224. package/dist/esm/arr/index.d.ts +0 -17
  225. package/dist/esm/arr/index.js +0 -18
  226. package/dist/esm/arr/index.js.map +0 -1
  227. package/dist/esm/arr/max.d.ts +0 -1
  228. package/dist/esm/arr/max.js +0 -11
  229. package/dist/esm/arr/max.js.map +0 -1
  230. package/dist/esm/arr/min.d.ts +0 -1
  231. package/dist/esm/arr/min.js +0 -5
  232. package/dist/esm/arr/min.js.map +0 -1
  233. package/dist/esm/arr/range.d.ts +0 -1
  234. package/dist/esm/arr/range.js +0 -9
  235. package/dist/esm/arr/range.js.map +0 -1
  236. package/dist/esm/arr/sort.d.ts +0 -1
  237. package/dist/esm/arr/sort.js +0 -17
  238. package/dist/esm/arr/sort.js.map +0 -1
  239. package/dist/esm/arr/transpose.d.ts +0 -2
  240. package/dist/esm/arr/transpose.js +0 -8
  241. package/dist/esm/arr/transpose.js.map +0 -1
  242. package/dist/esm/arr/types.d.ts +0 -11
  243. package/dist/esm/arr/types.js +0 -2
  244. package/dist/esm/arr/types.js.map +0 -1
  245. package/dist/esm/arr/union.d.ts +0 -1
  246. package/dist/esm/arr/union.js +0 -5
  247. package/dist/esm/arr/union.js.map +0 -1
  248. package/dist/esm/arr/unique.d.ts +0 -2
  249. package/dist/esm/arr/unique.js +0 -6
  250. package/dist/esm/arr/unique.js.map +0 -1
  251. package/dist/esm/arr/zip.d.ts +0 -1
  252. package/dist/esm/arr/zip.js +0 -4
  253. package/dist/esm/arr/zip.js.map +0 -1
  254. package/dist/esm/func/apply.d.ts +0 -1
  255. package/dist/esm/func/apply.js +0 -4
  256. package/dist/esm/func/apply.js.map +0 -1
  257. package/dist/esm/func/curry.d.ts +0 -2
  258. package/dist/esm/func/curry.js +0 -13
  259. package/dist/esm/func/curry.js.map +0 -1
  260. package/dist/esm/func/debounce.d.ts +0 -1
  261. package/dist/esm/func/debounce.js +0 -11
  262. package/dist/esm/func/debounce.js.map +0 -1
  263. package/dist/esm/func/index.d.ts +0 -6
  264. package/dist/esm/func/index.js +0 -7
  265. package/dist/esm/func/index.js.map +0 -1
  266. package/dist/esm/func/memo.d.ts +0 -2
  267. package/dist/esm/func/memo.js +0 -18
  268. package/dist/esm/func/memo.js.map +0 -1
  269. package/dist/esm/func/throttle.d.ts +0 -1
  270. package/dist/esm/func/throttle.js +0 -15
  271. package/dist/esm/func/throttle.js.map +0 -1
  272. package/dist/esm/func/types.d.ts +0 -8
  273. package/dist/esm/func/types.js +0 -2
  274. package/dist/esm/func/types.js.map +0 -1
  275. package/dist/esm/func/unapply.d.ts +0 -1
  276. package/dist/esm/func/unapply.js +0 -4
  277. package/dist/esm/func/unapply.js.map +0 -1
  278. package/dist/esm/index.d.ts +0 -13
  279. package/dist/esm/index.js +0 -14
  280. package/dist/esm/index.js.map +0 -1
  281. package/dist/esm/math/add.d.ts +0 -1
  282. package/dist/esm/math/add.js +0 -5
  283. package/dist/esm/math/add.js.map +0 -1
  284. package/dist/esm/math/aprox.d.ts +0 -1
  285. package/dist/esm/math/aprox.js +0 -5
  286. package/dist/esm/math/aprox.js.map +0 -1
  287. package/dist/esm/math/calc.d.ts +0 -5
  288. package/dist/esm/math/calc.js +0 -19
  289. package/dist/esm/math/calc.js.map +0 -1
  290. package/dist/esm/math/cumsum.d.ts +0 -1
  291. package/dist/esm/math/cumsum.js +0 -9
  292. package/dist/esm/math/cumsum.js.map +0 -1
  293. package/dist/esm/math/divide.d.ts +0 -1
  294. package/dist/esm/math/divide.js +0 -3
  295. package/dist/esm/math/divide.js.map +0 -1
  296. package/dist/esm/math/inRange.d.ts +0 -1
  297. package/dist/esm/math/inRange.js +0 -7
  298. package/dist/esm/math/inRange.js.map +0 -1
  299. package/dist/esm/math/index.d.ts +0 -16
  300. package/dist/esm/math/index.js +0 -17
  301. package/dist/esm/math/index.js.map +0 -1
  302. package/dist/esm/math/interp.d.ts +0 -1
  303. package/dist/esm/math/interp.js +0 -18
  304. package/dist/esm/math/interp.js.map +0 -1
  305. package/dist/esm/math/mean.d.ts +0 -1
  306. package/dist/esm/math/mean.js +0 -12
  307. package/dist/esm/math/mean.js.map +0 -1
  308. package/dist/esm/math/median.d.ts +0 -1
  309. package/dist/esm/math/median.js +0 -5
  310. package/dist/esm/math/median.js.map +0 -1
  311. package/dist/esm/math/mod.d.ts +0 -1
  312. package/dist/esm/math/mod.js +0 -4
  313. package/dist/esm/math/mod.js.map +0 -1
  314. package/dist/esm/math/multiply.d.ts +0 -1
  315. package/dist/esm/math/multiply.js +0 -4
  316. package/dist/esm/math/multiply.js.map +0 -1
  317. package/dist/esm/math/percentile.d.ts +0 -2
  318. package/dist/esm/math/percentile.js +0 -45
  319. package/dist/esm/math/percentile.js.map +0 -1
  320. package/dist/esm/math/pow.d.ts +0 -1
  321. package/dist/esm/math/pow.js +0 -4
  322. package/dist/esm/math/pow.js.map +0 -1
  323. package/dist/esm/math/round.d.ts +0 -2
  324. package/dist/esm/math/round.js +0 -11
  325. package/dist/esm/math/round.js.map +0 -1
  326. package/dist/esm/math/subtract.d.ts +0 -1
  327. package/dist/esm/math/subtract.js +0 -3
  328. package/dist/esm/math/subtract.js.map +0 -1
  329. package/dist/esm/math/sum.d.ts +0 -1
  330. package/dist/esm/math/sum.js +0 -4
  331. package/dist/esm/math/sum.js.map +0 -1
  332. package/dist/esm/math/types.d.ts +0 -4
  333. package/dist/esm/math/types.js +0 -2
  334. package/dist/esm/math/types.js.map +0 -1
  335. package/dist/esm/obj/copy.d.ts +0 -1
  336. package/dist/esm/obj/copy.js +0 -12
  337. package/dist/esm/obj/copy.js.map +0 -1
  338. package/dist/esm/obj/entries.d.ts +0 -2
  339. package/dist/esm/obj/entries.js +0 -2
  340. package/dist/esm/obj/entries.js.map +0 -1
  341. package/dist/esm/obj/equal.d.ts +0 -1
  342. package/dist/esm/obj/equal.js +0 -27
  343. package/dist/esm/obj/equal.js.map +0 -1
  344. package/dist/esm/obj/get.d.ts +0 -1
  345. package/dist/esm/obj/get.js +0 -15
  346. package/dist/esm/obj/get.js.map +0 -1
  347. package/dist/esm/obj/has.d.ts +0 -1
  348. package/dist/esm/obj/has.js +0 -4
  349. package/dist/esm/obj/has.js.map +0 -1
  350. package/dist/esm/obj/index.d.ts +0 -11
  351. package/dist/esm/obj/index.js +0 -12
  352. package/dist/esm/obj/index.js.map +0 -1
  353. package/dist/esm/obj/isObj.d.ts +0 -1
  354. package/dist/esm/obj/isObj.js +0 -4
  355. package/dist/esm/obj/isObj.js.map +0 -1
  356. package/dist/esm/obj/keys.d.ts +0 -2
  357. package/dist/esm/obj/keys.js +0 -2
  358. package/dist/esm/obj/keys.js.map +0 -1
  359. package/dist/esm/obj/merge.d.ts +0 -1
  360. package/dist/esm/obj/merge.js +0 -5
  361. package/dist/esm/obj/merge.js.map +0 -1
  362. package/dist/esm/obj/omit.d.ts +0 -1
  363. package/dist/esm/obj/omit.js +0 -9
  364. package/dist/esm/obj/omit.js.map +0 -1
  365. package/dist/esm/obj/pick.d.ts +0 -1
  366. package/dist/esm/obj/pick.js +0 -9
  367. package/dist/esm/obj/pick.js.map +0 -1
  368. package/dist/esm/obj/types.d.ts +0 -4
  369. package/dist/esm/obj/types.js +0 -2
  370. package/dist/esm/obj/types.js.map +0 -1
  371. package/dist/esm/obj/vals.d.ts +0 -2
  372. package/dist/esm/obj/vals.js +0 -2
  373. package/dist/esm/obj/vals.js.map +0 -1
  374. package/dist/esm/time/index.d.ts +0 -16
  375. package/dist/esm/time/index.js +0 -55
  376. package/dist/esm/time/index.js.map +0 -1
  377. package/dist/esm/time/types.d.ts +0 -4
  378. package/dist/esm/time/types.js +0 -2
  379. package/dist/esm/time/types.js.map +0 -1
  380. package/dist/esm/types/index.d.ts +0 -1
  381. package/dist/esm/types/index.js +0 -2
  382. package/dist/esm/types/index.js.map +0 -1
  383. package/dist/esm/types/primitives.d.ts +0 -4
  384. package/dist/esm/types/primitives.js +0 -2
  385. package/dist/esm/types/primitives.js.map +0 -1
@@ -0,0 +1,1132 @@
1
+ /**
2
+ * Binary search for insertion index in a sorted array using a custom accessor
3
+ * @param arr Sorted array to search
4
+ * @param target Value to search for
5
+ * @param getVal Function to extract comparison value from each element
6
+ * @param start Start index (inclusive)
7
+ * @param end End index (exclusive)
8
+ * @returns Index to insert target to maintain order
9
+ */
10
+ const binSearch = (arr, target, getVal, start = 0, end = arr.length) => {
11
+ if (start < 0 || end > arr.length || start > end) {
12
+ throw new Error("Invalid start or end of search");
13
+ }
14
+ let a = start;
15
+ let b = end;
16
+ while (a < b) {
17
+ const mid = Math.floor((a + b) / 2);
18
+ const midVal = getVal(arr[mid]);
19
+ if (midVal < target) {
20
+ a = mid + 1;
21
+ }
22
+ else {
23
+ b = mid;
24
+ }
25
+ }
26
+ return a;
27
+ };
28
+
29
+ /**
30
+ * Creates an array of size `n`, filling each element using the map function
31
+ * @param n Size of the array to create
32
+ * @param mapFn Function that maps each index to an array element
33
+ * @returns Array of mapped values
34
+ */
35
+ const from = (n, mapFn) => {
36
+ const res = Array(n);
37
+ let i = n;
38
+ while (--i >= 0) {
39
+ res[i] = mapFn(i);
40
+ }
41
+ return res;
42
+ };
43
+
44
+ /**
45
+ * Creates an array of numbers from `a` up to `b` incremented by `step`
46
+ * @param a Start of the range (inclusive)
47
+ * @param b End of the range (exclusive)
48
+ * @param step Step between elements (default is 1)
49
+ * @returns Array of numbers in the specified range
50
+ */
51
+ const range = (a, b, step = 1) => {
52
+ if (step === 0) {
53
+ throw new Error("Step cannot be 0");
54
+ }
55
+ const n = Math.ceil((b - a) / step);
56
+ return from(n, (i) => a + step * i);
57
+ };
58
+
59
+ /**
60
+ * Splits an array into multiple chunks of a specified size
61
+ * @param arr Array to split
62
+ * @param size Size of each chunk
63
+ * @returns Array of chunks
64
+ */
65
+ const chunk = (arr, size) => {
66
+ if (!Number.isInteger(size)) {
67
+ throw new Error("Chunk size must be an integer");
68
+ }
69
+ return range(0, arr.length, size).map((i) => arr.slice(i, i + size));
70
+ };
71
+
72
+ /**
73
+ * Creates array of size `n` filled with the specified value
74
+ * @param n Array size
75
+ * @param val Value to fill the array with
76
+ * @returns Array containing `val` repeated `n` times
77
+ */
78
+ const fill = (n, val) => {
79
+ return from(n, () => val);
80
+ };
81
+
82
+ /**
83
+ * Finds the index of the first element that matches the given predicate
84
+ * @param arr Array to search
85
+ * @param predicate Function to test each element
86
+ * @param from Start index (inclusive). Default: 0
87
+ * @param to End index (exclusive). Default: arr.length
88
+ * @returns Index of the first matching element, or -1 if none found
89
+ */
90
+ const findIdx = (arr, predicate, from = 0, to = arr.length) => {
91
+ for (let i = from; i < to; i++) {
92
+ if (predicate(arr[i], i, arr)) {
93
+ return i;
94
+ }
95
+ }
96
+ return -1;
97
+ };
98
+
99
+ /**
100
+ * Finds the first element that matches the given predicate
101
+ * @param arr Array to search
102
+ * @param predicate Function to test each element
103
+ * @param from Start index (inclusive). Default: 0
104
+ * @param to End index (exclusive). Default: arr.length
105
+ * @returns First matching element, or undefined if none found
106
+ */
107
+ const find = (arr, predicate, from = 0, to = arr.length) => {
108
+ return arr[findIdx(arr, predicate, from, to)];
109
+ };
110
+
111
+ /**
112
+ * Finds indices of all elements that match the given predicate
113
+ * @param arr Array to search
114
+ * @param predicate Function to test each element
115
+ * @param from Start index (inclusive). Default: 0
116
+ * @param to End index (exclusive). Default: arr.length
117
+ * @param limit Maximum number of indices to return. Default: arr.length
118
+ * @returns Array of matching indices
119
+ */
120
+ const findAllIdx = (arr, predicate, from = 0, to = arr.length, limit = arr.length) => {
121
+ const res = [];
122
+ for (let i = from; i < to; i++) {
123
+ if (predicate(arr[i], i, arr)) {
124
+ res.push(i);
125
+ if (res.length >= limit) {
126
+ break;
127
+ }
128
+ }
129
+ }
130
+ return res;
131
+ };
132
+
133
+ /**
134
+ * Finds all elements that match the given predicate
135
+ * @param arr Array to search
136
+ * @param predicate Function to test each element
137
+ * @param from Start index (inclusive). Default: 0
138
+ * @param to End index (exclusive). Default: arr.length
139
+ * @param limit Maximum number of matches to return. Default: arr.length
140
+ * @returns Array of matching elements
141
+ */
142
+ const findAll = (arr, predicate, from = 0, to = arr.length, limit = arr.length) => {
143
+ return findAllIdx(arr, predicate, from, to, limit).map((i) => arr[i]);
144
+ };
145
+
146
+ /**
147
+ * Groups array items into an object by a key
148
+ * @param arr Array to group
149
+ * @param getKey Function to extract the group key from each item
150
+ * @returns Object with keys as group ids and values as arrays of grouped items
151
+ */
152
+ const group = (arr, getKey) => {
153
+ const res = {};
154
+ arr.forEach((el) => {
155
+ const val = getKey(el);
156
+ if (res[val] === undefined) {
157
+ res[val] = [];
158
+ }
159
+ res[val].push(el);
160
+ });
161
+ return res;
162
+ };
163
+
164
+ /**
165
+ * @deprecated Use `group` instead
166
+ */
167
+ const groupBy = (arr, key) => {
168
+ return group(arr, (obj) => obj[key]);
169
+ };
170
+
171
+ /**
172
+ * Returns the element with the maximum value based on the provided map function
173
+ * @param arr Array to search
174
+ * @param fn Function to extract the value for comparison
175
+ * @returns Element with the maximum value
176
+ */
177
+ const max = (arr, fn) => {
178
+ const scores = arr.map(fn);
179
+ let maxIdx = 0;
180
+ for (let i = 1; i < scores.length; i++) {
181
+ if (scores[i] > scores[maxIdx]) {
182
+ maxIdx = i;
183
+ }
184
+ }
185
+ return arr[maxIdx];
186
+ };
187
+
188
+ /**
189
+ * Returns the element with the minimum value based on the provided map function
190
+ * @param arr Array to search
191
+ * @param fn Function to extract the value for comparison
192
+ * @returns Element with the minimum value
193
+ */
194
+ const min = (arr, fn) => {
195
+ return max(arr, (val) => -fn(val));
196
+ };
197
+
198
+ /**
199
+ * Sorts an array in-place based on a mapping function
200
+ * @param arr Array to sort
201
+ * @param mapFn Function to map each element to a sortable value
202
+ * @returns Sorted array in-place
203
+ */
204
+ const sort = (arr, mapFn) => {
205
+ const mapped = arr.map((el) => [mapFn(el), el]);
206
+ mapped.sort(([a], [b]) => {
207
+ if (a < b) {
208
+ return -1;
209
+ }
210
+ if (a > b) {
211
+ return 1;
212
+ }
213
+ return 0;
214
+ });
215
+ mapped.forEach(([, el], i) => {
216
+ arr[i] = el;
217
+ });
218
+ return arr;
219
+ };
220
+
221
+ /**
222
+ * Transposes a 2D array (matrix), switching its rows and columns
223
+ * @param matrix The 2D array to transpose
224
+ * @returns Transposed matrix
225
+ */
226
+ const transpose = (matrix) => {
227
+ const rows = matrix.length;
228
+ const cols = matrix[0].length;
229
+ if (matrix.some((row) => row.length !== cols)) {
230
+ throw new Error("Invalid matrix. Rows have different size");
231
+ }
232
+ const res = from(cols, (i) => from(rows, (j) => matrix[j][i]));
233
+ return res;
234
+ };
235
+
236
+ /**
237
+ * Creates a set containing unique values from all provided arrays
238
+ * @param arrs Arrays to union
239
+ * @returns Set of unique values
240
+ */
241
+ const union = (...arrs) => {
242
+ return new Set(arrs.flat(1));
243
+ };
244
+
245
+ /**
246
+ * Creates array of unique values from the input array, preserving their order
247
+ * @param arr Array of primitive values
248
+ * @returns Array of unique values
249
+ */
250
+ const unique = (arr) => {
251
+ const set = Array.from(new Set(arr));
252
+ return sort(set, (el) => arr.indexOf(el));
253
+ };
254
+
255
+ /**
256
+ * Transforms a function with array argument into one with spread arguments
257
+ * @param fn Function accepting an array of arguments
258
+ * @returns Function accepting spread arguments
259
+ */
260
+ const unapply = (fn) => {
261
+ return (...args) => fn(args);
262
+ };
263
+
264
+ /**
265
+ * Creates an array of grouped elements, where each group contains the elements
266
+ * at the corresponding index from the input arrays
267
+ * @param arrays Arrays to process
268
+ * @returns Array of grouped elements
269
+ */
270
+ const zip = unapply(transpose);
271
+
272
+ const index$5 = /*#__PURE__*/Object.freeze({
273
+ __proto__: null,
274
+ binSearch: binSearch,
275
+ chunk: chunk,
276
+ fill: fill,
277
+ find: find,
278
+ findAll: findAll,
279
+ findAllIdx: findAllIdx,
280
+ findIdx: findIdx,
281
+ from: from,
282
+ group: group,
283
+ groupBy: groupBy,
284
+ max: max,
285
+ min: min,
286
+ range: range,
287
+ sort: sort,
288
+ transpose: transpose,
289
+ union: union,
290
+ unique: unique,
291
+ zip: zip
292
+ });
293
+
294
+ /**
295
+ * Transforms a function with spread arguments into one with array argument
296
+ * @param fn Function accepting spread arguments
297
+ * @returns Function accepting an array of arguments
298
+ */
299
+ const apply = (fn) => {
300
+ return (arg) => fn.apply(undefined, arg);
301
+ };
302
+
303
+ /**
304
+ * Creates a curried version of a function, allowing partial application of arguments
305
+ * @param fn Function to curry
306
+ * @param arity Number of arguments the function expects. Default: fn.length
307
+ * @returns Curried function
308
+ */
309
+ const curry = (fn, arity = fn.length) => {
310
+ return (...args) => {
311
+ const missing = arity - args.length;
312
+ if (missing <= 0) {
313
+ return fn.apply(undefined, args);
314
+ }
315
+ return curry((...rArgs) => {
316
+ return fn.apply(undefined, args.concat(rArgs));
317
+ }, missing);
318
+ };
319
+ };
320
+
321
+ /**
322
+ * Creates a debounced version of a function that delays invoking until after the specified delay.
323
+ * Only the last call within the delay period is executed
324
+ * @param fn Function to debounce
325
+ * @param delay Delay in milliseconds. Default: 100
326
+ * @returns Debounced function
327
+ */
328
+ const debounce = (fn, delay = 100) => {
329
+ let timer;
330
+ return (...args) => {
331
+ clearTimeout(timer);
332
+ timer = setTimeout(() => {
333
+ fn.apply(undefined, args);
334
+ }, delay);
335
+ };
336
+ };
337
+
338
+ /**
339
+ * Returns the input value unchanged
340
+ * @param value Value to return
341
+ * @returns Same value provided as input
342
+ */
343
+ const identity = (x) => x;
344
+
345
+ /**
346
+ * Creates a memoized version of a function, caching its output for faster repeated calls.
347
+ * Optionally accepts a custom cache key generator and a TTL (time-to-live) in milliseconds
348
+ * @param fn Function to memoize
349
+ * @param idFn Function to generate a cache key from arguments. Default: JSON.stringify
350
+ * @param ttl Optional cache expiration time in milliseconds. Default: 0 (no expiration)
351
+ * @returns Memoized function
352
+ */
353
+ const memo = (fn, idFn = JSON.stringify, ttl = 0) => {
354
+ const cache = new Map();
355
+ return (...args) => {
356
+ const key = idFn(args);
357
+ const cached = cache.get(key);
358
+ if (cached !== undefined) {
359
+ if (cached.exp === undefined || Date.now() < cached.exp) {
360
+ return cached.val;
361
+ }
362
+ }
363
+ const val = fn.apply(undefined, args);
364
+ const exp = ttl <= 0 ? undefined : Date.now() + ttl;
365
+ cache.set(key, { exp, val });
366
+ return val;
367
+ };
368
+ };
369
+
370
+ /**
371
+ * Ensures the provided function is executed only once
372
+ * Subsequent calls return the result of the first execution
373
+ * @param fn Function to execute only once
374
+ * @returns Function that invokes `fn` only once
375
+ */
376
+ const once = (fn) => {
377
+ let call = true;
378
+ let res;
379
+ return () => {
380
+ if (call) {
381
+ res = fn();
382
+ call = false;
383
+ }
384
+ return res;
385
+ };
386
+ };
387
+
388
+ /**
389
+ * Creates a function by composing multiple unary functions from left to right.
390
+ * The output of each function is passed as the input to the next
391
+ * @param fns Sequence of unary functions to compose
392
+ * @returns Composed function from left to right
393
+ */
394
+ const pipe = (...fns) => {
395
+ return ((input) => {
396
+ return fns.reduce((acc, fn) => fn(acc), input);
397
+ });
398
+ };
399
+
400
+ /**
401
+ * Creates a throttled version of the given function that only executes once per specified interval
402
+ * @param fn Function to throttle
403
+ * @param interval Minimum time (ms) between calls. Default: 100
404
+ * @returns Throttled function
405
+ */
406
+ const throttle = (fn, interval = 100) => {
407
+ let wait = false;
408
+ return (...args) => {
409
+ if (wait) {
410
+ return;
411
+ }
412
+ wait = true;
413
+ fn.apply(undefined, args);
414
+ setTimeout(() => {
415
+ wait = false;
416
+ }, interval);
417
+ };
418
+ };
419
+
420
+ const index$4 = /*#__PURE__*/Object.freeze({
421
+ __proto__: null,
422
+ apply: apply,
423
+ curry: curry,
424
+ debounce: debounce,
425
+ identity: identity,
426
+ memo: memo,
427
+ once: once,
428
+ pipe: pipe,
429
+ throttle: throttle,
430
+ unapply: unapply
431
+ });
432
+
433
+ /**
434
+ * Creates a function that applies the given operation to any combination of scalars and vectors
435
+ * @template T Tuple or array of numbers for the operation
436
+ * @param opFn Operation function to apply to the inputs
437
+ * @returns Function that takes quantities (scalars or vectors) and returns the calculated result
438
+ * @example
439
+ * const fn = calc((a, b, c) => a * b + c);
440
+ * fn([1, 2], 3, 4); // [7, 10]
441
+ */
442
+ const calc = (opFn) => {
443
+ return (...arr) => {
444
+ const vectors = arr.filter((el) => typeof el !== "number");
445
+ if (vectors.length === 0) {
446
+ return opFn.apply(undefined, arr);
447
+ }
448
+ const size = vectors[0].length;
449
+ if (vectors.some((v) => v.length !== size)) {
450
+ throw new Error("All vectors must have same length");
451
+ }
452
+ return from(size, (i) => {
453
+ const input = arr.map((el) => (typeof el === "number" ? el : el[i]));
454
+ return opFn.apply(undefined, input);
455
+ });
456
+ };
457
+ };
458
+
459
+ /**
460
+ * Calculates the sum of given quantities (vectors or scalars)
461
+ * @param q Quantities to add
462
+ * @returns Sum of the input quantities
463
+ * @example
464
+ * add([-4, 1, 0, 3], 5); // [1, 6, 5, 8]
465
+ * add([1, 2], [3, 4]); // [4, 6]
466
+ */
467
+ const add = calc((...arr) => arr.reduce((acc, el) => acc + el, 0));
468
+
469
+ const _round = (n, p) => {
470
+ const k = Math.pow(10, p);
471
+ return Math.round(n * k) / k;
472
+ };
473
+ /**
474
+ * Rounds a quantity (vector or scalar) to the specified number of decimal places
475
+ * @param q Quantity to round
476
+ * @param precision Number of decimal places to round to. Default: 0
477
+ * @returns Rounded quantity
478
+ */
479
+ const round = (q, precision = 0) => {
480
+ if (typeof q === "number") {
481
+ return _round(q, precision);
482
+ }
483
+ return q.map((el) => _round(el, precision));
484
+ };
485
+
486
+ /**
487
+ * Compares if two numbers are approximately equal using a custom precision
488
+ * @param a First number to compare
489
+ * @param b Second number to compare
490
+ * @param precision Number of decimal places to consider. Default: 4
491
+ * @returns True if numbers are approximately equal, false otherwise
492
+ */
493
+ const aprox = (a, b, precision = 4) => {
494
+ return round(a, precision) === round(b, precision);
495
+ };
496
+
497
+ /**
498
+ * Calculates the cumulative sum of an array of numbers
499
+ * @param arr Array of numbers to sum
500
+ * @returns Array of cumulative sums
501
+ */
502
+ const cumsum = (arr) => {
503
+ const res = Array(arr.length);
504
+ res[0] = arr[0];
505
+ for (let i = 1; i < arr.length; i++) {
506
+ res[i] = res[i - 1] + arr[i];
507
+ }
508
+ return res;
509
+ };
510
+
511
+ /**
512
+ * Calculates the division of two quantities (vectors or scalars)
513
+ * @param a Dividend(s)
514
+ * @param b Divisor(s)
515
+ * @returns Division of the input quantities
516
+ * @example
517
+ * divide([-4, 1, 0, 3], 2); // [-2, 0.5, 0, 1.5]
518
+ * divide([1, 2], [3, 4]); // [1 / 3, 0.5]
519
+ */
520
+ const divide = calc((a, b) => a / b);
521
+
522
+ /**
523
+ * Calculates the linear interpolation of monotonic increasing points (xp, fp) at given x values
524
+ * @param x Points to interpolate
525
+ * @param xp Known x-coordinates (must be increasing)
526
+ * @param fp Known y-coordinates (must be increasing, same length as xp)
527
+ * @returns Interpolated values at each x
528
+ */
529
+ const interp = (x, xp, fp) => {
530
+ if (xp.length !== fp.length) {
531
+ throw new Error("xp and fp must have the same length");
532
+ }
533
+ return x.map((xi) => {
534
+ if (xi >= xp[xp.length - 1]) {
535
+ return fp[fp.length - 1];
536
+ }
537
+ const i = binSearch(xp, xi, (el) => el);
538
+ if (i === 0) {
539
+ return fp[0];
540
+ }
541
+ const slope = (fp[i] - fp[i - 1]) / (xp[i] - xp[i - 1]);
542
+ return fp[i - 1] + slope * (xi - xp[i - 1]);
543
+ });
544
+ };
545
+
546
+ /**
547
+ * Checks if a number is within a half-open range [a, b)
548
+ * @param n The number to check
549
+ * @param a Start of the range
550
+ * @param b End of the range. Default: 0
551
+ * @returns True if n is in [a, b), false otherwise
552
+ */
553
+ const inRange = (n, a, b = 0) => {
554
+ if (a > b) {
555
+ return inRange(n, b, a);
556
+ }
557
+ return n >= a && n < b;
558
+ };
559
+
560
+ /**
561
+ * Calculates the multiplication of given quantities (vectors or scalars)
562
+ * @param q Quantities to multiply
563
+ * @returns Product of the input quantities
564
+ * @example
565
+ * multiply([-4, 1, 0, 3], 3); // => [-12, 3, 0, 9]
566
+ * multiply([1, 2], [3, 4]); // => [3, 8]
567
+ */
568
+ const multiply = calc((...arr) => arr.reduce((acc, el) => acc * el, 1));
569
+
570
+ /**
571
+ * Calculates the sum of an array of numbers
572
+ * @param arr Numbers to sum
573
+ * @returns Sum of all numbers in the array
574
+ */
575
+ const sum = (arr) => {
576
+ return arr.reduce((acc, el) => acc + el, 0);
577
+ };
578
+
579
+ /**
580
+ * Calculates the mean (average) of an array of numbers. Supports optional weighted mean
581
+ * @param arr Array of numbers
582
+ * @param weights Optional array of weights
583
+ * @returns Mean of the numbers
584
+ */
585
+ const mean = (arr, weights) => {
586
+ if (weights === undefined) {
587
+ return sum(arr) / arr.length;
588
+ }
589
+ if (arr.length !== weights.length) {
590
+ throw new Error("Nums and weights must have the same length");
591
+ }
592
+ return sum(multiply(arr, weights)) / sum(weights);
593
+ };
594
+
595
+ const _linear = (x, p) => {
596
+ const Pnorm = divide(p, 100);
597
+ const step = 1 / (x.length - 1);
598
+ const xp = range(0, 1 + step, step);
599
+ return interp(Pnorm, xp, x.sort());
600
+ };
601
+ const _weighted = (x, p, w) => {
602
+ if (w.length !== x.length) {
603
+ throw new Error("Weights must be the same length as the array");
604
+ }
605
+ else if (w.some((v) => v < 0)) {
606
+ throw new Error("Weights must be non-negative");
607
+ }
608
+ const X = sort(transpose([x, w]), (el) => el[0]);
609
+ const [Xsorted, Wsorted] = transpose(X);
610
+ const Wcum = cumsum(Wsorted);
611
+ const Wtotal = Wcum[Wcum.length - 1];
612
+ const Wnorm = divide(Wcum, Wtotal);
613
+ const Pnorm = divide(p, 100);
614
+ let i = 0;
615
+ return Pnorm.map((pi) => {
616
+ i = binSearch(Wnorm, pi, (el) => el, i);
617
+ return Xsorted[i];
618
+ });
619
+ };
620
+ /**
621
+ * Calculates the given percentile(s) of an array of numbers
622
+ * Supports both linear interpolation and weighted percentiles
623
+ * @param x Array of numbers
624
+ * @param p Percentile(s) to compute (number or array of numbers, 0–100)
625
+ * @param weights Optional array of weights (same length as x)
626
+ * @returns Computed percentile value(s)
627
+ */
628
+ const percentile = (x, p, weights) => {
629
+ if (typeof p === "number") {
630
+ return percentile(x, [p], weights)[0];
631
+ }
632
+ if (p.some((v) => v < 0 || v > 100)) {
633
+ throw new Error("Percentiles must be between 0 and 100");
634
+ }
635
+ if (weights === undefined) {
636
+ return _linear(x, p);
637
+ }
638
+ return _weighted(x, p, weights);
639
+ };
640
+
641
+ /**
642
+ * Calculates the median of an array of numbers
643
+ * @param arr Array of numbers
644
+ * @param weights Optional array of weights
645
+ * @returns Median value
646
+ */
647
+ const median = (arr, weights) => {
648
+ return percentile(arr, 50, weights);
649
+ };
650
+
651
+ /**
652
+ * Calculates the modulo of two quantities (vectors or scalars)
653
+ * @param x Dividend(s)
654
+ * @param modulo Divisor(s)
655
+ * @returns Modulo, matching the input shape
656
+ * @example
657
+ * mod(5, 3); // 2
658
+ * mod([2, 3, 4], 3); // [2, 0, 1]
659
+ * mod([4, 5], [2, 3]); // [0, 2]
660
+ */
661
+ const mod = calc((x, modulo) => {
662
+ const m = Math.abs(modulo);
663
+ return ((x % m) + m) % m;
664
+ });
665
+
666
+ /**
667
+ * Calculates the exponentiation of two quantities (vectors or scalars)
668
+ * @param base Base quantity
669
+ * @param exp Exponent quantity
670
+ * @returns base raised to the power of exp
671
+ */
672
+ const pow = calc((base, exp) => Math.pow(base, exp));
673
+
674
+ /**
675
+ * Calculates the subtraction of two quantities (vectors or scalars)
676
+ * @param a Minuend quantity
677
+ * @param b Subtrahend quantity
678
+ * @returns Subtraction of `b` from `a`
679
+ */
680
+ const subtract = calc((a, b) => a - b);
681
+
682
+ const index$3 = /*#__PURE__*/Object.freeze({
683
+ __proto__: null,
684
+ add: add,
685
+ aprox: aprox,
686
+ calc: calc,
687
+ cumsum: cumsum,
688
+ divide: divide,
689
+ inRange: inRange,
690
+ interp: interp,
691
+ mean: mean,
692
+ median: median,
693
+ mod: mod,
694
+ multiply: multiply,
695
+ percentile: percentile,
696
+ pow: pow,
697
+ round: round,
698
+ subtract: subtract,
699
+ sum: sum
700
+ });
701
+
702
+ /**
703
+ * Retrieves a strongly-typed array of the entries (key, value) of an object
704
+ * @param obj Object whose entries are to be retrieved
705
+ * @returns Array of key-value pairs from the object
706
+ */
707
+ const entries = Object.entries;
708
+
709
+ /**
710
+ * Checks if the provided value is a non-null object
711
+ * @param el Value to check
712
+ * @returns True if `el` is a non-null object, otherwise false
713
+ */
714
+ const isObj = (el) => {
715
+ return typeof el === "object" && el !== null;
716
+ };
717
+
718
+ /**
719
+ * Creates a deep copy of the provided object or array
720
+ * @param obj Object or array to copy
721
+ * @returns Deep copy of the input
722
+ */
723
+ const copy = (obj) => {
724
+ if (!isObj(obj)) {
725
+ return obj;
726
+ }
727
+ const res = (Array.isArray(obj) ? [] : {});
728
+ entries(obj).forEach(([key, val]) => {
729
+ res[key] = copy(val);
730
+ });
731
+ return res;
732
+ };
733
+
734
+ /**
735
+ * Retrieves a strongly-typed array of the keys of an object
736
+ * @param obj Object whose keys are to be retrieved
737
+ * @returns Array of the object's keys
738
+ */
739
+ const keys = Object.keys;
740
+
741
+ const deepEqual = (args) => {
742
+ if (args.every((arg) => arg === args[0])) {
743
+ return true;
744
+ }
745
+ if (!args.every(isObj)) {
746
+ return false;
747
+ }
748
+ const objs = args;
749
+ const objsKeys = objs.map(keys);
750
+ if (!deepEqual(objsKeys.map((key) => key.length))) {
751
+ return false;
752
+ }
753
+ const keysUnion = union.apply(undefined, objsKeys);
754
+ if (keysUnion.size !== objsKeys[0].length) {
755
+ return false;
756
+ }
757
+ return objsKeys[0].every((key) => {
758
+ const vals = objs.map((obj) => obj[key]);
759
+ return deepEqual(vals);
760
+ });
761
+ };
762
+ /**
763
+ * Performs a deep comparison between multiple objects to determine if they are equal
764
+ * @param objs Objects to compare
765
+ * @returns True if all objects are deeply equal, false otherwise
766
+ */
767
+ const equal = unapply(deepEqual);
768
+
769
+ /**
770
+ * Checks if an object has all specified properties
771
+ * @param obj Object to check
772
+ * @param keys Property keys to look for
773
+ * @returns True if all keys exist on the object, false otherwise
774
+ */
775
+ const has = (obj, ...keys) => {
776
+ return keys.every((key) => Object.prototype.hasOwnProperty.call(obj, key));
777
+ };
778
+
779
+ /**
780
+ * Gets a value at a nested path of an object or array
781
+ * @param obj Source object
782
+ * @param path Dot-separated path string
783
+ * @param fallback Value to return if the path is not found
784
+ * @returns Value at the specified path or the fallback
785
+ */
786
+ const get = (obj, path, fallback) => {
787
+ let val = obj;
788
+ for (const key of path.split(".")) {
789
+ if (isObj(val) && has(val, key)) {
790
+ val = val[key];
791
+ }
792
+ else {
793
+ return fallback;
794
+ }
795
+ }
796
+ return val;
797
+ };
798
+
799
+ /**
800
+ * Creates a strongly-typed object from the shallow merge of deep copies of two objects
801
+ * If both objects have the same property, the value from the second object overwrites the first
802
+ * @param a First object to merge
803
+ * @param b Second object to merge
804
+ * @returns The merged object with properties from both a and b
805
+ */
806
+ const merge = (a, b) => {
807
+ return Object.assign(copy(a), copy(b));
808
+ };
809
+
810
+ /**
811
+ * Creates a deep copy of an object without the specified keys
812
+ * @param obj Source object
813
+ * @param keys Array of keys to omit from the result
814
+ * @returns New object without the specified keys
815
+ */
816
+ const omit = (obj, keys) => {
817
+ const newObj = copy(obj);
818
+ for (const key of keys) {
819
+ delete newObj[key];
820
+ }
821
+ return newObj;
822
+ };
823
+
824
+ /**
825
+ * Creates a deep copy of an object with only the specified keys
826
+ * @param obj Source object
827
+ * @param keys Array of keys to pick from the object
828
+ * @returns New object with only the picked keys
829
+ */
830
+ const pick = (obj, keys) => {
831
+ const res = {};
832
+ for (const key of keys) {
833
+ res[key] = copy(obj[key]);
834
+ }
835
+ return res;
836
+ };
837
+
838
+ /**
839
+ * Sets a value at a nested path of an object, creating nested objects if needed
840
+ * @param obj Target object to modify
841
+ * @param path Dot-separated string path where the value should be set
842
+ * @param value Value to set at the specified path
843
+ * @returns Modified object with the value set at the given path
844
+ */
845
+ const set = (obj, path, value) => {
846
+ let val = obj;
847
+ const keys = path.split(".");
848
+ const end = keys.length - 1;
849
+ for (let i = 0; i < end; i++) {
850
+ const key = keys[i];
851
+ if (!isObj(val[key])) {
852
+ val[key] = {};
853
+ }
854
+ val = val[key];
855
+ }
856
+ val[keys[end]] = value;
857
+ return obj;
858
+ };
859
+
860
+ /**
861
+ * Retrieves a strongly-typed array of the values of an object
862
+ * @param obj Source object
863
+ * @returns Array of the object's values
864
+ */
865
+ const vals = Object.values;
866
+
867
+ const index$2 = /*#__PURE__*/Object.freeze({
868
+ __proto__: null,
869
+ copy: copy,
870
+ entries: entries,
871
+ equal: equal,
872
+ get: get,
873
+ has: has,
874
+ isObj: isObj,
875
+ keys: keys,
876
+ merge: merge,
877
+ omit: omit,
878
+ pick: pick,
879
+ set: set,
880
+ vals: vals
881
+ });
882
+
883
+ /**
884
+ * Returns a random integer between two numbers
885
+ * @param a Lower bound (inclusive)
886
+ * @param b Upper bound (exclusive). Default: 0
887
+ * @returns Random integer between a and b
888
+ */
889
+ const randInt = (a, b = 0) => {
890
+ if (!Number.isInteger(a) || !Number.isInteger(b)) {
891
+ throw Error("a and b must be integers");
892
+ }
893
+ return Math.floor(Math.random() * (b - a) + a);
894
+ };
895
+
896
+ /**
897
+ * Selects a random index based on the provided weights
898
+ * @param weights Array of non-negative weights
899
+ * @returns Selected index
900
+ */
901
+ const randWeight = (weights) => {
902
+ if (weights.length === 0) {
903
+ throw new Error("Weights array cannot be empty");
904
+ }
905
+ if (weights.some((w) => w < 0)) {
906
+ throw new Error("Weights array cannot contain negative values");
907
+ }
908
+ const wAccum = cumsum(weights);
909
+ const wTotal = wAccum[wAccum.length - 1];
910
+ if (wTotal === 0) {
911
+ throw new Error("Total weight must be greater than zero");
912
+ }
913
+ const r = Math.random() * wTotal;
914
+ return binSearch(wAccum, r, (el) => el);
915
+ };
916
+
917
+ const op = (arr, size, pick) => {
918
+ const n = Math.min(size, arr.length);
919
+ const res = arr.slice();
920
+ const end = res.length - n;
921
+ for (let i = res.length - 1; i > end; i--) {
922
+ const idx = pick(i + 1);
923
+ [res[i], res[idx]] = [res[idx], res[i]];
924
+ }
925
+ return n === arr.length ? res : res.slice(0, n);
926
+ };
927
+ const fisherYates = (data, size, weights) => {
928
+ if (size <= 0) {
929
+ return [];
930
+ }
931
+ if (weights === undefined) {
932
+ return op(data, size, (n) => Math.floor(Math.random() * n));
933
+ }
934
+ if (weights.length !== data.length) {
935
+ throw new Error("Weights must have the same length as the data array");
936
+ }
937
+ if (weights.some((w) => w < 0)) {
938
+ throw new Error("Weights cannot contain negative values.");
939
+ }
940
+ const w = weights.slice();
941
+ return op(data, size, () => {
942
+ const idx = randWeight(w);
943
+ w[idx] = 0;
944
+ return idx;
945
+ });
946
+ };
947
+
948
+ /**
949
+ * Samples elements from an array randomly, optionally using weights to influence selection
950
+ * @param data Array to sample from
951
+ * @param size Number of elements to sample
952
+ * @param weights Optional array of weights for weighted sampling
953
+ * @returns New array containing the sampled elements
954
+ */
955
+ const sample = fisherYates;
956
+
957
+ /**
958
+ * Shuffles an array randomly, optionally using weights to influence the
959
+ * likelihood of selecting elements first
960
+ * @param data Array to shuffle
961
+ * @param weights Optional array of weights for weighted shuffling
962
+ * @returns New array with the elements shuffled
963
+ */
964
+ const shuffle = (data, weights) => {
965
+ return fisherYates(data, data.length, weights);
966
+ };
967
+
968
+ const index$1 = /*#__PURE__*/Object.freeze({
969
+ __proto__: null,
970
+ randInt: randInt,
971
+ randWeight: randWeight,
972
+ sample: sample,
973
+ shuffle: shuffle
974
+ });
975
+
976
+ const words = (str) => {
977
+ return str
978
+ .replace(/([a-z])([A-Z])/g, "$1 $2") // Split camelCase and PascalCase
979
+ .replace(/([A-Z])([A-Z][a-z])/g, "$1 $2") // Split UPPERPascal > UPPER Pascal
980
+ .replace(/([0-9]+)/g, " $1 ")
981
+ .split(/[_-\s]+/)
982
+ .filter(Boolean);
983
+ };
984
+
985
+ /**
986
+ * Capitalizes the first letter of a string and converts the rest to lowercase
987
+ * @param str String to capitalize
988
+ * @returns Capitalized string
989
+ */
990
+ const capitalize = (str) => {
991
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
992
+ };
993
+
994
+ /**
995
+ * Converts a string to camelCase
996
+ * @param str String to convert
997
+ * @returns camelCase version of the input string
998
+ */
999
+ const camel = (str) => {
1000
+ const w = words(str).map(capitalize);
1001
+ if (w.length === 0) {
1002
+ return "";
1003
+ }
1004
+ w[0] = w[0].toLowerCase();
1005
+ return w.join("");
1006
+ };
1007
+
1008
+ /**
1009
+ * Converts a string to kebab-case
1010
+ * @param str String to convert
1011
+ * @returns kebab-case version of the input string
1012
+ */
1013
+ const kebab = (str) => {
1014
+ return words(str)
1015
+ .map((str) => str.toLowerCase())
1016
+ .join("-");
1017
+ };
1018
+
1019
+ /**
1020
+ * Converts a string to PascalCase
1021
+ * @param str String to convert
1022
+ * @returns PascalCase version of the input string
1023
+ */
1024
+ const pascal = (str) => {
1025
+ return words(str).map(capitalize).join("");
1026
+ };
1027
+
1028
+ /**
1029
+ * Converts a string to snake_case
1030
+ * @param str String to convert
1031
+ * @returns snake_case version of the input string
1032
+ */
1033
+ const snake = (str) => {
1034
+ return words(str)
1035
+ .map((str) => str.toLowerCase())
1036
+ .join("_");
1037
+ };
1038
+
1039
+ /**
1040
+ * Replaces placeholders in the format `{{path.to.value}}` within a string
1041
+ * with corresponding values from the provided data object
1042
+ * @param str String containing placeholders to replace
1043
+ * @param data Object with values for the placeholders
1044
+ * @returns String with placeholders replaced by their values
1045
+ */
1046
+ const template = (str, data) => {
1047
+ return str.replace(/\{\{([a-zA-Z0-9._]+)\}\}/g, (_, path) => {
1048
+ return get(data, path, "");
1049
+ });
1050
+ };
1051
+
1052
+ /**
1053
+ * Removes leading and trailing whitespace or specified characters from a string
1054
+ * @param str String to trim
1055
+ * @param chars Optional characters to trim from the string. Default: whitespace
1056
+ * @returns Trimmed string
1057
+ */
1058
+ const trim = (str, chars = " ") => {
1059
+ const reg = new RegExp(`^[${chars}]+|[${chars}]+$`, "g");
1060
+ return str.replace(reg, "");
1061
+ };
1062
+
1063
+ const index = /*#__PURE__*/Object.freeze({
1064
+ __proto__: null,
1065
+ camel: camel,
1066
+ capitalize: capitalize,
1067
+ kebab: kebab,
1068
+ pascal: pascal,
1069
+ snake: snake,
1070
+ template: template,
1071
+ trim: trim
1072
+ });
1073
+
1074
+ /**
1075
+ * @deprecated Time module is deprecated and may be removed in future releases
1076
+ */
1077
+ class Time {
1078
+ constructor(val, unit = "ms") {
1079
+ this.date = new Date();
1080
+ if (val !== undefined) {
1081
+ this.set(val, unit);
1082
+ }
1083
+ }
1084
+ static convert(val, from, to = "ms") {
1085
+ const ms = Math.round(Time.UNITS[from] * val);
1086
+ return ms / Time.UNITS[to];
1087
+ }
1088
+ add(val, unit = "ms") {
1089
+ return this.set(this.get(unit) + val, unit);
1090
+ }
1091
+ format(mode = "full", local = Time.locales, opts = {}) {
1092
+ const options = merge(Time.formatOptions[mode], opts);
1093
+ return this.date.toLocaleString(local, options);
1094
+ }
1095
+ get(unit = "ms") {
1096
+ return Time.convert(this.date.getTime(), "ms", unit);
1097
+ }
1098
+ getDayTime(unit = "ms") {
1099
+ return Time.convert(this.get("d") % 1, "d", unit);
1100
+ }
1101
+ set(val, unit = "ms") {
1102
+ return this.date.setTime(Time.convert(val, unit));
1103
+ }
1104
+ setDayTime(val, unit = "ms") {
1105
+ return this.add(val - this.getDayTime(unit), unit);
1106
+ }
1107
+ toDate() {
1108
+ return new Date(this.date);
1109
+ }
1110
+ }
1111
+ Time.UNITS = {
1112
+ d: 864e5,
1113
+ h: 36e5,
1114
+ m: 6e4,
1115
+ ms: 1,
1116
+ s: 1e3
1117
+ };
1118
+ Time.formatOptions = {
1119
+ date: {
1120
+ dateStyle: "medium"
1121
+ },
1122
+ full: {
1123
+ dateStyle: "short",
1124
+ timeStyle: "short"
1125
+ },
1126
+ time: {
1127
+ timeStyle: "medium"
1128
+ }
1129
+ };
1130
+
1131
+ export { Time, add, apply, aprox, index$5 as arr, binSearch, calc, camel, capitalize, chunk, copy, cumsum, curry, debounce, divide, entries, equal, fill, find, findAll, findAllIdx, findIdx, from, index$4 as func, get, group, groupBy, has, identity, inRange, interp, isObj, kebab, keys, index$3 as math, max, mean, median, memo, merge, min, mod, multiply, index$2 as obj, omit, once, pascal, percentile, pick, pipe, pow, index$1 as rand, randInt, randWeight, range, round, sample, set, shuffle, snake, sort, index as str, subtract, sum, template, throttle, transpose, trim, unapply, union, unique, vals, zip };
1132
+ //# sourceMappingURL=index.esm.js.map