@develia/commons 0.4.24 → 0.4.26

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 (363) hide show
  1. package/dist/array.d.ts.map +1 -0
  2. package/dist/array.js.map +1 -0
  3. package/dist/async-pool-executor.d.ts.map +1 -0
  4. package/dist/async-pool-executor.js.map +1 -0
  5. package/dist/browser/form-utilities.d.ts.map +1 -0
  6. package/dist/browser/form-utilities.js.map +1 -0
  7. package/dist/browser/geo-location.d.ts.map +1 -0
  8. package/dist/browser/geo-location.js.map +1 -0
  9. package/dist/browser/index.d.ts.map +1 -0
  10. package/dist/browser/index.js.map +1 -0
  11. package/dist/browser/native-bridge.d.ts.map +1 -0
  12. package/dist/browser/native-bridge.js.map +1 -0
  13. package/dist/cancellable-promise.d.ts.map +1 -0
  14. package/dist/cancellable-promise.js.map +1 -0
  15. package/dist/clean-url-search-params.d.ts.map +1 -0
  16. package/dist/clean-url-search-params.js.map +1 -0
  17. package/dist/collections/cache-dictionary.d.ts.map +1 -0
  18. package/dist/collections/cache-dictionary.js.map +1 -0
  19. package/dist/collections/default-map.d.ts.map +1 -0
  20. package/dist/collections/default-map.js.map +1 -0
  21. package/dist/collections/default-weak-map.d.ts.map +1 -0
  22. package/dist/collections/default-weak-map.js.map +1 -0
  23. package/dist/{types/collections → collections}/from.d.ts +15 -6
  24. package/dist/collections/from.d.ts.map +1 -0
  25. package/dist/{esm/collections → collections}/from.js +4 -10
  26. package/dist/collections/from.js.map +1 -0
  27. package/dist/collections/index.d.ts.map +1 -0
  28. package/dist/collections/index.js.map +1 -0
  29. package/dist/debouncer.d.ts.map +1 -0
  30. package/dist/debouncer.js.map +1 -0
  31. package/dist/draft.d.ts.map +1 -0
  32. package/dist/draft.js.map +1 -0
  33. package/dist/event-bus.d.ts.map +1 -0
  34. package/dist/event-bus.js.map +1 -0
  35. package/dist/functions.d.ts.map +1 -0
  36. package/dist/functions.js.map +1 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/key-value-pair.d.ts.map +1 -0
  40. package/dist/key-value-pair.js.map +1 -0
  41. package/dist/keyed-debouncer.d.ts.map +1 -0
  42. package/dist/keyed-debouncer.js.map +1 -0
  43. package/dist/lazy.d.ts.map +1 -0
  44. package/dist/lazy.js.map +1 -0
  45. package/dist/math.d.ts.map +1 -0
  46. package/dist/math.js.map +1 -0
  47. package/dist/order.d.ts.map +1 -0
  48. package/dist/order.js.map +1 -0
  49. package/dist/parse.d.ts.map +1 -0
  50. package/dist/parse.js.map +1 -0
  51. package/dist/patch.d.ts.map +1 -0
  52. package/dist/patch.js.map +1 -0
  53. package/dist/range.d.ts.map +1 -0
  54. package/dist/range.js.map +1 -0
  55. package/dist/result.d.ts.map +1 -0
  56. package/dist/result.js.map +1 -0
  57. package/dist/stopwatch.d.ts.map +1 -0
  58. package/dist/stopwatch.js.map +1 -0
  59. package/dist/string.d.ts.map +1 -0
  60. package/dist/string.js.map +1 -0
  61. package/dist/timer.d.ts.map +1 -0
  62. package/dist/timer.js.map +1 -0
  63. package/dist/timespan.d.ts.map +1 -0
  64. package/dist/timespan.js.map +1 -0
  65. package/dist/triggers.d.ts.map +1 -0
  66. package/dist/triggers.js.map +1 -0
  67. package/dist/type-code.d.ts.map +1 -0
  68. package/dist/type-code.js.map +1 -0
  69. package/dist/type.d.ts.map +1 -0
  70. package/dist/type.js.map +1 -0
  71. package/dist/types.d.ts.map +1 -0
  72. package/dist/types.js.map +1 -0
  73. package/dist/{types/utilities.d.ts → utilities.d.ts} +4 -3
  74. package/dist/utilities.d.ts.map +1 -0
  75. package/dist/{web/utilities.js → utilities.js} +4 -3
  76. package/dist/utilities.js.map +1 -0
  77. package/package.json +13 -62
  78. package/src/collections/from.ts +21 -11
  79. package/src/utilities.ts +5 -4
  80. package/dist/cjs/array.js +0 -106
  81. package/dist/cjs/array.js.map +0 -1
  82. package/dist/cjs/async-pool-executor.js +0 -79
  83. package/dist/cjs/async-pool-executor.js.map +0 -1
  84. package/dist/cjs/browser/form-utilities.js +0 -162
  85. package/dist/cjs/browser/form-utilities.js.map +0 -1
  86. package/dist/cjs/browser/geo-location.js +0 -78
  87. package/dist/cjs/browser/geo-location.js.map +0 -1
  88. package/dist/cjs/browser/index.js +0 -99
  89. package/dist/cjs/browser/index.js.map +0 -1
  90. package/dist/cjs/browser/native-bridge.js +0 -81
  91. package/dist/cjs/browser/native-bridge.js.map +0 -1
  92. package/dist/cjs/cancellable-promise.js +0 -81
  93. package/dist/cjs/cancellable-promise.js.map +0 -1
  94. package/dist/cjs/clean-url-search-params.js +0 -34
  95. package/dist/cjs/clean-url-search-params.js.map +0 -1
  96. package/dist/cjs/collections/cache-dictionary.js +0 -102
  97. package/dist/cjs/collections/cache-dictionary.js.map +0 -1
  98. package/dist/cjs/collections/default-map.js +0 -45
  99. package/dist/cjs/collections/default-map.js.map +0 -1
  100. package/dist/cjs/collections/default-weak-map.js +0 -46
  101. package/dist/cjs/collections/default-weak-map.js.map +0 -1
  102. package/dist/cjs/collections/from.js +0 -778
  103. package/dist/cjs/collections/from.js.map +0 -1
  104. package/dist/cjs/collections/index.js +0 -15
  105. package/dist/cjs/collections/index.js.map +0 -1
  106. package/dist/cjs/debouncer.js +0 -121
  107. package/dist/cjs/debouncer.js.map +0 -1
  108. package/dist/cjs/draft.js +0 -225
  109. package/dist/cjs/draft.js.map +0 -1
  110. package/dist/cjs/event-bus.js +0 -71
  111. package/dist/cjs/event-bus.js.map +0 -1
  112. package/dist/cjs/functions.js +0 -262
  113. package/dist/cjs/functions.js.map +0 -1
  114. package/dist/cjs/index.js +0 -84
  115. package/dist/cjs/index.js.map +0 -1
  116. package/dist/cjs/key-value-pair.js +0 -22
  117. package/dist/cjs/key-value-pair.js.map +0 -1
  118. package/dist/cjs/keyed-debouncer.js +0 -144
  119. package/dist/cjs/keyed-debouncer.js.map +0 -1
  120. package/dist/cjs/lazy.js +0 -29
  121. package/dist/cjs/lazy.js.map +0 -1
  122. package/dist/cjs/math.js +0 -37
  123. package/dist/cjs/math.js.map +0 -1
  124. package/dist/cjs/order.js +0 -9
  125. package/dist/cjs/order.js.map +0 -1
  126. package/dist/cjs/parse.js +0 -174
  127. package/dist/cjs/parse.js.map +0 -1
  128. package/dist/cjs/patch.js +0 -52
  129. package/dist/cjs/patch.js.map +0 -1
  130. package/dist/cjs/range.js +0 -154
  131. package/dist/cjs/range.js.map +0 -1
  132. package/dist/cjs/result.js +0 -3
  133. package/dist/cjs/result.js.map +0 -1
  134. package/dist/cjs/stopwatch.js +0 -46
  135. package/dist/cjs/stopwatch.js.map +0 -1
  136. package/dist/cjs/string.js +0 -154
  137. package/dist/cjs/string.js.map +0 -1
  138. package/dist/cjs/timer.js +0 -57
  139. package/dist/cjs/timer.js.map +0 -1
  140. package/dist/cjs/timespan.js +0 -367
  141. package/dist/cjs/timespan.js.map +0 -1
  142. package/dist/cjs/triggers.js +0 -103
  143. package/dist/cjs/triggers.js.map +0 -1
  144. package/dist/cjs/type-code.js +0 -18
  145. package/dist/cjs/type-code.js.map +0 -1
  146. package/dist/cjs/type.js +0 -296
  147. package/dist/cjs/type.js.map +0 -1
  148. package/dist/cjs/types.js +0 -3
  149. package/dist/cjs/types.js.map +0 -1
  150. package/dist/cjs/utilities.js +0 -621
  151. package/dist/cjs/utilities.js.map +0 -1
  152. package/dist/esm/array.js.map +0 -1
  153. package/dist/esm/async-pool-executor.js.map +0 -1
  154. package/dist/esm/browser/form-utilities.js.map +0 -1
  155. package/dist/esm/browser/geo-location.js.map +0 -1
  156. package/dist/esm/browser/index.js.map +0 -1
  157. package/dist/esm/browser/native-bridge.js.map +0 -1
  158. package/dist/esm/cancellable-promise.js.map +0 -1
  159. package/dist/esm/clean-url-search-params.js.map +0 -1
  160. package/dist/esm/collections/cache-dictionary.js.map +0 -1
  161. package/dist/esm/collections/default-map.js.map +0 -1
  162. package/dist/esm/collections/default-weak-map.js.map +0 -1
  163. package/dist/esm/collections/from.js.map +0 -1
  164. package/dist/esm/collections/index.js.map +0 -1
  165. package/dist/esm/debouncer.js.map +0 -1
  166. package/dist/esm/draft.js.map +0 -1
  167. package/dist/esm/event-bus.js.map +0 -1
  168. package/dist/esm/functions.js.map +0 -1
  169. package/dist/esm/index.js.map +0 -1
  170. package/dist/esm/key-value-pair.js.map +0 -1
  171. package/dist/esm/keyed-debouncer.js.map +0 -1
  172. package/dist/esm/lazy.js.map +0 -1
  173. package/dist/esm/math.js.map +0 -1
  174. package/dist/esm/order.js.map +0 -1
  175. package/dist/esm/parse.js.map +0 -1
  176. package/dist/esm/patch.js.map +0 -1
  177. package/dist/esm/range.js.map +0 -1
  178. package/dist/esm/result.js.map +0 -1
  179. package/dist/esm/stopwatch.js.map +0 -1
  180. package/dist/esm/string.js.map +0 -1
  181. package/dist/esm/timer.js.map +0 -1
  182. package/dist/esm/timespan.js.map +0 -1
  183. package/dist/esm/triggers.js.map +0 -1
  184. package/dist/esm/type-code.js.map +0 -1
  185. package/dist/esm/type.js.map +0 -1
  186. package/dist/esm/types.js.map +0 -1
  187. package/dist/esm/utilities.js +0 -590
  188. package/dist/esm/utilities.js.map +0 -1
  189. package/dist/types/array.d.ts.map +0 -1
  190. package/dist/types/async-pool-executor.d.ts.map +0 -1
  191. package/dist/types/browser/form-utilities.d.ts.map +0 -1
  192. package/dist/types/browser/geo-location.d.ts.map +0 -1
  193. package/dist/types/browser/index.d.ts.map +0 -1
  194. package/dist/types/browser/native-bridge.d.ts.map +0 -1
  195. package/dist/types/cancellable-promise.d.ts.map +0 -1
  196. package/dist/types/clean-url-search-params.d.ts.map +0 -1
  197. package/dist/types/collections/cache-dictionary.d.ts.map +0 -1
  198. package/dist/types/collections/default-map.d.ts.map +0 -1
  199. package/dist/types/collections/default-weak-map.d.ts.map +0 -1
  200. package/dist/types/collections/from.d.ts.map +0 -1
  201. package/dist/types/collections/index.d.ts.map +0 -1
  202. package/dist/types/debouncer.d.ts.map +0 -1
  203. package/dist/types/draft.d.ts.map +0 -1
  204. package/dist/types/event-bus.d.ts.map +0 -1
  205. package/dist/types/functions.d.ts.map +0 -1
  206. package/dist/types/index.d.ts.map +0 -1
  207. package/dist/types/key-value-pair.d.ts.map +0 -1
  208. package/dist/types/keyed-debouncer.d.ts.map +0 -1
  209. package/dist/types/lazy.d.ts.map +0 -1
  210. package/dist/types/math.d.ts.map +0 -1
  211. package/dist/types/order.d.ts.map +0 -1
  212. package/dist/types/parse.d.ts.map +0 -1
  213. package/dist/types/patch.d.ts.map +0 -1
  214. package/dist/types/range.d.ts.map +0 -1
  215. package/dist/types/result.d.ts.map +0 -1
  216. package/dist/types/stopwatch.d.ts.map +0 -1
  217. package/dist/types/string.d.ts.map +0 -1
  218. package/dist/types/timer.d.ts.map +0 -1
  219. package/dist/types/timespan.d.ts.map +0 -1
  220. package/dist/types/triggers.d.ts.map +0 -1
  221. package/dist/types/type-code.d.ts.map +0 -1
  222. package/dist/types/type.d.ts.map +0 -1
  223. package/dist/types/types.d.ts.map +0 -1
  224. package/dist/types/utilities.d.ts.map +0 -1
  225. package/dist/web/array.js +0 -98
  226. package/dist/web/array.js.map +0 -1
  227. package/dist/web/async-pool-executor.js +0 -76
  228. package/dist/web/async-pool-executor.js.map +0 -1
  229. package/dist/web/browser/form-utilities.js +0 -155
  230. package/dist/web/browser/form-utilities.js.map +0 -1
  231. package/dist/web/browser/geo-location.js +0 -75
  232. package/dist/web/browser/geo-location.js.map +0 -1
  233. package/dist/web/browser/index.js +0 -75
  234. package/dist/web/browser/index.js.map +0 -1
  235. package/dist/web/browser/native-bridge.js +0 -78
  236. package/dist/web/browser/native-bridge.js.map +0 -1
  237. package/dist/web/cancellable-promise.js +0 -78
  238. package/dist/web/cancellable-promise.js.map +0 -1
  239. package/dist/web/clean-url-search-params.js +0 -31
  240. package/dist/web/clean-url-search-params.js.map +0 -1
  241. package/dist/web/collections/cache-dictionary.js +0 -99
  242. package/dist/web/collections/cache-dictionary.js.map +0 -1
  243. package/dist/web/collections/default-map.js +0 -42
  244. package/dist/web/collections/default-map.js.map +0 -1
  245. package/dist/web/collections/default-weak-map.js +0 -43
  246. package/dist/web/collections/default-weak-map.js.map +0 -1
  247. package/dist/web/collections/from.js +0 -770
  248. package/dist/web/collections/from.js.map +0 -1
  249. package/dist/web/collections/index.js +0 -5
  250. package/dist/web/collections/index.js.map +0 -1
  251. package/dist/web/debouncer.js +0 -118
  252. package/dist/web/debouncer.js.map +0 -1
  253. package/dist/web/draft.js +0 -222
  254. package/dist/web/draft.js.map +0 -1
  255. package/dist/web/event-bus.js +0 -66
  256. package/dist/web/event-bus.js.map +0 -1
  257. package/dist/web/functions.js +0 -251
  258. package/dist/web/functions.js.map +0 -1
  259. package/dist/web/index.js +0 -40
  260. package/dist/web/index.js.map +0 -1
  261. package/dist/web/key-value-pair.js +0 -19
  262. package/dist/web/key-value-pair.js.map +0 -1
  263. package/dist/web/keyed-debouncer.js +0 -109
  264. package/dist/web/keyed-debouncer.js.map +0 -1
  265. package/dist/web/lazy.js +0 -26
  266. package/dist/web/lazy.js.map +0 -1
  267. package/dist/web/math.js +0 -33
  268. package/dist/web/math.js.map +0 -1
  269. package/dist/web/order.js +0 -7
  270. package/dist/web/order.js.map +0 -1
  271. package/dist/web/parse.js +0 -169
  272. package/dist/web/parse.js.map +0 -1
  273. package/dist/web/patch.js +0 -48
  274. package/dist/web/patch.js.map +0 -1
  275. package/dist/web/range.js +0 -151
  276. package/dist/web/range.js.map +0 -1
  277. package/dist/web/result.js +0 -2
  278. package/dist/web/result.js.map +0 -1
  279. package/dist/web/stopwatch.js +0 -40
  280. package/dist/web/stopwatch.js.map +0 -1
  281. package/dist/web/string.js +0 -142
  282. package/dist/web/string.js.map +0 -1
  283. package/dist/web/timer.js +0 -54
  284. package/dist/web/timer.js.map +0 -1
  285. package/dist/web/timespan.js +0 -365
  286. package/dist/web/timespan.js.map +0 -1
  287. package/dist/web/triggers.js +0 -99
  288. package/dist/web/triggers.js.map +0 -1
  289. package/dist/web/type-code.js +0 -16
  290. package/dist/web/type-code.js.map +0 -1
  291. package/dist/web/type.js +0 -292
  292. package/dist/web/type.js.map +0 -1
  293. package/dist/web/types.js +0 -2
  294. package/dist/web/types.js.map +0 -1
  295. package/dist/web/utilities.js.map +0 -1
  296. /package/dist/{types/array.d.ts → array.d.ts} +0 -0
  297. /package/dist/{esm/array.js → array.js} +0 -0
  298. /package/dist/{types/async-pool-executor.d.ts → async-pool-executor.d.ts} +0 -0
  299. /package/dist/{esm/async-pool-executor.js → async-pool-executor.js} +0 -0
  300. /package/dist/{types/browser → browser}/form-utilities.d.ts +0 -0
  301. /package/dist/{esm/browser → browser}/form-utilities.js +0 -0
  302. /package/dist/{types/browser → browser}/geo-location.d.ts +0 -0
  303. /package/dist/{esm/browser → browser}/geo-location.js +0 -0
  304. /package/dist/{types/browser → browser}/index.d.ts +0 -0
  305. /package/dist/{esm/browser → browser}/index.js +0 -0
  306. /package/dist/{types/browser → browser}/native-bridge.d.ts +0 -0
  307. /package/dist/{esm/browser → browser}/native-bridge.js +0 -0
  308. /package/dist/{types/cancellable-promise.d.ts → cancellable-promise.d.ts} +0 -0
  309. /package/dist/{esm/cancellable-promise.js → cancellable-promise.js} +0 -0
  310. /package/dist/{types/clean-url-search-params.d.ts → clean-url-search-params.d.ts} +0 -0
  311. /package/dist/{esm/clean-url-search-params.js → clean-url-search-params.js} +0 -0
  312. /package/dist/{types/collections → collections}/cache-dictionary.d.ts +0 -0
  313. /package/dist/{esm/collections → collections}/cache-dictionary.js +0 -0
  314. /package/dist/{types/collections → collections}/default-map.d.ts +0 -0
  315. /package/dist/{esm/collections → collections}/default-map.js +0 -0
  316. /package/dist/{types/collections → collections}/default-weak-map.d.ts +0 -0
  317. /package/dist/{esm/collections → collections}/default-weak-map.js +0 -0
  318. /package/dist/{types/collections → collections}/index.d.ts +0 -0
  319. /package/dist/{esm/collections → collections}/index.js +0 -0
  320. /package/dist/{types/debouncer.d.ts → debouncer.d.ts} +0 -0
  321. /package/dist/{esm/debouncer.js → debouncer.js} +0 -0
  322. /package/dist/{types/draft.d.ts → draft.d.ts} +0 -0
  323. /package/dist/{esm/draft.js → draft.js} +0 -0
  324. /package/dist/{types/event-bus.d.ts → event-bus.d.ts} +0 -0
  325. /package/dist/{esm/event-bus.js → event-bus.js} +0 -0
  326. /package/dist/{types/functions.d.ts → functions.d.ts} +0 -0
  327. /package/dist/{esm/functions.js → functions.js} +0 -0
  328. /package/dist/{types/index.d.ts → index.d.ts} +0 -0
  329. /package/dist/{esm/index.js → index.js} +0 -0
  330. /package/dist/{types/key-value-pair.d.ts → key-value-pair.d.ts} +0 -0
  331. /package/dist/{esm/key-value-pair.js → key-value-pair.js} +0 -0
  332. /package/dist/{types/keyed-debouncer.d.ts → keyed-debouncer.d.ts} +0 -0
  333. /package/dist/{esm/keyed-debouncer.js → keyed-debouncer.js} +0 -0
  334. /package/dist/{types/lazy.d.ts → lazy.d.ts} +0 -0
  335. /package/dist/{esm/lazy.js → lazy.js} +0 -0
  336. /package/dist/{types/math.d.ts → math.d.ts} +0 -0
  337. /package/dist/{esm/math.js → math.js} +0 -0
  338. /package/dist/{types/order.d.ts → order.d.ts} +0 -0
  339. /package/dist/{esm/order.js → order.js} +0 -0
  340. /package/dist/{types/parse.d.ts → parse.d.ts} +0 -0
  341. /package/dist/{esm/parse.js → parse.js} +0 -0
  342. /package/dist/{types/patch.d.ts → patch.d.ts} +0 -0
  343. /package/dist/{esm/patch.js → patch.js} +0 -0
  344. /package/dist/{types/range.d.ts → range.d.ts} +0 -0
  345. /package/dist/{esm/range.js → range.js} +0 -0
  346. /package/dist/{types/result.d.ts → result.d.ts} +0 -0
  347. /package/dist/{esm/result.js → result.js} +0 -0
  348. /package/dist/{types/stopwatch.d.ts → stopwatch.d.ts} +0 -0
  349. /package/dist/{esm/stopwatch.js → stopwatch.js} +0 -0
  350. /package/dist/{types/string.d.ts → string.d.ts} +0 -0
  351. /package/dist/{esm/string.js → string.js} +0 -0
  352. /package/dist/{types/timer.d.ts → timer.d.ts} +0 -0
  353. /package/dist/{esm/timer.js → timer.js} +0 -0
  354. /package/dist/{types/timespan.d.ts → timespan.d.ts} +0 -0
  355. /package/dist/{esm/timespan.js → timespan.js} +0 -0
  356. /package/dist/{types/triggers.d.ts → triggers.d.ts} +0 -0
  357. /package/dist/{esm/triggers.js → triggers.js} +0 -0
  358. /package/dist/{types/type-code.d.ts → type-code.d.ts} +0 -0
  359. /package/dist/{esm/type-code.js → type-code.js} +0 -0
  360. /package/dist/{types/type.d.ts → type.d.ts} +0 -0
  361. /package/dist/{esm/type.js → type.js} +0 -0
  362. /package/dist/{types/types.d.ts → types.d.ts} +0 -0
  363. /package/dist/{esm/types.js → types.js} +0 -0
