yummies 5.4.5 → 5.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (516) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/config.json +11 -0
  3. package/.github/FUNDING.yml +1 -0
  4. package/.github/workflows/main.yml +34 -0
  5. package/.github/workflows/version-or-publish.yml +45 -0
  6. package/.nvmrc +1 -0
  7. package/.vscode/settings.json +19 -0
  8. package/CHANGELOG.md +215 -0
  9. package/CONTRIBUTING.md +8 -0
  10. package/Makefile +7 -0
  11. package/assets/logo.png +0 -0
  12. package/assets/logo.pxz +0 -0
  13. package/biome.json +3 -0
  14. package/commitfmt.toml +18 -0
  15. package/lefthook.yml +14 -0
  16. package/package.json +3 -389
  17. package/scripts/post-build.ts +71 -0
  18. package/src/async.ts +86 -0
  19. package/src/common.ts +26 -0
  20. package/src/complex/counter.test.ts +41 -0
  21. package/src/complex/counter.ts +40 -0
  22. package/src/complex/global-config.ts +55 -0
  23. package/src/complex/index.ts +3 -0
  24. package/src/complex/modules-factory.ts +65 -0
  25. package/src/cookie.ts +11 -0
  26. package/src/css.ts +60 -0
  27. package/src/data.test.ts +99 -0
  28. package/src/data.ts +65 -0
  29. package/src/date-time.test.ts +119 -0
  30. package/src/date-time.ts +236 -0
  31. package/src/device.ts +42 -0
  32. package/src/encodings.ts +270 -0
  33. package/src/errors.ts +40 -0
  34. package/src/file.ts +25 -0
  35. package/src/format/_exports.ts +4 -0
  36. package/{dist/format/constants.js → src/format/constants.ts} +2 -0
  37. package/{dist/format/index.js → src/format/index.ts} +2 -1
  38. package/src/format/number.test.ts +16 -0
  39. package/src/format/number.ts +96 -0
  40. package/src/format/percent.ts +40 -0
  41. package/src/format/skip-spaces.ts +4 -0
  42. package/src/html.ts +238 -0
  43. package/{dist/id.js → src/id.ts} +16 -6
  44. package/src/imports.ts +52 -0
  45. package/src/math.ts +20 -0
  46. package/src/media.ts +134 -0
  47. package/src/mobx/apply-observable.ts +20 -0
  48. package/src/mobx/create-enhanced-atom.ts +28 -0
  49. package/src/mobx/deep-observable-struct.test.ts +69 -0
  50. package/src/mobx/deep-observable-struct.ts +69 -0
  51. package/src/mobx/get-mobx-administration.ts +10 -0
  52. package/src/mobx/index.ts +5 -0
  53. package/src/mobx/lazy-observe.ts +59 -0
  54. package/src/ms.ts +20 -0
  55. package/src/number.ts +14 -0
  56. package/src/parser/_exports.ts +3 -0
  57. package/{dist/parser/index.js → src/parser/index.ts} +2 -1
  58. package/src/parser/number.test.ts +38 -0
  59. package/src/parser/number.ts +73 -0
  60. package/src/parser/percent.ts +11 -0
  61. package/src/parser/string.ts +29 -0
  62. package/src/price.ts +33 -0
  63. package/src/random.ts +27 -0
  64. package/src/react/hooks/index.ts +21 -0
  65. package/src/react/hooks/use-abort-controller.ts +15 -0
  66. package/src/react/hooks/use-abort-signal.ts +5 -0
  67. package/src/react/hooks/use-click-outside.ts +27 -0
  68. package/{dist/react/hooks/use-constant.js → src/react/hooks/use-constant.ts} +9 -6
  69. package/{dist/react/hooks/use-define-ref.js → src/react/hooks/use-define-ref.ts} +10 -7
  70. package/src/react/hooks/use-element-ref.ts +11 -0
  71. package/src/react/hooks/use-event-listener.ts +29 -0
  72. package/src/react/hooks/use-event.ts +23 -0
  73. package/src/react/hooks/use-flag.ts +27 -0
  74. package/src/react/hooks/use-force-update.ts +9 -0
  75. package/src/react/hooks/use-initial-height.ts +16 -0
  76. package/{dist/react/hooks/use-instance.js → src/react/hooks/use-instance.ts} +31 -9
  77. package/src/react/hooks/use-intersection-observer.ts +18 -0
  78. package/src/react/hooks/use-last-defined-value.ts +9 -0
  79. package/src/react/hooks/use-last-value-ref.ts +11 -0
  80. package/src/react/hooks/use-life-cycle.ts +17 -0
  81. package/src/react/hooks/use-resize-observer.ts +14 -0
  82. package/src/react/hooks/use-sync-ref.ts +7 -0
  83. package/src/react/hooks/use-toggle.ts +9 -0
  84. package/src/react/hooks/use-value.ts +10 -0
  85. package/src/react/hooks/use-visibility-state.ts +19 -0
  86. package/src/react/index.ts +1 -0
  87. package/src/sound.ts +15 -0
  88. package/src/storage.ts +137 -0
  89. package/src/text.test.ts +91 -0
  90. package/src/text.ts +60 -0
  91. package/src/type-guard/_exports.ts +154 -0
  92. package/src/type-guard/index.test.ts +127 -0
  93. package/{dist/type-guard/index.js → src/type-guard/index.ts} +2 -1
  94. package/src/vibrate.ts +8 -0
  95. package/tsconfig.json +26 -0
  96. package/tsconfig.test.json +33 -0
  97. package/vitest.config.ts +20 -0
  98. package/dist/async.cjs +0 -70
  99. package/dist/async.d.cts +0 -28
  100. package/dist/async.d.cts.map +0 -1
  101. package/dist/async.d.ts +0 -28
  102. package/dist/async.d.ts.map +0 -1
  103. package/dist/async.js +0 -62
  104. package/dist/common.cjs +0 -18
  105. package/dist/common.d.cts +0 -15
  106. package/dist/common.d.cts.map +0 -1
  107. package/dist/common.d.ts +0 -15
  108. package/dist/common.d.ts.map +0 -1
  109. package/dist/common.js +0 -14
  110. package/dist/complex/counter.cjs +0 -21
  111. package/dist/complex/counter.d.cts +0 -15
  112. package/dist/complex/counter.d.cts.map +0 -1
  113. package/dist/complex/counter.d.ts +0 -15
  114. package/dist/complex/counter.d.ts.map +0 -1
  115. package/dist/complex/counter.js +0 -17
  116. package/dist/complex/global-config.cjs +0 -46
  117. package/dist/complex/global-config.d.cts +0 -11
  118. package/dist/complex/global-config.d.cts.map +0 -1
  119. package/dist/complex/global-config.d.ts +0 -11
  120. package/dist/complex/global-config.d.ts.map +0 -1
  121. package/dist/complex/global-config.js +0 -41
  122. package/dist/complex/index.cjs +0 -19
  123. package/dist/complex/index.d.cts +0 -4
  124. package/dist/complex/index.d.cts.map +0 -1
  125. package/dist/complex/index.d.ts +0 -4
  126. package/dist/complex/index.d.ts.map +0 -1
  127. package/dist/complex/index.js +0 -3
  128. package/dist/complex/modules-factory.cjs +0 -50
  129. package/dist/complex/modules-factory.d.cts +0 -49
  130. package/dist/complex/modules-factory.d.cts.map +0 -1
  131. package/dist/complex/modules-factory.d.ts +0 -49
  132. package/dist/complex/modules-factory.d.ts.map +0 -1
  133. package/dist/complex/modules-factory.js +0 -46
  134. package/dist/cookie.cjs +0 -13
  135. package/dist/cookie.d.cts +0 -3
  136. package/dist/cookie.d.cts.map +0 -1
  137. package/dist/cookie.d.ts +0 -3
  138. package/dist/cookie.d.ts.map +0 -1
  139. package/dist/cookie.js +0 -9
  140. package/dist/css.cjs +0 -28
  141. package/dist/css.d.cts +0 -36
  142. package/dist/css.d.cts.map +0 -1
  143. package/dist/css.d.ts +0 -36
  144. package/dist/css.d.ts.map +0 -1
  145. package/dist/css.js +0 -20
  146. package/dist/data.cjs +0 -58
  147. package/dist/data.d.cts +0 -4
  148. package/dist/data.d.cts.map +0 -1
  149. package/dist/data.d.ts +0 -4
  150. package/dist/data.d.ts.map +0 -1
  151. package/dist/data.js +0 -52
  152. package/dist/date-time.cjs +0 -171
  153. package/dist/date-time.d.cts +0 -28
  154. package/dist/date-time.d.cts.map +0 -1
  155. package/dist/date-time.d.ts +0 -28
  156. package/dist/date-time.d.ts.map +0 -1
  157. package/dist/date-time.js +0 -160
  158. package/dist/device.cjs +0 -28
  159. package/dist/device.d.cts +0 -8
  160. package/dist/device.d.cts.map +0 -1
  161. package/dist/device.d.ts +0 -8
  162. package/dist/device.d.ts.map +0 -1
  163. package/dist/device.js +0 -21
  164. package/dist/encodings.cjs +0 -270
  165. package/dist/encodings.d.cts +0 -2
  166. package/dist/encodings.d.cts.map +0 -1
  167. package/dist/encodings.d.ts +0 -2
  168. package/dist/encodings.d.ts.map +0 -1
  169. package/dist/encodings.js +0 -267
  170. package/dist/errors.cjs +0 -34
  171. package/dist/errors.d.cts +0 -19
  172. package/dist/errors.d.cts.map +0 -1
  173. package/dist/errors.d.ts +0 -19
  174. package/dist/errors.d.ts.map +0 -1
  175. package/dist/errors.js +0 -30
  176. package/dist/file.cjs +0 -29
  177. package/dist/file.d.cts +0 -3
  178. package/dist/file.d.cts.map +0 -1
  179. package/dist/file.d.ts +0 -3
  180. package/dist/file.d.ts.map +0 -1
  181. package/dist/file.js +0 -24
  182. package/dist/format/_exports.cjs +0 -20
  183. package/dist/format/_exports.d.cts +0 -5
  184. package/dist/format/_exports.d.cts.map +0 -1
  185. package/dist/format/_exports.d.ts +0 -5
  186. package/dist/format/_exports.d.ts.map +0 -1
  187. package/dist/format/_exports.js +0 -4
  188. package/dist/format/constants.cjs +0 -6
  189. package/dist/format/constants.d.cts +0 -4
  190. package/dist/format/constants.d.cts.map +0 -1
  191. package/dist/format/constants.d.ts +0 -4
  192. package/dist/format/constants.d.ts.map +0 -1
  193. package/dist/format/index.cjs +0 -40
  194. package/dist/format/index.d.cts +0 -3
  195. package/dist/format/index.d.cts.map +0 -1
  196. package/dist/format/index.d.ts +0 -3
  197. package/dist/format/index.d.ts.map +0 -1
  198. package/dist/format/number.cjs +0 -48
  199. package/dist/format/number.d.cts +0 -36
  200. package/dist/format/number.d.cts.map +0 -1
  201. package/dist/format/number.d.ts +0 -36
  202. package/dist/format/number.d.ts.map +0 -1
  203. package/dist/format/number.js +0 -44
  204. package/dist/format/percent.cjs +0 -27
  205. package/dist/format/percent.d.cts +0 -15
  206. package/dist/format/percent.d.cts.map +0 -1
  207. package/dist/format/percent.d.ts +0 -15
  208. package/dist/format/percent.d.ts.map +0 -1
  209. package/dist/format/percent.js +0 -23
  210. package/dist/format/skip-spaces.cjs +0 -8
  211. package/dist/format/skip-spaces.d.cts +0 -5
  212. package/dist/format/skip-spaces.d.cts.map +0 -1
  213. package/dist/format/skip-spaces.d.ts +0 -5
  214. package/dist/format/skip-spaces.d.ts.map +0 -1
  215. package/dist/format/skip-spaces.js +0 -4
  216. package/dist/html.cjs +0 -202
  217. package/dist/html.d.cts +0 -44
  218. package/dist/html.d.cts.map +0 -1
  219. package/dist/html.d.ts +0 -44
  220. package/dist/html.d.ts.map +0 -1
  221. package/dist/html.js +0 -182
  222. package/dist/id.cjs +0 -76
  223. package/dist/id.d.cts +0 -63
  224. package/dist/id.d.cts.map +0 -1
  225. package/dist/id.d.ts +0 -63
  226. package/dist/id.d.ts.map +0 -1
  227. package/dist/imports.cjs +0 -45
  228. package/dist/imports.d.cts +0 -15
  229. package/dist/imports.d.cts.map +0 -1
  230. package/dist/imports.d.ts +0 -15
  231. package/dist/imports.d.ts.map +0 -1
  232. package/dist/imports.js +0 -40
  233. package/dist/math.cjs +0 -23
  234. package/dist/math.d.cts +0 -13
  235. package/dist/math.d.cts.map +0 -1
  236. package/dist/math.d.ts +0 -13
  237. package/dist/math.d.ts.map +0 -1
  238. package/dist/math.js +0 -17
  239. package/dist/media.cjs +0 -115
  240. package/dist/media.d.cts +0 -20
  241. package/dist/media.d.cts.map +0 -1
  242. package/dist/media.d.ts +0 -20
  243. package/dist/media.d.ts.map +0 -1
  244. package/dist/media.js +0 -103
  245. package/dist/mobx/apply-observable.cjs +0 -16
  246. package/dist/mobx/apply-observable.d.cts +0 -4
  247. package/dist/mobx/apply-observable.d.cts.map +0 -1
  248. package/dist/mobx/apply-observable.d.ts +0 -4
  249. package/dist/mobx/apply-observable.d.ts.map +0 -1
  250. package/dist/mobx/apply-observable.js +0 -12
  251. package/dist/mobx/create-enhanced-atom.cjs +0 -16
  252. package/dist/mobx/create-enhanced-atom.d.cts +0 -11
  253. package/dist/mobx/create-enhanced-atom.d.cts.map +0 -1
  254. package/dist/mobx/create-enhanced-atom.d.ts +0 -11
  255. package/dist/mobx/create-enhanced-atom.d.ts.map +0 -1
  256. package/dist/mobx/create-enhanced-atom.js +0 -12
  257. package/dist/mobx/deep-observable-struct.cjs +0 -61
  258. package/dist/mobx/deep-observable-struct.d.cts +0 -7
  259. package/dist/mobx/deep-observable-struct.d.cts.map +0 -1
  260. package/dist/mobx/deep-observable-struct.d.ts +0 -7
  261. package/dist/mobx/deep-observable-struct.d.ts.map +0 -1
  262. package/dist/mobx/deep-observable-struct.js +0 -57
  263. package/dist/mobx/get-mobx-administration.cjs +0 -6
  264. package/dist/mobx/get-mobx-administration.d.cts +0 -6
  265. package/dist/mobx/get-mobx-administration.d.cts.map +0 -1
  266. package/dist/mobx/get-mobx-administration.d.ts +0 -6
  267. package/dist/mobx/get-mobx-administration.d.ts.map +0 -1
  268. package/dist/mobx/get-mobx-administration.js +0 -2
  269. package/dist/mobx/index.cjs +0 -21
  270. package/dist/mobx/index.d.cts +0 -6
  271. package/dist/mobx/index.d.cts.map +0 -1
  272. package/dist/mobx/index.d.ts +0 -6
  273. package/dist/mobx/index.d.ts.map +0 -1
  274. package/dist/mobx/index.js +0 -5
  275. package/dist/mobx/lazy-observe.cjs +0 -47
  276. package/dist/mobx/lazy-observe.d.cts +0 -8
  277. package/dist/mobx/lazy-observe.d.cts.map +0 -1
  278. package/dist/mobx/lazy-observe.d.ts +0 -8
  279. package/dist/mobx/lazy-observe.d.ts.map +0 -1
  280. package/dist/mobx/lazy-observe.js +0 -43
  281. package/dist/ms.cjs +0 -22
  282. package/dist/ms.d.cts +0 -19
  283. package/dist/ms.d.cts.map +0 -1
  284. package/dist/ms.d.ts +0 -19
  285. package/dist/ms.d.ts.map +0 -1
  286. package/dist/ms.js +0 -18
  287. package/dist/number.cjs +0 -16
  288. package/dist/number.d.cts +0 -8
  289. package/dist/number.d.cts.map +0 -1
  290. package/dist/number.d.ts +0 -8
  291. package/dist/number.d.ts.map +0 -1
  292. package/dist/number.js +0 -13
  293. package/dist/parser/_exports.cjs +0 -19
  294. package/dist/parser/_exports.d.cts +0 -4
  295. package/dist/parser/_exports.d.cts.map +0 -1
  296. package/dist/parser/_exports.d.ts +0 -4
  297. package/dist/parser/_exports.d.ts.map +0 -1
  298. package/dist/parser/_exports.js +0 -3
  299. package/dist/parser/index.cjs +0 -40
  300. package/dist/parser/index.d.cts +0 -3
  301. package/dist/parser/index.d.cts.map +0 -1
  302. package/dist/parser/index.d.ts +0 -3
  303. package/dist/parser/index.d.ts.map +0 -1
  304. package/dist/parser/number.cjs +0 -48
  305. package/dist/parser/number.d.cts +0 -21
  306. package/dist/parser/number.d.cts.map +0 -1
  307. package/dist/parser/number.d.ts +0 -21
  308. package/dist/parser/number.d.ts.map +0 -1
  309. package/dist/parser/number.js +0 -44
  310. package/dist/parser/percent.cjs +0 -8
  311. package/dist/parser/percent.d.cts +0 -4
  312. package/dist/parser/percent.d.cts.map +0 -1
  313. package/dist/parser/percent.d.ts +0 -4
  314. package/dist/parser/percent.d.ts.map +0 -1
  315. package/dist/parser/percent.js +0 -4
  316. package/dist/parser/string.cjs +0 -18
  317. package/dist/parser/string.d.cts +0 -7
  318. package/dist/parser/string.d.cts.map +0 -1
  319. package/dist/parser/string.d.ts +0 -7
  320. package/dist/parser/string.d.ts.map +0 -1
  321. package/dist/parser/string.js +0 -14
  322. package/dist/price.cjs +0 -21
  323. package/dist/price.d.cts +0 -6
  324. package/dist/price.d.cts.map +0 -1
  325. package/dist/price.d.ts +0 -6
  326. package/dist/price.d.ts.map +0 -1
  327. package/dist/price.js +0 -17
  328. package/dist/random.cjs +0 -25
  329. package/dist/random.d.cts +0 -9
  330. package/dist/random.d.cts.map +0 -1
  331. package/dist/random.d.ts +0 -9
  332. package/dist/random.d.ts.map +0 -1
  333. package/dist/random.js +0 -14
  334. package/dist/react/hooks/index.cjs +0 -37
  335. package/dist/react/hooks/index.d.cts +0 -22
  336. package/dist/react/hooks/index.d.cts.map +0 -1
  337. package/dist/react/hooks/index.d.ts +0 -22
  338. package/dist/react/hooks/index.d.ts.map +0 -1
  339. package/dist/react/hooks/index.js +0 -21
  340. package/dist/react/hooks/use-abort-controller.cjs +0 -15
  341. package/dist/react/hooks/use-abort-controller.d.cts +0 -2
  342. package/dist/react/hooks/use-abort-controller.d.cts.map +0 -1
  343. package/dist/react/hooks/use-abort-controller.d.ts +0 -2
  344. package/dist/react/hooks/use-abort-controller.d.ts.map +0 -1
  345. package/dist/react/hooks/use-abort-controller.js +0 -11
  346. package/dist/react/hooks/use-abort-signal.cjs +0 -8
  347. package/dist/react/hooks/use-abort-signal.d.cts +0 -2
  348. package/dist/react/hooks/use-abort-signal.d.cts.map +0 -1
  349. package/dist/react/hooks/use-abort-signal.d.ts +0 -2
  350. package/dist/react/hooks/use-abort-signal.d.ts.map +0 -1
  351. package/dist/react/hooks/use-abort-signal.js +0 -4
  352. package/dist/react/hooks/use-click-outside.cjs +0 -17
  353. package/dist/react/hooks/use-click-outside.d.cts +0 -9
  354. package/dist/react/hooks/use-click-outside.d.cts.map +0 -1
  355. package/dist/react/hooks/use-click-outside.d.ts +0 -9
  356. package/dist/react/hooks/use-click-outside.d.ts.map +0 -1
  357. package/dist/react/hooks/use-click-outside.js +0 -13
  358. package/dist/react/hooks/use-constant.cjs +0 -19
  359. package/dist/react/hooks/use-constant.d.cts +0 -9
  360. package/dist/react/hooks/use-constant.d.cts.map +0 -1
  361. package/dist/react/hooks/use-constant.d.ts +0 -9
  362. package/dist/react/hooks/use-constant.d.ts.map +0 -1
  363. package/dist/react/hooks/use-define-ref.cjs +0 -19
  364. package/dist/react/hooks/use-define-ref.d.cts +0 -10
  365. package/dist/react/hooks/use-define-ref.d.cts.map +0 -1
  366. package/dist/react/hooks/use-define-ref.d.ts +0 -10
  367. package/dist/react/hooks/use-define-ref.d.ts.map +0 -1
  368. package/dist/react/hooks/use-element-ref.cjs +0 -12
  369. package/dist/react/hooks/use-element-ref.d.cts +0 -2
  370. package/dist/react/hooks/use-element-ref.d.cts.map +0 -1
  371. package/dist/react/hooks/use-element-ref.d.ts +0 -2
  372. package/dist/react/hooks/use-element-ref.d.ts.map +0 -1
  373. package/dist/react/hooks/use-element-ref.js +0 -8
  374. package/dist/react/hooks/use-event-listener.cjs +0 -17
  375. package/dist/react/hooks/use-event-listener.d.cts +0 -8
  376. package/dist/react/hooks/use-event-listener.d.cts.map +0 -1
  377. package/dist/react/hooks/use-event-listener.d.ts +0 -8
  378. package/dist/react/hooks/use-event-listener.d.ts.map +0 -1
  379. package/dist/react/hooks/use-event-listener.js +0 -13
  380. package/dist/react/hooks/use-event.cjs +0 -23
  381. package/dist/react/hooks/use-event.d.cts +0 -3
  382. package/dist/react/hooks/use-event.d.cts.map +0 -1
  383. package/dist/react/hooks/use-event.d.ts +0 -3
  384. package/dist/react/hooks/use-event.d.ts.map +0 -1
  385. package/dist/react/hooks/use-event.js +0 -19
  386. package/dist/react/hooks/use-flag.cjs +0 -19
  387. package/dist/react/hooks/use-flag.d.cts +0 -8
  388. package/dist/react/hooks/use-flag.d.cts.map +0 -1
  389. package/dist/react/hooks/use-flag.d.ts +0 -8
  390. package/dist/react/hooks/use-flag.d.ts.map +0 -1
  391. package/dist/react/hooks/use-flag.js +0 -15
  392. package/dist/react/hooks/use-force-update.cjs +0 -11
  393. package/dist/react/hooks/use-force-update.d.cts +0 -2
  394. package/dist/react/hooks/use-force-update.d.cts.map +0 -1
  395. package/dist/react/hooks/use-force-update.d.ts +0 -2
  396. package/dist/react/hooks/use-force-update.d.ts.map +0 -1
  397. package/dist/react/hooks/use-force-update.js +0 -7
  398. package/dist/react/hooks/use-initial-height.cjs +0 -15
  399. package/dist/react/hooks/use-initial-height.d.cts +0 -5
  400. package/dist/react/hooks/use-initial-height.d.cts.map +0 -1
  401. package/dist/react/hooks/use-initial-height.d.ts +0 -5
  402. package/dist/react/hooks/use-initial-height.d.ts.map +0 -1
  403. package/dist/react/hooks/use-initial-height.js +0 -11
  404. package/dist/react/hooks/use-instance.cjs +0 -31
  405. package/dist/react/hooks/use-instance.d.cts +0 -27
  406. package/dist/react/hooks/use-instance.d.cts.map +0 -1
  407. package/dist/react/hooks/use-instance.d.ts +0 -27
  408. package/dist/react/hooks/use-instance.d.ts.map +0 -1
  409. package/dist/react/hooks/use-intersection-observer.cjs +0 -14
  410. package/dist/react/hooks/use-intersection-observer.d.cts +0 -2
  411. package/dist/react/hooks/use-intersection-observer.d.cts.map +0 -1
  412. package/dist/react/hooks/use-intersection-observer.d.ts +0 -2
  413. package/dist/react/hooks/use-intersection-observer.d.ts.map +0 -1
  414. package/dist/react/hooks/use-intersection-observer.js +0 -10
  415. package/dist/react/hooks/use-last-defined-value.cjs +0 -12
  416. package/dist/react/hooks/use-last-defined-value.d.cts +0 -2
  417. package/dist/react/hooks/use-last-defined-value.d.cts.map +0 -1
  418. package/dist/react/hooks/use-last-defined-value.d.ts +0 -2
  419. package/dist/react/hooks/use-last-defined-value.d.ts.map +0 -1
  420. package/dist/react/hooks/use-last-defined-value.js +0 -8
  421. package/dist/react/hooks/use-last-value-ref.cjs +0 -12
  422. package/dist/react/hooks/use-last-value-ref.d.cts +0 -2
  423. package/dist/react/hooks/use-last-value-ref.d.cts.map +0 -1
  424. package/dist/react/hooks/use-last-value-ref.d.ts +0 -2
  425. package/dist/react/hooks/use-last-value-ref.d.ts.map +0 -1
  426. package/dist/react/hooks/use-last-value-ref.js +0 -8
  427. package/dist/react/hooks/use-life-cycle.cjs +0 -14
  428. package/dist/react/hooks/use-life-cycle.d.cts +0 -5
  429. package/dist/react/hooks/use-life-cycle.d.cts.map +0 -1
  430. package/dist/react/hooks/use-life-cycle.d.ts +0 -5
  431. package/dist/react/hooks/use-life-cycle.d.ts.map +0 -1
  432. package/dist/react/hooks/use-life-cycle.js +0 -10
  433. package/dist/react/hooks/use-resize-observer.cjs +0 -15
  434. package/dist/react/hooks/use-resize-observer.d.cts +0 -2
  435. package/dist/react/hooks/use-resize-observer.d.cts.map +0 -1
  436. package/dist/react/hooks/use-resize-observer.d.ts +0 -2
  437. package/dist/react/hooks/use-resize-observer.d.ts.map +0 -1
  438. package/dist/react/hooks/use-resize-observer.js +0 -11
  439. package/dist/react/hooks/use-sync-ref.cjs +0 -10
  440. package/dist/react/hooks/use-sync-ref.d.cts +0 -2
  441. package/dist/react/hooks/use-sync-ref.d.cts.map +0 -1
  442. package/dist/react/hooks/use-sync-ref.d.ts +0 -2
  443. package/dist/react/hooks/use-sync-ref.d.ts.map +0 -1
  444. package/dist/react/hooks/use-sync-ref.js +0 -6
  445. package/dist/react/hooks/use-toggle.cjs +0 -10
  446. package/dist/react/hooks/use-toggle.d.cts +0 -2
  447. package/dist/react/hooks/use-toggle.d.cts.map +0 -1
  448. package/dist/react/hooks/use-toggle.d.ts +0 -2
  449. package/dist/react/hooks/use-toggle.d.ts.map +0 -1
  450. package/dist/react/hooks/use-toggle.js +0 -6
  451. package/dist/react/hooks/use-value.cjs +0 -12
  452. package/dist/react/hooks/use-value.d.cts +0 -5
  453. package/dist/react/hooks/use-value.d.cts.map +0 -1
  454. package/dist/react/hooks/use-value.d.ts +0 -5
  455. package/dist/react/hooks/use-value.d.ts.map +0 -1
  456. package/dist/react/hooks/use-value.js +0 -8
  457. package/dist/react/hooks/use-visibility-state.cjs +0 -18
  458. package/dist/react/hooks/use-visibility-state.d.cts +0 -2
  459. package/dist/react/hooks/use-visibility-state.d.cts.map +0 -1
  460. package/dist/react/hooks/use-visibility-state.d.ts +0 -2
  461. package/dist/react/hooks/use-visibility-state.d.ts.map +0 -1
  462. package/dist/react/hooks/use-visibility-state.js +0 -14
  463. package/dist/react/index.cjs +0 -17
  464. package/dist/react/index.d.cts +0 -2
  465. package/dist/react/index.d.cts.map +0 -1
  466. package/dist/react/index.d.ts +0 -2
  467. package/dist/react/index.d.ts.map +0 -1
  468. package/dist/react/index.js +0 -1
  469. package/dist/sound.cjs +0 -16
  470. package/dist/sound.d.cts +0 -7
  471. package/dist/sound.d.cts.map +0 -1
  472. package/dist/sound.d.ts +0 -7
  473. package/dist/sound.d.ts.map +0 -1
  474. package/dist/sound.js +0 -12
  475. package/dist/storage.cjs +0 -48
  476. package/dist/storage.d.cts +0 -39
  477. package/dist/storage.d.cts.map +0 -1
  478. package/dist/storage.d.ts +0 -39
  479. package/dist/storage.d.ts.map +0 -1
  480. package/dist/storage.js +0 -43
  481. package/dist/text.cjs +0 -53
  482. package/dist/text.d.cts +0 -15
  483. package/dist/text.d.cts.map +0 -1
  484. package/dist/text.d.ts +0 -15
  485. package/dist/text.d.ts.map +0 -1
  486. package/dist/text.js +0 -48
  487. package/dist/type-guard/_exports.cjs +0 -129
  488. package/dist/type-guard/_exports.d.cts +0 -86
  489. package/dist/type-guard/_exports.d.cts.map +0 -1
  490. package/dist/type-guard/_exports.d.ts +0 -86
  491. package/dist/type-guard/_exports.d.ts.map +0 -1
  492. package/dist/type-guard/_exports.js +0 -125
  493. package/dist/type-guard/index.cjs +0 -40
  494. package/dist/type-guard/index.d.cts +0 -3
  495. package/dist/type-guard/index.d.cts.map +0 -1
  496. package/dist/type-guard/index.d.ts +0 -3
  497. package/dist/type-guard/index.d.ts.map +0 -1
  498. package/dist/utils/types.cjs +0 -2
  499. package/dist/utils/types.d.cts +0 -395
  500. package/dist/utils/types.d.cts.map +0 -1
  501. package/dist/utils/types.d.ts +0 -395
  502. package/dist/utils/types.d.ts.map +0 -1
  503. package/dist/utils/types.js +0 -1
  504. package/dist/vibrate.cjs +0 -12
  505. package/dist/vibrate.d.cts +0 -5
  506. package/dist/vibrate.d.cts.map +0 -1
  507. package/dist/vibrate.d.ts +0 -5
  508. package/dist/vibrate.d.ts.map +0 -1
  509. package/dist/vibrate.js +0 -8
  510. package/utility-types.d.ts +0 -395
  511. package/utils/types.cjs +0 -2
  512. package/utils/types.d.cts +0 -395
  513. package/utils/types.d.cts.map +0 -1
  514. package/utils/types.d.ts +0 -395
  515. package/utils/types.d.ts.map +0 -1
  516. package/utils/types.js +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yummies",
3
- "version": "5.4.5",
3
+ "version": "5.4.6",
4
4
  "keywords": [],
5
5
  "author": "js2me",
6
6
  "license": "MIT",
@@ -17,42 +17,6 @@
17
17
  "mobx": "^6.12.4",
18
18
  "react": "^18 || ^19"
19
19
  },
20
- "zshy": {
21
- "exports": {
22
- "./package.json": "./package.json",
23
- "./complex": "./src/complex/index.ts",
24
- "./format": "./src/format/index.ts",
25
- "./mobx": "./src/mobx/index.ts",
26
- "./parser": "./src/parser/index.ts",
27
- "./react": "./src/react/index.ts",
28
- "./type-guard": "./src/type-guard/index.ts",
29
- "./utils/types": "./src/utils/types.ts",
30
- "./async": "./src/async.ts",
31
- "./common": "./src/common.ts",
32
- "./cookie": "./src/cookie.ts",
33
- "./css": "./src/css.ts",
34
- "./data": "./src/data.ts",
35
- "./date-time": "./src/date-time.ts",
36
- "./device": "./src/device.ts",
37
- "./encodings": "./src/encodings.ts",
38
- "./errors": "./src/errors.ts",
39
- "./file": "./src/file.ts",
40
- "./html": "./src/html.ts",
41
- "./id": "./src/id.ts",
42
- "./imports": "./src/imports.ts",
43
- "./math": "./src/math.ts",
44
- "./media": "./src/media.ts",
45
- "./ms": "./src/ms.ts",
46
- "./number": "./src/number.ts",
47
- "./price": "./src/price.ts",
48
- "./random": "./src/random.ts",
49
- "./sound": "./src/sound.ts",
50
- "./storage": "./src/storage.ts",
51
- "./text": "./src/text.ts",
52
- "./vibrate": "./src/vibrate.ts",
53
- "./utility-types": "./src/utils/types.ts"
54
- }
55
- },
56
20
  "peerDependenciesMeta": {
57
21
  "mobx": {
58
22
  "optional": true
@@ -86,359 +50,9 @@
86
50
  "rimraf": "^6.0.1",
87
51
  "tsx": "^4.20.5",
88
52
  "typescript": "^5.8.3",
89
- "vitest": "^3.1.2",
90
- "zshy": "^0.4.2"
53
+ "vitest": "^3.1.2"
91
54
  },
92
55
  "type": "module",
93
- "files": [
94
- "dist",
95
- "utility-types.d.ts",
96
- "utils"
97
- ],
98
- "exports": {
99
- "./package.json": "./package.json",
100
- "./complex": {
101
- "types": "./dist/complex/index.d.ts",
102
- "import": {
103
- "types": "./dist/complex/index.d.ts",
104
- "default": "./dist/complex/index.js"
105
- },
106
- "require": {
107
- "types": "./dist/complex/index.d.cts",
108
- "default": "./dist/complex/index.cjs"
109
- }
110
- },
111
- "./format": {
112
- "types": "./dist/format/index.d.ts",
113
- "import": {
114
- "types": "./dist/format/index.d.ts",
115
- "default": "./dist/format/index.js"
116
- },
117
- "require": {
118
- "types": "./dist/format/index.d.cts",
119
- "default": "./dist/format/index.cjs"
120
- }
121
- },
122
- "./mobx": {
123
- "types": "./dist/mobx/index.d.ts",
124
- "import": {
125
- "types": "./dist/mobx/index.d.ts",
126
- "default": "./dist/mobx/index.js"
127
- },
128
- "require": {
129
- "types": "./dist/mobx/index.d.cts",
130
- "default": "./dist/mobx/index.cjs"
131
- }
132
- },
133
- "./parser": {
134
- "types": "./dist/parser/index.d.ts",
135
- "import": {
136
- "types": "./dist/parser/index.d.ts",
137
- "default": "./dist/parser/index.js"
138
- },
139
- "require": {
140
- "types": "./dist/parser/index.d.cts",
141
- "default": "./dist/parser/index.cjs"
142
- }
143
- },
144
- "./react": {
145
- "types": "./dist/react/index.d.ts",
146
- "import": {
147
- "types": "./dist/react/index.d.ts",
148
- "default": "./dist/react/index.js"
149
- },
150
- "require": {
151
- "types": "./dist/react/index.d.cts",
152
- "default": "./dist/react/index.cjs"
153
- }
154
- },
155
- "./type-guard": {
156
- "types": "./dist/type-guard/index.d.ts",
157
- "import": {
158
- "types": "./dist/type-guard/index.d.ts",
159
- "default": "./dist/type-guard/index.js"
160
- },
161
- "require": {
162
- "types": "./dist/type-guard/index.d.cts",
163
- "default": "./dist/type-guard/index.cjs"
164
- }
165
- },
166
- "./utils/types": {
167
- "types": "./dist/utils/types.d.ts",
168
- "import": {
169
- "types": "./dist/utils/types.d.ts",
170
- "default": "./dist/utils/types.js"
171
- },
172
- "require": {
173
- "types": "./dist/utils/types.d.cts",
174
- "default": "./dist/utils/types.cjs"
175
- }
176
- },
177
- "./async": {
178
- "types": "./dist/async.d.ts",
179
- "import": {
180
- "types": "./dist/async.d.ts",
181
- "default": "./dist/async.js"
182
- },
183
- "require": {
184
- "types": "./dist/async.d.cts",
185
- "default": "./dist/async.cjs"
186
- }
187
- },
188
- "./common": {
189
- "types": "./dist/common.d.ts",
190
- "import": {
191
- "types": "./dist/common.d.ts",
192
- "default": "./dist/common.js"
193
- },
194
- "require": {
195
- "types": "./dist/common.d.cts",
196
- "default": "./dist/common.cjs"
197
- }
198
- },
199
- "./cookie": {
200
- "types": "./dist/cookie.d.ts",
201
- "import": {
202
- "types": "./dist/cookie.d.ts",
203
- "default": "./dist/cookie.js"
204
- },
205
- "require": {
206
- "types": "./dist/cookie.d.cts",
207
- "default": "./dist/cookie.cjs"
208
- }
209
- },
210
- "./css": {
211
- "types": "./dist/css.d.ts",
212
- "import": {
213
- "types": "./dist/css.d.ts",
214
- "default": "./dist/css.js"
215
- },
216
- "require": {
217
- "types": "./dist/css.d.cts",
218
- "default": "./dist/css.cjs"
219
- }
220
- },
221
- "./data": {
222
- "types": "./dist/data.d.ts",
223
- "import": {
224
- "types": "./dist/data.d.ts",
225
- "default": "./dist/data.js"
226
- },
227
- "require": {
228
- "types": "./dist/data.d.cts",
229
- "default": "./dist/data.cjs"
230
- }
231
- },
232
- "./date-time": {
233
- "types": "./dist/date-time.d.ts",
234
- "import": {
235
- "types": "./dist/date-time.d.ts",
236
- "default": "./dist/date-time.js"
237
- },
238
- "require": {
239
- "types": "./dist/date-time.d.cts",
240
- "default": "./dist/date-time.cjs"
241
- }
242
- },
243
- "./device": {
244
- "types": "./dist/device.d.ts",
245
- "import": {
246
- "types": "./dist/device.d.ts",
247
- "default": "./dist/device.js"
248
- },
249
- "require": {
250
- "types": "./dist/device.d.cts",
251
- "default": "./dist/device.cjs"
252
- }
253
- },
254
- "./encodings": {
255
- "types": "./dist/encodings.d.ts",
256
- "import": {
257
- "types": "./dist/encodings.d.ts",
258
- "default": "./dist/encodings.js"
259
- },
260
- "require": {
261
- "types": "./dist/encodings.d.cts",
262
- "default": "./dist/encodings.cjs"
263
- }
264
- },
265
- "./errors": {
266
- "types": "./dist/errors.d.ts",
267
- "import": {
268
- "types": "./dist/errors.d.ts",
269
- "default": "./dist/errors.js"
270
- },
271
- "require": {
272
- "types": "./dist/errors.d.cts",
273
- "default": "./dist/errors.cjs"
274
- }
275
- },
276
- "./file": {
277
- "types": "./dist/file.d.ts",
278
- "import": {
279
- "types": "./dist/file.d.ts",
280
- "default": "./dist/file.js"
281
- },
282
- "require": {
283
- "types": "./dist/file.d.cts",
284
- "default": "./dist/file.cjs"
285
- }
286
- },
287
- "./html": {
288
- "types": "./dist/html.d.ts",
289
- "import": {
290
- "types": "./dist/html.d.ts",
291
- "default": "./dist/html.js"
292
- },
293
- "require": {
294
- "types": "./dist/html.d.cts",
295
- "default": "./dist/html.cjs"
296
- }
297
- },
298
- "./id": {
299
- "types": "./dist/id.d.ts",
300
- "import": {
301
- "types": "./dist/id.d.ts",
302
- "default": "./dist/id.js"
303
- },
304
- "require": {
305
- "types": "./dist/id.d.cts",
306
- "default": "./dist/id.cjs"
307
- }
308
- },
309
- "./imports": {
310
- "types": "./dist/imports.d.ts",
311
- "import": {
312
- "types": "./dist/imports.d.ts",
313
- "default": "./dist/imports.js"
314
- },
315
- "require": {
316
- "types": "./dist/imports.d.cts",
317
- "default": "./dist/imports.cjs"
318
- }
319
- },
320
- "./math": {
321
- "types": "./dist/math.d.ts",
322
- "import": {
323
- "types": "./dist/math.d.ts",
324
- "default": "./dist/math.js"
325
- },
326
- "require": {
327
- "types": "./dist/math.d.cts",
328
- "default": "./dist/math.cjs"
329
- }
330
- },
331
- "./media": {
332
- "types": "./dist/media.d.ts",
333
- "import": {
334
- "types": "./dist/media.d.ts",
335
- "default": "./dist/media.js"
336
- },
337
- "require": {
338
- "types": "./dist/media.d.cts",
339
- "default": "./dist/media.cjs"
340
- }
341
- },
342
- "./ms": {
343
- "types": "./dist/ms.d.ts",
344
- "import": {
345
- "types": "./dist/ms.d.ts",
346
- "default": "./dist/ms.js"
347
- },
348
- "require": {
349
- "types": "./dist/ms.d.cts",
350
- "default": "./dist/ms.cjs"
351
- }
352
- },
353
- "./number": {
354
- "types": "./dist/number.d.ts",
355
- "import": {
356
- "types": "./dist/number.d.ts",
357
- "default": "./dist/number.js"
358
- },
359
- "require": {
360
- "types": "./dist/number.d.cts",
361
- "default": "./dist/number.cjs"
362
- }
363
- },
364
- "./price": {
365
- "types": "./dist/price.d.ts",
366
- "import": {
367
- "types": "./dist/price.d.ts",
368
- "default": "./dist/price.js"
369
- },
370
- "require": {
371
- "types": "./dist/price.d.cts",
372
- "default": "./dist/price.cjs"
373
- }
374
- },
375
- "./random": {
376
- "types": "./dist/random.d.ts",
377
- "import": {
378
- "types": "./dist/random.d.ts",
379
- "default": "./dist/random.js"
380
- },
381
- "require": {
382
- "types": "./dist/random.d.cts",
383
- "default": "./dist/random.cjs"
384
- }
385
- },
386
- "./sound": {
387
- "types": "./dist/sound.d.ts",
388
- "import": {
389
- "types": "./dist/sound.d.ts",
390
- "default": "./dist/sound.js"
391
- },
392
- "require": {
393
- "types": "./dist/sound.d.cts",
394
- "default": "./dist/sound.cjs"
395
- }
396
- },
397
- "./storage": {
398
- "types": "./dist/storage.d.ts",
399
- "import": {
400
- "types": "./dist/storage.d.ts",
401
- "default": "./dist/storage.js"
402
- },
403
- "require": {
404
- "types": "./dist/storage.d.cts",
405
- "default": "./dist/storage.cjs"
406
- }
407
- },
408
- "./text": {
409
- "types": "./dist/text.d.ts",
410
- "import": {
411
- "types": "./dist/text.d.ts",
412
- "default": "./dist/text.js"
413
- },
414
- "require": {
415
- "types": "./dist/text.d.cts",
416
- "default": "./dist/text.cjs"
417
- }
418
- },
419
- "./vibrate": {
420
- "types": "./dist/vibrate.d.ts",
421
- "import": {
422
- "types": "./dist/vibrate.d.ts",
423
- "default": "./dist/vibrate.js"
424
- },
425
- "require": {
426
- "types": "./dist/vibrate.d.cts",
427
- "default": "./dist/vibrate.cjs"
428
- }
429
- },
430
- "./utility-types": {
431
- "types": "./utility-types.d.ts",
432
- "import": {
433
- "types": "./dist/utils/types.d.ts",
434
- "default": "./dist/utils/types.js"
435
- },
436
- "require": {
437
- "types": "./dist/utils/types.d.cts",
438
- "default": "./dist/utils/types.cjs"
439
- }
440
- }
441
- },
442
56
  "scripts": {
443
57
  "clean": "rm -rf dist",
444
58
  "lint:check": "pnpm exec biome check --write --no-errors-on-unmatched --files-ignore-unknown=true",
@@ -446,7 +60,7 @@
446
60
  "check": "npm run lint:check && npm run ts:check",
447
61
  "prebuild": "npm run clean && npm run check",
448
62
  "build:watch": "pnpm build && nodemon --watch src --ext ts --exec \"pnpm build\"",
449
- "build": "zshy && tsx scripts/process-exports-field && tsx scripts/generate-utility-types-file",
63
+ "build": "tsc && tsx scripts/post-build",
450
64
  "pub": "pnpm build && node node_modules/js2me-exports-post-build-script/scripts/publish",
451
65
  "pub:patch": "PUBLISH_VERSION=patch pnpm pub",
452
66
  "pub:minor": "PUBLISH_VERSION=minor pnpm pub",
@@ -0,0 +1,71 @@
1
+ import {
2
+ getInfoFromChangelog,
3
+ postBuildScript,
4
+ publishGhRelease,
5
+ publishScript,
6
+ } from "js2me-exports-post-build-script";
7
+ import path from "path";
8
+
9
+ postBuildScript({
10
+ buildDir: "dist",
11
+ rootDir: ".",
12
+ srcDirName: "src",
13
+ filesToCopy: ["LICENSE", "README.md", "assets"],
14
+ updateVersion: process.env.PUBLISH_VERSION as "patch" | "minor" | "major" | undefined,
15
+ onDone: (versionsDiff, targetPackageJson, { $ }) => {
16
+ $("pnpm test");
17
+ $(`cp dist/utils/types.d.ts dist/utility-types.d.ts`);
18
+ $(`sed -i 's/^export type/type/' dist/utility-types.d.ts`);
19
+
20
+ if (process.env.PUBLISH) {
21
+ if (!process.env.CI) {
22
+ $(`pnpm test`);
23
+ $("pnpm changeset version");
24
+ }
25
+
26
+ // remove all test compiled files. TODO: find a better to ignore test files
27
+ $("rm dist/**/*.test.*");
28
+
29
+ const nextVersion = versionsDiff?.next ?? targetPackageJson.data.version;
30
+
31
+ const publishOutput = publishScript({
32
+ gitTagFormat: "<tag>",
33
+ nextVersion: nextVersion,
34
+ packageManager: "pnpm",
35
+ commitAllCurrentChanges: true,
36
+ createTag: true,
37
+ safe: true,
38
+ onAlreadyPublishedThisVersion: () => {
39
+ console.warn(`${nextVersion} already published`);
40
+ },
41
+ cleanupCommand: "pnpm clean",
42
+ targetPackageJson,
43
+ });
44
+
45
+ if (process.env.CI) {
46
+ if (publishOutput?.publishedGitTag) {
47
+ const { whatChangesText } = getInfoFromChangelog(
48
+ nextVersion,
49
+ path.resolve(targetPackageJson.locationDir, "../CHANGELOG.md"),
50
+ targetPackageJson.repositoryUrl,
51
+ );
52
+
53
+ publishGhRelease({
54
+ authToken: process.env.GITHUB_TOKEN!,
55
+ body: whatChangesText,
56
+ owner: targetPackageJson.ghRepoData.user,
57
+ repo: targetPackageJson.ghRepoData.packageName,
58
+ version: nextVersion,
59
+ })
60
+ .then((r) => {
61
+ console.info("published new gh release", r);
62
+ })
63
+ .catch((err) => {
64
+ console.error("failed to publish new gh release", err);
65
+ process.exit(1);
66
+ });
67
+ }
68
+ }
69
+ }
70
+ },
71
+ });
package/src/async.ts ADDED
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Создает промис, который будет ждать указанное количество ms, чтобы выполниться
3
+ *
4
+ * @param ms значение в миллисекундах
5
+ * @returns Promise
6
+ */
7
+ export const sleep = (time: number = 0) =>
8
+ new Promise((resolve) => setTimeout(resolve, time));
9
+
10
+ /**
11
+ * Создает промис, который будет ждать указанное количество ms, чтобы выполниться
12
+ *
13
+ * @deprecated используй {sleep}
14
+ * @param ms значение в миллисекундах
15
+ * @returns Promise
16
+ */
17
+ export const waitAsync = async (ms = 1000) =>
18
+ new Promise((resolve) => setTimeout(resolve, ms));
19
+
20
+ /**
21
+ * Создает вызов requestAnimationFrame, посылая туда фукнцию {quitFn}, если она возвращает true,
22
+ * тогда повторно не будет создан вызов requestAnimationFrame, иначе будут создаваться повторно
23
+ * вызовы requestAnimationFrame до тем пор, пока эта функция не вернёт true
24
+ *
25
+ * @param quitFn - сама фукнция которая исполнится в requestAnimationFrame
26
+ * @param asMicrotask - дополнительно оборачивает RAF в queueMicrotask
27
+ * @returns void
28
+ */
29
+ export const endlessRAF = (
30
+ quitFunction: () => boolean | void,
31
+ asMicrotask?: boolean,
32
+ ) => {
33
+ if (quitFunction()) return;
34
+
35
+ const raf = () =>
36
+ requestAnimationFrame(() => endlessRAF(quitFunction, asMicrotask));
37
+
38
+ if (asMicrotask) {
39
+ queueMicrotask(raf);
40
+ } else {
41
+ raf();
42
+ }
43
+ };
44
+
45
+ export function setAbortableTimeout(
46
+ callback: VoidFunction,
47
+ delayInMs?: number,
48
+ signal?: AbortSignal,
49
+ ) {
50
+ let internalTimer: number | null = null;
51
+
52
+ const handleAbort = () => {
53
+ if (internalTimer == null) {
54
+ return;
55
+ }
56
+ clearTimeout(internalTimer);
57
+ internalTimer = null;
58
+ };
59
+
60
+ signal?.addEventListener('abort', handleAbort, { once: true });
61
+
62
+ internalTimer = setTimeout(() => {
63
+ signal?.removeEventListener('abort', handleAbort);
64
+ callback();
65
+ }, delayInMs);
66
+ }
67
+
68
+ export function setAbortableInterval(
69
+ callback: VoidFunction,
70
+ delayInMs?: number,
71
+ signal?: AbortSignal,
72
+ ) {
73
+ let timer: number | null = null;
74
+
75
+ const handleAbort = () => {
76
+ if (timer == null) {
77
+ return;
78
+ }
79
+ clearInterval(timer);
80
+ timer = null;
81
+ };
82
+
83
+ signal?.addEventListener('abort', handleAbort, { once: true });
84
+
85
+ timer = setInterval(callback, delayInMs);
86
+ }
package/src/common.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { MaybeFn } from './utils/types.js';
2
+
3
+ /**
4
+ * @deprecated use {MaybeFn} type
5
+ */
6
+ export type FnValue<TValue, TArgs extends any[] = []> = MaybeFn<TValue, TArgs>;
7
+
8
+ /**
9
+ * Calls the provided function with the given arguments if it is a function;
10
+ * otherwise, returns the value directly.
11
+ */
12
+ export const callFunction = <TValue, TArgs extends any[] = []>(
13
+ fn: MaybeFn<TValue, TArgs>,
14
+ ...args: TArgs
15
+ ) => {
16
+ if (typeof fn === 'function') {
17
+ return (fn as any)(...args) as TValue;
18
+ }
19
+
20
+ return fn;
21
+ };
22
+
23
+ /**
24
+ * @deprecated use {callFunction}
25
+ */
26
+ export const resolveFnValue = callFunction;
@@ -0,0 +1,41 @@
1
+ import { describe } from 'node:test';
2
+ import { expect, it } from 'vitest';
3
+
4
+ import { createCounter } from './counter';
5
+
6
+ describe('createCounter', () => {
7
+ it('should have initial values', () => {
8
+ const counter = createCounter(undefined, -1);
9
+
10
+ expect(counter.counter).toBe(-1);
11
+ expect(counter.value).toBe(-1);
12
+ });
13
+
14
+ it('should increment and update value and counter properties', () => {
15
+ const counter = createCounter(undefined, -1);
16
+
17
+ counter();
18
+
19
+ expect(counter.counter).toBe(0);
20
+ expect(counter.value).toBe(0);
21
+ });
22
+
23
+ it('should decrement and update value and counter properties', () => {
24
+ const counter = createCounter(undefined, -1);
25
+
26
+ counter.decrement();
27
+
28
+ expect(counter.counter).toBe(-2);
29
+ expect(counter.value).toBe(-2);
30
+ });
31
+
32
+ it('should increment and update processed value', () => {
33
+ const counter = createCounter((counter) => `counter_${counter}_counter`);
34
+
35
+ expect(counter.value).toBe(`counter_0_counter`);
36
+
37
+ counter();
38
+
39
+ expect(counter.value).toBe(`counter_1_counter`);
40
+ });
41
+ });
@@ -0,0 +1,40 @@
1
+ export interface Counter<TValue = number> {
2
+ (): TValue;
3
+ counter: number;
4
+ value: TValue;
5
+ increment(): TValue;
6
+ decrement(): TValue;
7
+ reset(): void;
8
+ }
9
+
10
+ /**
11
+ * @deprecated use {`Counter`}. Will be removed in next major release
12
+ */
13
+ export interface CounterFn<TValue = number> extends Counter<TValue> {}
14
+
15
+ export const createCounter = <TValue = number>(
16
+ processValue?: (value: number) => TValue,
17
+ initial: number = 0,
18
+ ): Counter<TValue> => {
19
+ const update = (counter: number) => {
20
+ fn.value = processValue?.(counter) ?? (counter as TValue);
21
+ return fn.value;
22
+ };
23
+
24
+ const increment = () => update(++fn.counter);
25
+ const decrement = () => update(--fn.counter);
26
+
27
+ const fn: Counter<TValue> = increment as any;
28
+
29
+ fn.increment = increment;
30
+ fn.decrement = decrement;
31
+
32
+ fn.reset = () => {
33
+ fn.counter = initial;
34
+ fn.value = processValue?.(initial) ?? (initial as TValue);
35
+ };
36
+
37
+ fn.reset();
38
+
39
+ return fn as Counter<TValue>;
40
+ };