@@ -1,262 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.identity = identity;
4
- exports.constant = constant;
5
- exports.noop = noop;
6
- exports.once = once;
7
- exports.memoize = memoize;
8
- exports.throttle = throttle;
9
- exports.partial = partial;
10
- exports.pipe = pipe;
11
- exports.compose = compose;
12
- /**
13
- * Return the received value unchanged.
14
- * Useful as a default mapper, placeholder callback, or neutral transform in a pipeline.
15
- *
16
- * @example
17
- * ```ts
18
- * identity(5); // 5
19
- *
20
- * const value = {name: "commons"};
21
- * identity(value) === value; // true
22
- * ```
23
- */
24
- function identity(value) {
25
- return value;
26
- }
27
- /**
28
- * Create a function that always returns the same value.
29
- *
30
- * @example
31
- * ```ts
32
- * const getAnswer = constant(42);
33
- *
34
- * getAnswer(); // 42
35
- * getAnswer(); // 42
36
- * ```
37
- */
38
- function constant(value) {
39
- return () => value;
40
- }
41
- /**
42
- * Do nothing and return undefined.
43
- * Useful as a safe default callback.
44
- *
45
- * @example
46
- * ```ts
47
- * const onComplete = options.onComplete ?? noop;
48
- * onComplete();
49
- * ```
50
- */
51
- function noop() {
52
- // Intentionally empty.
53
- }
54
- /**
55
- * Create a function that can be executed only once.
56
- * Later calls return the result from the first execution without calling the original function again.
57
- *
58
- * @example
59
- * ```ts
60
- * const initialize = once(() => ({connected: true}));
61
- *
62
- * const first = initialize();
63
- * const second = initialize();
64
- * first === second; // true
65
- * ```
66
- */
67
- function once(fn) {
68
- let called = false;
69
- let result;
70
- return function (...args) {
71
- if (!called) {
72
- called = true;
73
- result = fn.apply(this, args);
74
- }
75
- return result;
76
- };
77
- }
78
- /**
79
- * Cache the result of a function and reuse it for calls with the same resolved key.
80
- * By default, the first argument is used as the cache key.
81
- *
82
- * @example
83
- * ```ts
84
- * const double = memoize((value: number) => value * 2);
85
- *
86
- * double(4); // 8, computed
87
- * double(4); // 8, read from cache
88
- * double.has(4); // true
89
- * ```
90
- *
91
- * @example
92
- * ```ts
93
- * const sum = memoize(
94
- * (left: number, right: number) => left + right,
95
- * (left, right) => `${left}:${right}`,
96
- * );
97
- *
98
- * sum(2, 3); // 5
99
- * sum.delete(2, 3); // true
100
- * sum.clear();
101
- * ```
102
- */
103
- function memoize(fn, resolver, cache = new Map()) {
104
- const resolveKey = (...args) => {
105
- if (resolver)
106
- return resolver(...args);
107
- return args[0];
108
- };
109
- const memoized = function (...args) {
110
- const key = resolveKey(...args);
111
- if (cache.has(key)) {
112
- return cache.get(key);
113
- }
114
- const value = fn.apply(this, args);
115
- cache.set(key, value);
116
- return value;
117
- };
118
- Object.defineProperty(memoized, "cache", {
119
- value: cache,
120
- enumerable: false,
121
- });
122
- memoized.clear = () => cache.clear();
123
- memoized.delete = (...args) => cache.delete(resolveKey(...args));
124
- memoized.has = (...args) => cache.has(resolveKey(...args));
125
- return memoized;
126
- }
127
- /**
128
- * Limit how often a function can run during a time window.
129
- * Calls made while the function is throttled can optionally be replayed once at the end with the latest arguments.
130
- *
131
- * @example
132
- * ```ts
133
- * const onScroll = throttle(() => {
134
- * console.log(window.scrollY);
135
- * }, 100);
136
- *
137
- * window.addEventListener("scroll", onScroll);
138
- * ```
139
- *
140
- * @example
141
- * ```ts
142
- * const refresh = throttle(loadData, 500, {leading: false});
143
- *
144
- * refresh(); // scheduled instead of executed immediately
145
- * refresh.flush(); // execute the scheduled call now
146
- * ```
147
- */
148
- function throttle(fn, wait, options = {}) {
149
- const delay = normalizeDelay(wait);
150
- const leading = options.leading ?? true;
151
- const trailing = options.trailing ?? true;
152
- let timer;
153
- let lastArgs;
154
- let lastThis;
155
- let lastInvokeTime = 0;
156
- let hasInvoked = false;
157
- let result;
158
- const invoke = (time) => {
159
- const args = lastArgs;
160
- const context = lastThis;
161
- lastArgs = undefined;
162
- lastThis = undefined;
163
- hasInvoked = true;
164
- lastInvokeTime = time;
165
- result = fn.apply(context, args);
166
- return result;
167
- };
168
- const expire = () => {
169
- timer = undefined;
170
- if (trailing && lastArgs) {
171
- invoke(Date.now());
172
- }
173
- else {
174
- lastArgs = undefined;
175
- lastThis = undefined;
176
- }
177
- };
178
- const throttled = function (...args) {
179
- const now = Date.now();
180
- lastArgs = args;
181
- lastThis = this;
182
- if (!hasInvoked) {
183
- if (leading) {
184
- return invoke(now);
185
- }
186
- hasInvoked = true;
187
- lastInvokeTime = now;
188
- }
189
- const remaining = delay - (now - lastInvokeTime);
190
- if (remaining <= 0 || remaining > delay) {
191
- if (timer !== undefined) {
192
- clearTimeout(timer);
193
- timer = undefined;
194
- }
195
- return invoke(now);
196
- }
197
- if (timer === undefined && trailing) {
198
- timer = setTimeout(expire, remaining);
199
- }
200
- return result;
201
- };
202
- throttled.cancel = () => {
203
- if (timer !== undefined) {
204
- clearTimeout(timer);
205
- }
206
- timer = undefined;
207
- lastArgs = undefined;
208
- lastThis = undefined;
209
- lastInvokeTime = 0;
210
- hasInvoked = false;
211
- };
212
- throttled.flush = () => {
213
- if (timer !== undefined) {
214
- clearTimeout(timer);
215
- timer = undefined;
216
- if (lastArgs && trailing) {
217
- return invoke(Date.now());
218
- }
219
- }
220
- return result;
221
- };
222
- throttled.pending = () => timer !== undefined;
223
- return throttled;
224
- }
225
- /**
226
- * Create a function with one or more arguments already provided.
227
- * Later arguments are appended after the preset arguments.
228
- *
229
- * @example
230
- * ```ts
231
- * const sum = (a: number, b: number, c: number) => a + b + c;
232
- * const addFive = partial(sum, 2, 3);
233
- *
234
- * addFive(4); // 9
235
- * ```
236
- */
237
- function partial(fn, ...presetArgs) {
238
- return function (...laterArgs) {
239
- return fn.apply(this, [...presetArgs, ...laterArgs]);
240
- };
241
- }
242
- function pipe(...fns) {
243
- return createFlow(fns);
244
- }
245
- function compose(...fns) {
246
- return createFlow(fns.slice().reverse());
247
- }
248
- function createFlow(fns) {
249
- if (fns.length === 0)
250
- return identity;
251
- return function (...args) {
252
- let result = fns[0].apply(this, args);
253
- for (let i = 1; i < fns.length; i++) {
254
- result = fns[i].call(this, result);
255
- }
256
- return result;
257
- };
258
- }
259
- function normalizeDelay(wait) {
260
- return Number.isFinite(wait) ? Math.max(0, wait) : 0;
261
- }
262
- //# sourceMappingURL=functions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/functions.ts"],"names":[],"mappings":";;AA4EA,4BAEC;AAaD,4BAEC;AAYD,oBAEC;AAeD,oBAWC;AA2BD,0BA+BC;AAuBD,4BA2FC;AAcD,0BAOC;AAoBD,oBAEC;AAoBD,0BAEC;AAlTD;;;;;;;;;;;GAWG;AACH,SAAgB,QAAQ,CAAI,KAAQ;IAChC,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,QAAQ,CAAI,KAAQ;IAChC,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC;AACvB,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,IAAI;IAChB,uBAAuB;AAC3B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,IAAI,CAAwB,EAAK;IAC7C,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,MAAqB,CAAC;IAE1B,OAAO,UAAsC,GAAG,IAAmB;QAC/D,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,MAAM,GAAG,IAAI,CAAC;YACd,MAAM,GAAG,EAAE,CAAC,KAAK,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ACN,CAAC;AAED,SAAS,cAAc,CAAC,IAAY;IAChC,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACzD,CAAC","sourcesContent":["type AnyFunction = (this: any, ...args: any[]) => any;\ntype TimerHandle = ReturnType<typeof setTimeout>;\n\n/** Options that control when a throttled function is executed. */\nexport interface ThrottleOptions {\n /** Execute immediately on the first call in a throttle window. Defaults to true. */\n leading?: boolean;\n /** Execute once more at the end of the throttle window using the latest arguments. Defaults to true. */\n trailing?: boolean;\n}\n\n/**\n * A delayed function returned by {@link throttle}.\n *\n * @example\n * ```ts\n * const refresh = throttle(loadData, 250);\n * refresh();\n *\n * if (refresh.pending()) {\n * refresh.flush();\n * }\n * ```\n */\nexport type DeferredFunction<F extends AnyFunction> = ((\n this: ThisParameterType<F>,\n ...args: Parameters<F>\n) => ReturnType<F> | undefined) & {\n /** Cancel the scheduled call and forget the latest arguments. */\n cancel(): void;\n /** Execute the scheduled trailing call immediately, when one exists. */\n flush(): ReturnType<F> | undefined;\n /** Return true while a trailing call is scheduled. */\n pending(): boolean;\n};\n\n/**\n * A memoized function with helpers for inspecting and invalidating its cache.\n *\n * @example\n * ```ts\n * const getUser = memoize((id: string) => fetchUser(id));\n *\n * getUser(\"42\");\n * getUser.has(\"42\"); // true\n * getUser.delete(\"42\");\n * ```\n */\nexport type MemoizedFunction<F extends AnyFunction, K> = ((\n this: ThisParameterType<F>,\n ...args: Parameters<F>\n) => ReturnType<F>) & {\n /** The backing cache used by the memoized function. */\n readonly cache: Map<K, ReturnType<F>>;\n /** Remove every cached value. */\n clear(): void;\n /** Remove the cached value for the key resolved from the provided arguments. */\n delete(...args: Parameters<F>): boolean;\n /** Return true when a cached value exists for the key resolved from the provided arguments. */\n has(...args: Parameters<F>): boolean;\n};\n\ntype Unary<T, R> = (arg: T) => R;\n\n/**\n * Return the received value unchanged.\n * Useful as a default mapper, placeholder callback, or neutral transform in a pipeline.\n *\n * @example\n * ```ts\n * identity(5); // 5\n *\n * const value = {name: \"commons\"};\n * identity(value) === value; // true\n * ```\n */\nexport function identity<T>(value: T): T {\n return value;\n}\n\n/**\n * Create a function that always returns the same value.\n *\n * @example\n * ```ts\n * const getAnswer = constant(42);\n *\n * getAnswer(); // 42\n * getAnswer(); // 42\n * ```\n */\nexport function constant<T>(value: T): () => T {\n return () => value;\n}\n\n/**\n * Do nothing and return undefined.\n * Useful as a safe default callback.\n *\n * @example\n * ```ts\n * const onComplete = options.onComplete ?? noop;\n * onComplete();\n * ```\n */\nexport function noop(): void {\n // Intentionally empty.\n}\n\n/**\n * Create a function that can be executed only once.\n * Later calls return the result from the first execution without calling the original function again.\n *\n * @example\n * ```ts\n * const initialize = once(() => ({connected: true}));\n *\n * const first = initialize();\n * const second = initialize();\n * first === second; // true\n * ```\n */\nexport function once<F extends AnyFunction>(fn: F): F {\n let called = false;\n let result: ReturnType<F>;\n\n return function (this: ThisParameterType<F>, ...args: Parameters<F>): ReturnType<F> {\n if (!called) {\n called = true;\n result = fn.apply(this, args);\n }\n return result;\n } as F;\n}\n\n/**\n * Cache the result of a function and reuse it for calls with the same resolved key.\n * By default, the first argument is used as the cache key.\n *\n * @example\n * ```ts\n * const double = memoize((value: number) => value * 2);\n *\n * double(4); // 8, computed\n * double(4); // 8, read from cache\n * double.has(4); // true\n * ```\n *\n * @example\n * ```ts\n * const sum = memoize(\n * (left: number, right: number) => left + right,\n * (left, right) => `${left}:${right}`,\n * );\n *\n * sum(2, 3); // 5\n * sum.delete(2, 3); // true\n * sum.clear();\n * ```\n */\nexport function memoize<F extends AnyFunction, K = Parameters<F>[0]>(\n fn: F,\n resolver?: (...args: Parameters<F>) => K,\n cache: Map<K, ReturnType<F>> = new Map<K, ReturnType<F>>()\n): MemoizedFunction<F, K> {\n const resolveKey = (...args: Parameters<F>): K => {\n if (resolver) return resolver(...args);\n return args[0] as K;\n };\n\n const memoized = function (this: ThisParameterType<F>, ...args: Parameters<F>): ReturnType<F> {\n const key = resolveKey(...args);\n if (cache.has(key)) {\n return cache.get(key)!;\n }\n\n const value = fn.apply(this, args);\n cache.set(key, value);\n return value;\n } as MemoizedFunction<F, K>;\n\n Object.defineProperty(memoized, \"cache\", {\n value: cache,\n enumerable: false,\n });\n\n memoized.clear = () => cache.clear();\n memoized.delete = (...args: Parameters<F>) => cache.delete(resolveKey(...args));\n memoized.has = (...args: Parameters<F>) => cache.has(resolveKey(...args));\n\n return memoized;\n}\n\n/**\n * Limit how often a function can run during a time window.\n * Calls made while the function is throttled can optionally be replayed once at the end with the latest arguments.\n *\n * @example\n * ```ts\n * const onScroll = throttle(() => {\n * console.log(window.scrollY);\n * }, 100);\n *\n * window.addEventListener(\"scroll\", onScroll);\n * ```\n *\n * @example\n * ```ts\n * const refresh = throttle(loadData, 500, {leading: false});\n *\n * refresh(); // scheduled instead of executed immediately\n * refresh.flush(); // execute the scheduled call now\n * ```\n */\nexport function throttle<F extends AnyFunction>(\n fn: F,\n wait: number,\n options: ThrottleOptions = {}\n): DeferredFunction<F> {\n const delay = normalizeDelay(wait);\n const leading = options.leading ?? true;\n const trailing = options.trailing ?? true;\n\n let timer: TimerHandle | undefined;\n let lastArgs: Parameters<F> | undefined;\n let lastThis: ThisParameterType<F> | undefined;\n let lastInvokeTime = 0;\n let hasInvoked = false;\n let result: ReturnType<F> | undefined;\n\n const invoke = (time: number): ReturnType<F> => {\n const args = lastArgs!;\n const context = lastThis!;\n lastArgs = undefined;\n lastThis = undefined;\n hasInvoked = true;\n lastInvokeTime = time;\n result = fn.apply(context, args);\n return result as ReturnType<F>;\n };\n\n const expire = (): void => {\n timer = undefined;\n if (trailing && lastArgs) {\n invoke(Date.now());\n } else {\n lastArgs = undefined;\n lastThis = undefined;\n }\n };\n\n const throttled = function (this: ThisParameterType<F>, ...args: Parameters<F>): ReturnType<F> | undefined {\n const now = Date.now();\n lastArgs = args;\n lastThis = this;\n\n if (!hasInvoked) {\n if (leading) {\n return invoke(now);\n }\n hasInvoked = true;\n lastInvokeTime = now;\n }\n\n const remaining = delay - (now - lastInvokeTime);\n if (remaining <= 0 || remaining > delay) {\n if (timer !== undefined) {\n clearTimeout(timer);\n timer = undefined;\n }\n return invoke(now);\n }\n\n if (timer === undefined && trailing) {\n timer = setTimeout(expire, remaining);\n }\n\n return result;\n } as DeferredFunction<F>;\n\n throttled.cancel = (): void => {\n if (timer !== undefined) {\n clearTimeout(timer);\n }\n timer = undefined;\n lastArgs = undefined;\n lastThis = undefined;\n lastInvokeTime = 0;\n hasInvoked = false;\n };\n\n throttled.flush = (): ReturnType<F> | undefined => {\n if (timer !== undefined) {\n clearTimeout(timer);\n timer = undefined;\n if (lastArgs && trailing) {\n return invoke(Date.now());\n }\n }\n return result;\n };\n\n throttled.pending = (): boolean => timer !== undefined;\n\n return throttled;\n}\n\n/**\n * Create a function with one or more arguments already provided.\n * Later arguments are appended after the preset arguments.\n *\n * @example\n * ```ts\n * const sum = (a: number, b: number, c: number) => a + b + c;\n * const addFive = partial(sum, 2, 3);\n *\n * addFive(4); // 9\n * ```\n */\nexport function partial<F extends AnyFunction>(\n fn: F,\n ...presetArgs: unknown[]\n): (...laterArgs: unknown[]) => ReturnType<F> {\n return function (this: ThisParameterType<F>, ...laterArgs: unknown[]): ReturnType<F> {\n return fn.apply(this, [...presetArgs, ...laterArgs] as Parameters<F>);\n };\n}\n\n/**\n * Compose unary functions from left to right.\n * The first function receives the original arguments, and each next function receives the previous result.\n *\n * @example\n * ```ts\n * const transform = pipe(\n * (value: number) => value + 1,\n * (value: number) => value * 2,\n * );\n *\n * transform(2); // 6\n * ```\n */\nexport function pipe<A, B>(ab: Unary<A, B>): Unary<A, B>;\nexport function pipe<A, B, C>(ab: Unary<A, B>, bc: Unary<B, C>): Unary<A, C>;\nexport function pipe<A, B, C, D>(ab: Unary<A, B>, bc: Unary<B, C>, cd: Unary<C, D>): Unary<A, D>;\nexport function pipe<A, B, C, D, E>(ab: Unary<A, B>, bc: Unary<B, C>, cd: Unary<C, D>, de: Unary<D, E>): Unary<A, E>;\nexport function pipe(...fns: AnyFunction[]): AnyFunction {\n return createFlow(fns);\n}\n\n/**\n * Compose unary functions from right to left.\n * The rightmost function receives the original arguments, and each function to its left receives the previous result.\n *\n * @example\n * ```ts\n * const transform = compose(\n * (value: number) => value + 1,\n * (value: number) => value * 2,\n * );\n *\n * transform(2); // 5\n * ```\n */\nexport function compose<A, B>(ab: Unary<A, B>): Unary<A, B>;\nexport function compose<A, B, C>(bc: Unary<B, C>, ab: Unary<A, B>): Unary<A, C>;\nexport function compose<A, B, C, D>(cd: Unary<C, D>, bc: Unary<B, C>, ab: Unary<A, B>): Unary<A, D>;\nexport function compose<A, B, C, D, E>(de: Unary<D, E>, cd: Unary<C, D>, bc: Unary<B, C>, ab: Unary<A, B>): Unary<A, E>;\nexport function compose(...fns: AnyFunction[]): AnyFunction {\n return createFlow(fns.slice().reverse());\n}\n\nfunction createFlow(fns: AnyFunction[]): AnyFunction {\n if (fns.length === 0) return identity;\n\n return function (this: any, ...args: any[]): unknown {\n let result = fns[0].apply(this, args);\n for (let i = 1; i < fns.length; i++) {\n result = fns[i].call(this, result);\n }\n return result;\n };\n}\n\nfunction normalizeDelay(wait: number): number {\n return Number.isFinite(wait) ? Math.max(0, wait) : 0;\n}"]}
package/dist/cjs/index.js DELETED
@@ -1,84 +0,0 @@
1
- "use strict";
2
- // src/index.ts
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
- };
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.formToObject = exports.submitForm = exports.ajaxSubmission = exports.ajaxSubmit = exports.CleanURLSearchParams = exports.draft = exports.Range = exports.Event = exports.EventBus = exports.from = exports.Lazy = exports.KeyedDebouncer = exports.Debouncer = exports.AsyncPoolExecutor = exports.CountTrigger = exports.TimeTrigger = exports.Stopwatch = exports.TimeSpan = exports.Timer = exports.Order = exports.KeyValuePair = exports.CancellablePromise = exports.TypeCode = exports.Type = void 0;
22
- // ─── Types ───────────────────────────────────────────
23
- __exportStar(require("./types.js"), exports);
24
- var type_js_1 = require("./type.js");
25
- Object.defineProperty(exports, "Type", { enumerable: true, get: function () { return __importDefault(type_js_1).default; } });
26
- var type_code_js_1 = require("./type-code.js");
27
- Object.defineProperty(exports, "TypeCode", { enumerable: true, get: function () { return __importDefault(type_code_js_1).default; } });
28
- // ─── Utilities ───────────────────────────────────────
29
- __exportStar(require("./utilities.js"), exports);
30
- __exportStar(require("./functions.js"), exports);
31
- __exportStar(require("./string.js"), exports);
32
- __exportStar(require("./math.js"), exports);
33
- __exportStar(require("./parse.js"), exports);
34
- var cancellable_promise_js_1 = require("./cancellable-promise.js");
35
- Object.defineProperty(exports, "CancellablePromise", { enumerable: true, get: function () { return __importDefault(cancellable_promise_js_1).default; } });
36
- // ─── Data Structures ────────────────────────────────
37
- var key_value_pair_js_1 = require("./key-value-pair.js");
38
- Object.defineProperty(exports, "KeyValuePair", { enumerable: true, get: function () { return __importDefault(key_value_pair_js_1).default; } });
39
- var order_js_1 = require("./order.js");
40
- Object.defineProperty(exports, "Order", { enumerable: true, get: function () { return __importDefault(order_js_1).default; } });
41
- // ─── Async & Timing ─────────────────────────────────
42
- var timer_js_1 = require("./timer.js");
43
- Object.defineProperty(exports, "Timer", { enumerable: true, get: function () { return __importDefault(timer_js_1).default; } });
44
- var timespan_js_1 = require("./timespan.js");
45
- Object.defineProperty(exports, "TimeSpan", { enumerable: true, get: function () { return __importDefault(timespan_js_1).default; } });
46
- var stopwatch_js_1 = require("./stopwatch.js");
47
- Object.defineProperty(exports, "Stopwatch", { enumerable: true, get: function () { return __importDefault(stopwatch_js_1).default; } });
48
- var triggers_js_1 = require("./triggers.js");
49
- Object.defineProperty(exports, "TimeTrigger", { enumerable: true, get: function () { return triggers_js_1.TimeTrigger; } });
50
- Object.defineProperty(exports, "CountTrigger", { enumerable: true, get: function () { return triggers_js_1.CountTrigger; } });
51
- var async_pool_executor_js_1 = require("./async-pool-executor.js");
52
- Object.defineProperty(exports, "AsyncPoolExecutor", { enumerable: true, get: function () { return __importDefault(async_pool_executor_js_1).default; } });
53
- var debouncer_js_1 = require("./debouncer.js");
54
- Object.defineProperty(exports, "Debouncer", { enumerable: true, get: function () { return __importDefault(debouncer_js_1).default; } });
55
- var keyed_debouncer_js_1 = require("./keyed-debouncer.js");
56
- Object.defineProperty(exports, "KeyedDebouncer", { enumerable: true, get: function () { return __importDefault(keyed_debouncer_js_1).default; } });
57
- // ─── Patterns ────────────────────────────────────────
58
- var lazy_js_1 = require("./lazy.js");
59
- Object.defineProperty(exports, "Lazy", { enumerable: true, get: function () { return __importDefault(lazy_js_1).default; } });
60
- var from_js_1 = require("./collections/from.js");
61
- Object.defineProperty(exports, "from", { enumerable: true, get: function () { return __importDefault(from_js_1).default; } });
62
- var event_bus_js_1 = require("./event-bus.js");
63
- Object.defineProperty(exports, "EventBus", { enumerable: true, get: function () { return event_bus_js_1.EventBus; } });
64
- Object.defineProperty(exports, "Event", { enumerable: true, get: function () { return event_bus_js_1.Event; } });
65
- var range_js_1 = require("./range.js");
66
- Object.defineProperty(exports, "Range", { enumerable: true, get: function () { return __importDefault(range_js_1).default; } });
67
- // ─── Draft ────────────────────────────────────────
68
- var draft_js_1 = require("./draft.js");
69
- Object.defineProperty(exports, "draft", { enumerable: true, get: function () { return __importDefault(draft_js_1).default; } });
70
- // ─── Web ─────────────────────────────────────────────
71
- var clean_url_search_params_js_1 = require("./clean-url-search-params.js");
72
- Object.defineProperty(exports, "CleanURLSearchParams", { enumerable: true, get: function () { return __importDefault(clean_url_search_params_js_1).default; } });
73
- /** @deprecated */
74
- var index_js_1 = require("./browser/index.js");
75
- Object.defineProperty(exports, "ajaxSubmit", { enumerable: true, get: function () { return index_js_1.ajaxSubmit; } });
76
- Object.defineProperty(exports, "ajaxSubmission", { enumerable: true, get: function () { return index_js_1.ajaxSubmission; } });
77
- Object.defineProperty(exports, "submitForm", { enumerable: true, get: function () { return index_js_1.submitForm; } });
78
- Object.defineProperty(exports, "formToObject", { enumerable: true, get: function () { return index_js_1.formToObject; } });
79
- // ─── Deprecated ──────────────────────────────────────
80
- /** @deprecated */
81
- __exportStar(require("./array.js"), exports);
82
- /** @deprecated */
83
- __exportStar(require("./collections/index.js"), exports);
84
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,eAAe;;;;;;;;;;;;;;;;;;;;AAEf,wDAAwD;AACxD,6CAA2B;AAC3B,qCAA0C;AAAlC,gHAAA,OAAO,OAAQ;AACvB,+CAAmD;AAA3C,yHAAA,OAAO,OAAY;AAE3B,wDAAwD;AACxD,iDAA+B;AAC/B,iDAA+B;AAC/B,8CAA4B;AAC5B,4CAA0B;AAC1B,6CAA2B;AAC3B,mEAAuE;AAA/D,6IAAA,OAAO,OAAsB;AAErC,uDAAuD;AACvD,yDAA4D;AAApD,kIAAA,OAAO,OAAgB;AAC/B,uCAA4C;AAApC,kHAAA,OAAO,OAAS;AAExB,uDAAuD;AACvD,uCAA4C;AAApC,kHAAA,OAAO,OAAS;AACxB,6CAAkD;AAA1C,wHAAA,OAAO,OAAY;AAC3B,+CAAoD;AAA5C,0HAAA,OAAO,OAAa;AAE5B,6CAAwD;AAAhD,0GAAA,WAAW,OAAA;AAAE,2GAAA,YAAY,OAAA;AACjC,mEAAsE;AAA9D,4IAAA,OAAO,OAAqB;AACpC,+CAAoD;AAA5C,0HAAA,OAAO,OAAa;AAE5B,2DAA+D;AAAvD,qIAAA,OAAO,OAAkB;AAGjC,wDAAwD;AACxD,qCAA0C;AAAlC,gHAAA,OAAO,OAAQ;AACvB,iDAAsD;AAA9C,gHAAA,OAAO,OAAQ;AACvB,+CAA+C;AAAvC,wGAAA,QAAQ,OAAA;AAAE,qGAAA,KAAK,OAAA;AACvB,uCAA4C;AAApC,kHAAA,OAAO,OAAS;AAExB,qDAAqD;AACrD,uCAA4C;AAApC,kHAAA,OAAO,OAAS;AAExB,wDAAwD;AACxD,2EAA6E;AAArE,mJAAA,OAAO,OAAwB;AACvC,mBAAmB;AACnB,+CAAwF;AAAhF,sGAAA,UAAU,OAAA;AAAE,0GAAA,cAAc,OAAA;AAAE,sGAAA,UAAU,OAAA;AAAE,wGAAA,YAAY,OAAA;AAI5D,wDAAwD;AACxD,mBAAmB;AACnB,6CAA2B;AAC3B,mBAAmB;AACnB,yDAAuC","sourcesContent":["// src/index.ts\n\n// ─── Types ───────────────────────────────────────────\nexport * from './types.js';\nexport {default as Type} from './type.js';\nexport {default as TypeCode} from './type-code.js';\n\n// ─── Utilities ───────────────────────────────────────\nexport * from './utilities.js';\nexport * from './functions.js';\nexport * from './string.js';\nexport * from './math.js';\nexport * from './parse.js';\nexport {default as CancellablePromise} from \"./cancellable-promise.js\";\n\n// ─── Data Structures ────────────────────────────────\nexport {default as KeyValuePair} from './key-value-pair.js';\nexport {default as Order} from './order.js';\n\n// ─── Async & Timing ─────────────────────────────────\nexport {default as Timer} from './timer.js';\nexport {default as TimeSpan} from './timespan.js';\nexport {default as Stopwatch} from './stopwatch.js';\nexport type {Result} from './result.js';\nexport {TimeTrigger, CountTrigger} from './triggers.js';\nexport {default as AsyncPoolExecutor} from './async-pool-executor.js';\nexport {default as Debouncer} from './debouncer.js';\nexport type {DebouncedTask, DebouncerOptions} from './debouncer.js';\nexport {default as KeyedDebouncer} from './keyed-debouncer.js';\nexport type {KeyedDebouncerOptions} from './keyed-debouncer.js';\n\n// ─── Patterns ────────────────────────────────────────\nexport {default as Lazy} from './lazy.js';\nexport {default as from} from './collections/from.js';\nexport {EventBus, Event} from './event-bus.js';\nexport {default as Range} from './range.js';\n\n// ─── Draft ────────────────────────────────────────\nexport {default as draft} from './draft.js';\n\n// ─── Web ─────────────────────────────────────────────\nexport {default as CleanURLSearchParams} from './clean-url-search-params.js';\n/** @deprecated */\nexport {ajaxSubmit, ajaxSubmission, submitForm, formToObject} from './browser/index.js';\n\n\n\n// ─── Deprecated ──────────────────────────────────────\n/** @deprecated */\nexport * from './array.js';\n/** @deprecated */\nexport * from './collections/index.js';"]}
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * Represents a pair of key and value.
5
- *
6
- * @template TKey The type of the key.
7
- * @template TValue The type of the value.
8
- */
9
- class KeyValuePair {
10
- get value() {
11
- return this._value;
12
- }
13
- get key() {
14
- return this._key;
15
- }
16
- constructor(key, value) {
17
- this._key = key;
18
- this._value = value;
19
- }
20
- }
21
- exports.default = KeyValuePair;
22
- //# sourceMappingURL=key-value-pair.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"key-value-pair.js","sourceRoot":"","sources":["../../src/key-value-pair.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,MAAqB,YAAY;IAC7B,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,IAAI,GAAG;QACH,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAKD,YAAY,GAAS,EAAE,KAAa;QAChC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;CAGJ;AAlBD,+BAkBC","sourcesContent":["/**\n * Represents a pair of key and value.\n *\n * @template TKey The type of the key.\n * @template TValue The type of the value.\n */\nexport default class KeyValuePair<TKey, TValue> {\n get value(): TValue {\n return this._value;\n }\n\n get key(): TKey {\n return this._key;\n }\n\n private readonly _key: TKey;\n private readonly _value: TValue;\n\n constructor(key: TKey, value: TValue) {\n this._key = key;\n this._value = value;\n }\n\n\n}"]}
@@ -1,144 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
36
- if (kind === "m") throw new TypeError("Private method is not writable");
37
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
38
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
39
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
40
- };
41
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
42
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
43
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
44
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
45
- };
46
- var _KeyedDebouncer_instances, _KeyedDebouncer_debouncers, _KeyedDebouncer_delayMs, _KeyedDebouncer_onSchedule, _KeyedDebouncer_onStart, _KeyedDebouncer_onSuccess, _KeyedDebouncer_onCancel, _KeyedDebouncer_onError, _KeyedDebouncer_onIdle, _KeyedDebouncer_create;
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- const debouncer_js_1 = __importStar(require("./debouncer.js"));
49
- const functions_js_1 = require("./functions.js");
50
- /**
51
- * An independent {@link Debouncer} per key.
52
- * Debouncers only exist for keys with pending work: each one is created when
53
- * its first task is scheduled and removed as soon as it becomes idle.
54
- *
55
- * @example
56
- * ```ts
57
- * const debouncer = new KeyedDebouncer<string>({delayMs: 1500});
58
- *
59
- * debouncer.schedule(chatId, async (signal) => {
60
- * const pending = await store.getPending(chatId);
61
- * const reply = await callAI(pending, {signal});
62
- * if (signal.aborted) return;
63
- * await sendReply(chatId, reply);
64
- * });
65
- * ```
66
- */
67
- class KeyedDebouncer {
68
- constructor(options) {
69
- _KeyedDebouncer_instances.add(this);
70
- _KeyedDebouncer_debouncers.set(this, new Map());
71
- _KeyedDebouncer_delayMs.set(this, void 0);
72
- _KeyedDebouncer_onSchedule.set(this, void 0);
73
- _KeyedDebouncer_onStart.set(this, void 0);
74
- _KeyedDebouncer_onSuccess.set(this, void 0);
75
- _KeyedDebouncer_onCancel.set(this, void 0);
76
- _KeyedDebouncer_onError.set(this, void 0);
77
- _KeyedDebouncer_onIdle.set(this, void 0);
78
- (0, debouncer_js_1.assertValidDelay)(options.delayMs);
79
- __classPrivateFieldSet(this, _KeyedDebouncer_delayMs, options.delayMs, "f");
80
- __classPrivateFieldSet(this, _KeyedDebouncer_onSchedule, options.onSchedule ?? functions_js_1.noop, "f");
81
- __classPrivateFieldSet(this, _KeyedDebouncer_onStart, options.onStart ?? functions_js_1.noop, "f");
82
- __classPrivateFieldSet(this, _KeyedDebouncer_onSuccess, options.onSuccess ?? functions_js_1.noop, "f");
83
- __classPrivateFieldSet(this, _KeyedDebouncer_onCancel, options.onCancel ?? functions_js_1.noop, "f");
84
- __classPrivateFieldSet(this, _KeyedDebouncer_onError, options.onError ?? console.error, "f");
85
- __classPrivateFieldSet(this, _KeyedDebouncer_onIdle, options.onIdle ?? functions_js_1.noop, "f");
86
- }
87
- /** Number of keys with a task waiting or running. */
88
- get size() {
89
- return __classPrivateFieldGet(this, _KeyedDebouncer_debouncers, "f").size;
90
- }
91
- /**
92
- * Schedule `task` for `key`, cancelling any previous task of that key.
93
- *
94
- * @param key - The key whose task is replaced.
95
- * @param task - The task to run once the delay elapses.
96
- * @param delayMs - Wait for this task only. Defaults to the configured `delayMs`.
97
- */
98
- schedule(key, task, delayMs) {
99
- const existing = __classPrivateFieldGet(this, _KeyedDebouncer_debouncers, "f").get(key);
100
- if (existing !== undefined) {
101
- existing.schedule(task, delayMs);
102
- return;
103
- }
104
- // Validate first so an invalid delay never registers the key.
105
- (0, debouncer_js_1.assertValidDelay)(delayMs ?? __classPrivateFieldGet(this, _KeyedDebouncer_delayMs, "f"));
106
- const debouncer = __classPrivateFieldGet(this, _KeyedDebouncer_instances, "m", _KeyedDebouncer_create).call(this, key);
107
- __classPrivateFieldGet(this, _KeyedDebouncer_debouncers, "f").set(key, debouncer);
108
- debouncer.schedule(task, delayMs);
109
- }
110
- /** Cancel the task of `key`, if any. */
111
- cancel(key) {
112
- __classPrivateFieldGet(this, _KeyedDebouncer_debouncers, "f").get(key)?.cancel();
113
- }
114
- /** Cancel every task. Useful when shutting the process down. */
115
- cancelAll() {
116
- // Copy first: cancelling removes the debouncer from the map.
117
- for (const debouncer of [...__classPrivateFieldGet(this, _KeyedDebouncer_debouncers, "f").values()]) {
118
- debouncer.cancel();
119
- }
120
- }
121
- /** Whether a task is waiting or running for `key`. */
122
- isPending(key) {
123
- return __classPrivateFieldGet(this, _KeyedDebouncer_debouncers, "f").has(key);
124
- }
125
- }
126
- _KeyedDebouncer_debouncers = new WeakMap(), _KeyedDebouncer_delayMs = new WeakMap(), _KeyedDebouncer_onSchedule = new WeakMap(), _KeyedDebouncer_onStart = new WeakMap(), _KeyedDebouncer_onSuccess = new WeakMap(), _KeyedDebouncer_onCancel = new WeakMap(), _KeyedDebouncer_onError = new WeakMap(), _KeyedDebouncer_onIdle = new WeakMap(), _KeyedDebouncer_instances = new WeakSet(), _KeyedDebouncer_create = function _KeyedDebouncer_create(key) {
127
- const debouncer = new debouncer_js_1.default({
128
- delayMs: __classPrivateFieldGet(this, _KeyedDebouncer_delayMs, "f"),
129
- onSchedule: () => __classPrivateFieldGet(this, _KeyedDebouncer_onSchedule, "f").call(this, key),
130
- onStart: () => __classPrivateFieldGet(this, _KeyedDebouncer_onStart, "f").call(this, key),
131
- onSuccess: () => __classPrivateFieldGet(this, _KeyedDebouncer_onSuccess, "f").call(this, key),
132
- onCancel: () => __classPrivateFieldGet(this, _KeyedDebouncer_onCancel, "f").call(this, key),
133
- onError: (error) => __classPrivateFieldGet(this, _KeyedDebouncer_onError, "f").call(this, error, key),
134
- onIdle: () => {
135
- if (__classPrivateFieldGet(this, _KeyedDebouncer_debouncers, "f").get(key) === debouncer) {
136
- __classPrivateFieldGet(this, _KeyedDebouncer_debouncers, "f").delete(key);
137
- __classPrivateFieldGet(this, _KeyedDebouncer_onIdle, "f").call(this, key);
138
- }
139
- },
140
- });
141
- return debouncer;
142
- };
143
- exports.default = KeyedDeb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AW,MAAf,IAAI,EAAY,GAAG,CAAC;QACrC,QAAQ,EAAE,GAAG,EAAE,CAAC,uBAAA,IAAI,gCAAU,MAAd,IAAI,EAAW,GAAG,CAAC;QACnC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,uBAAA,IAAI,+BAAS,MAAb,IAAI,EAAU,KAAK,EAAE,GAAG,CAAC;QAC7C,MAAM,EAAE,GAAG,EAAE;YACT,IAAI,uBAAA,IAAI,kCAAY,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;gBAC1C,uBAAA,IAAI,kCAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC7B,uBAAA,IAAI,8BAAQ,MAAZ,IAAI,EAAS,GAAG,CAAC,CAAC;YACtB,CAAC;QACL,CAAC;KACJ,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACrB,CAAC;kBAjFgB,cAAc","sourcesContent":["import Debouncer, {assertValidDelay, type DebouncedTask} from \"./debouncer.js\";\nimport {noop} from \"./functions.js\";\n\n/** Options accepted by {@link KeyedDebouncer}. Every callback receives the affected key. */\nexport interface KeyedDebouncerOptions<K> {\n /** Default wait, in milliseconds, before a task is executed. */\n delayMs: number;\n /** Called every time a task is scheduled for `key`, after any previous task of that key has been cancelled. */\n onSchedule?: (key: K) => void;\n /** Called when the wait elapses and the task of `key` is about to run. */\n onStart?: (key: K) => void;\n /** Called when the task of `key` completes without throwing and without being cancelled. */\n onSuccess?: (key: K) => void;\n /** Called when a live task of `key` is cancelled, either explicitly or by being replaced. */\n onCancel?: (key: K) => void;\n /** Receives task errors. Cancellations never reach this callback. Defaults to `console.error`. */\n onError?: (error: unknown, key: K) => void;\n /** Called when `key` has no more pending work, after it has been removed from the debouncer. */\n onIdle?: (key: K) => void;\n}\n\n/**\n * An independent {@link Debouncer} per key.\n * Debouncers only exist for keys with pending work: each one is created when\n * its first task is scheduled and removed as soon as it becomes idle.\n *\n * @example\n * ```ts\n * const debouncer = new KeyedDebouncer<string>({delayMs: 1500});\n *\n * debouncer.schedule(chatId, async (signal) => {\n * const pending = await store.getPending(chatId);\n * const reply = await callAI(pending, {signal});\n * if (signal.aborted) return;\n * await sendReply(chatId, reply);\n * });\n * ```\n */\nexport default class KeyedDebouncer<K = string> {\n readonly #debouncers = new Map<K, Debouncer>();\n readonly #delayMs: number;\n readonly #onSchedule: (key: K) => void;\n readonly #onStart: (key: K) => void;\n readonly #onSuccess: (key: K) => void;\n readonly #onCancel: (key: K) => void;\n readonly #onError: (error: unknown, key: K) => void;\n readonly #onIdle: (key: K) => void;\n\n constructor(options: KeyedDebouncerOptions<K>) {\n assertValidDelay(options.delayMs);\n this.#delayMs = options.delayMs;\n this.#onSchedule = options.onSchedule ?? noop;\n this.#onStart = options.onStart ?? noop;\n this.#onSuccess = options.onSuccess ?? noop;\n this.#onCancel = options.onCancel ?? noop;\n this.#onError = options.onError ?? console.error;\n this.#onIdle = options.onIdle ?? noop;\n }\n\n /** Number of keys with a task waiting or running. */\n get size(): number {\n return this.#debouncers.size;\n }\n\n /**\n * Schedule `task` for `key`, cancelling any previous task of that key.\n *\n * @param key - The key whose task is replaced.\n * @param task - The task to run once the delay elapses.\n * @param delayMs - Wait for this task only. Defaults to the configured `delayMs`.\n */\n schedule(key: K, task: DebouncedTask, delayMs?: number): void {\n const existing = this.#debouncers.get(key);\n if (existing !== undefined) {\n existing.schedule(task, delayMs);\n return;\n }\n\n // Validate first so an invalid delay never registers the key.\n assertValidDelay(delayMs ?? this.#delayMs);\n const debouncer = this.#create(key);\n this.#debouncers.set(key, debouncer);\n debouncer.schedule(task, delayMs);\n }\n\n /** Cancel the task of `key`, if any. */\n cancel(key: K): void {\n this.#debouncers.get(key)?.cancel();\n }\n\n /** Cancel every task. Useful when shutting the process down. */\n cancelAll(): void {\n // Copy first: cancelling removes the debouncer from the map.\n for (const debouncer of [...this.#debouncers.values()]) {\n debouncer.cancel();\n }\n }\n\n /** Whether a task is waiting or running for `key`. */\n isPending(key: K): boolean {\n return this.#debouncers.has(key);\n }\n\n #create(key: K): Debouncer {\n const debouncer: Debouncer = new Debouncer({\n delayMs: this.#delayMs,\n onSchedule: () => this.#onSchedule(key),\n onStart: () => this.#onStart(key),\n onSuccess: () => this.#onSuccess(key),\n onCancel: () => this.#onCancel(key),\n onError: (error) => this.#onError(error, key),\n onIdle: () => {\n if (this.#debouncers.get(key) === debouncer) {\n this.#debouncers.delete(key);\n this.#onIdle(key);\n }\n },\n });\n return debouncer;\n }\n}\n"]}
package/dist/cjs/lazy.js DELETED
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * Represents a lazy value that is created only when it is accessed for the first time.
5
- * @template T The type of the lazy value.
6
- */
7
- class Lazy {
8
- constructor(getter) {
9
- this._valueCreated = false;
10
- this._value = null;
11
- this._factoryMethod = getter;
12
- }
13
- get valueCreated() {
14
- return this._valueCreated;
15
- }
16
- get value() {
17
- if (!this._valueCreated) {
18
- this._value = this._factoryMethod();
19
- this._valueCreated = true;
20
- }
21
- return this._value;
22
- }
23
- reset() {
24
- this._valueCreated = false;
25
- this._value = null;
26
- }
27
- }
28
- exports.default = Lazy;
29
- //# sourceMappingURL=lazy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lazy.js","sourceRoot":"","sources":["../../src/lazy.ts"],"names":[],"mappings":";;AAGA;;;GAGG;AACH,MAAqB,IAAI;IAKrB,YAAY,MAAmB;QAJvB,kBAAa,GAAG,KAAK,CAAC;QACtB,WAAM,GAAgB,IAAI,CAAC;QAI/B,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC;IACjC,CAAC;IAED,IAAI,YAAY;QACZ,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IAED,IAAW,KAAK;QACZ,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YACpC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC9B,CAAC;QACD,OAAO,IAAI,CAAC,MAAW,CAAC;IAC5B,CAAC;IAED,KAAK;QACD,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;CACJ;AAzBD,uBAyBC","sourcesContent":["import type {Nullable, Supplier} from \"./types.js\";\n\n\n/**\n * Represents a lazy value that is created only when it is accessed for the first time.\n * @template T The type of the lazy value.\n */\nexport default class Lazy<T> {\n private _valueCreated = false;\n private _value: Nullable<T> = null;\n private readonly _factoryMethod: Supplier<T>;\n\n constructor(getter: Supplier<T>) {\n this._factoryMethod = getter;\n }\n\n get valueCreated(): boolean {\n return this._valueCreated;\n }\n\n public get value(): T {\n if (!this._valueCreated) {\n this._value = this._factoryMethod();\n this._valueCreated = true;\n }\n return this._value as T;\n }\n\n reset(): void {\n this._valueCreated = false;\n this._value = null;\n }\n}"]}
package/dist/cjs/math.js DELETED
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lerp = lerp;
4
- exports.clamp = clamp;
5
- /**
6
- * Linearly interpolates a number between two ranges.
7
- *
8
- * @param {number} n - The number to interpolate.
9
- * @param {number} inMin - The minimum value of the input range.
10
- * @param {number} inMax - The maximum value of the input range.
11
- * @param {number} outMin - The minimum value of the output range.
12
- * @param {number} outMax - The maximum value of the output range.
13
- *
14
- * @return {number} - The interpolated value.
15
- */
16
- function lerp(n, inMin, inMax, outMin, outMax) {
17
- if (inMax === inMin) {
18
- throw new Error("Input range cannot be zero");
19
- }
20
- return outMin + (outMax - outMin) * ((n - inMin) / (inMax - inMin));
21
- }
22
- /**
23
- * Clamps a number between a minimum and maximum value.
24
- *
25
- * @param {number} n - The value to be clamped.
26
- * @param {number} min - The minimum value.
27
- * @param {number} max - The maximum value.
28
- * @return {number} The clamped value.
29
- */
30
- function clamp(n, min, max) {
31
- if (n <= min)
32
- return min;
33
- if (n >= max)
34
- return max;
35
- return n;
36
- }
37
- //# sourceMappingURL=math.js.map