yummies 5.4.6 → 5.4.7

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 (290) hide show
  1. package/async.d.ts +28 -0
  2. package/async.d.ts.map +1 -0
  3. package/async.js +62 -0
  4. package/{src/common.ts → common.d.ts} +3 -14
  5. package/common.d.ts.map +1 -0
  6. package/common.js +14 -0
  7. package/complex/counter.d.ts +15 -0
  8. package/complex/counter.d.ts.map +1 -0
  9. package/complex/counter.js +17 -0
  10. package/complex/global-config.d.ts +11 -0
  11. package/complex/global-config.d.ts.map +1 -0
  12. package/complex/global-config.js +41 -0
  13. package/complex/index.d.ts +4 -0
  14. package/complex/index.d.ts.map +1 -0
  15. package/complex/modules-factory.d.ts +49 -0
  16. package/complex/modules-factory.d.ts.map +1 -0
  17. package/complex/modules-factory.js +46 -0
  18. package/cookie.d.ts +3 -0
  19. package/cookie.d.ts.map +1 -0
  20. package/cookie.js +9 -0
  21. package/css.d.ts +36 -0
  22. package/css.d.ts.map +1 -0
  23. package/css.js +20 -0
  24. package/data.d.ts +4 -0
  25. package/data.d.ts.map +1 -0
  26. package/data.js +52 -0
  27. package/date-time.d.ts +28 -0
  28. package/date-time.d.ts.map +1 -0
  29. package/date-time.js +160 -0
  30. package/device.d.ts +8 -0
  31. package/device.d.ts.map +1 -0
  32. package/device.js +21 -0
  33. package/encodings.d.ts +2 -0
  34. package/encodings.d.ts.map +1 -0
  35. package/encodings.js +267 -0
  36. package/errors.d.ts +19 -0
  37. package/errors.d.ts.map +1 -0
  38. package/errors.js +30 -0
  39. package/file.d.ts +3 -0
  40. package/file.d.ts.map +1 -0
  41. package/file.js +24 -0
  42. package/format/_exports.d.ts +5 -0
  43. package/format/_exports.d.ts.map +1 -0
  44. package/format/constants.d.ts +4 -0
  45. package/format/constants.d.ts.map +1 -0
  46. package/{src/format/constants.ts → format/constants.js} +0 -2
  47. package/format/index.d.ts +3 -0
  48. package/format/index.d.ts.map +1 -0
  49. package/{src/format/index.ts → format/index.js} +0 -1
  50. package/format/number.d.ts +36 -0
  51. package/format/number.d.ts.map +1 -0
  52. package/format/number.js +44 -0
  53. package/format/percent.d.ts +15 -0
  54. package/format/percent.d.ts.map +1 -0
  55. package/format/percent.js +23 -0
  56. package/format/skip-spaces.d.ts +5 -0
  57. package/format/skip-spaces.d.ts.map +1 -0
  58. package/format/skip-spaces.js +4 -0
  59. package/html.d.ts +44 -0
  60. package/html.d.ts.map +1 -0
  61. package/html.js +182 -0
  62. package/id.d.ts +63 -0
  63. package/id.d.ts.map +1 -0
  64. package/{src/id.ts → id.js} +6 -16
  65. package/imports.d.ts +15 -0
  66. package/imports.d.ts.map +1 -0
  67. package/imports.js +40 -0
  68. package/math.d.ts +13 -0
  69. package/math.d.ts.map +1 -0
  70. package/math.js +17 -0
  71. package/media.d.ts +20 -0
  72. package/media.d.ts.map +1 -0
  73. package/media.js +103 -0
  74. package/mobx/apply-observable.d.ts +4 -0
  75. package/mobx/apply-observable.d.ts.map +1 -0
  76. package/mobx/apply-observable.js +12 -0
  77. package/mobx/create-enhanced-atom.d.ts +11 -0
  78. package/mobx/create-enhanced-atom.d.ts.map +1 -0
  79. package/mobx/create-enhanced-atom.js +12 -0
  80. package/mobx/deep-observable-struct.d.ts +7 -0
  81. package/mobx/deep-observable-struct.d.ts.map +1 -0
  82. package/mobx/deep-observable-struct.js +57 -0
  83. package/mobx/get-mobx-administration.d.ts +6 -0
  84. package/mobx/get-mobx-administration.d.ts.map +1 -0
  85. package/mobx/get-mobx-administration.js +2 -0
  86. package/mobx/index.d.ts +6 -0
  87. package/mobx/index.d.ts.map +1 -0
  88. package/mobx/lazy-observe.d.ts +8 -0
  89. package/mobx/lazy-observe.d.ts.map +1 -0
  90. package/mobx/lazy-observe.js +43 -0
  91. package/ms.d.ts +19 -0
  92. package/ms.d.ts.map +1 -0
  93. package/ms.js +18 -0
  94. package/number.d.ts +8 -0
  95. package/number.d.ts.map +1 -0
  96. package/number.js +13 -0
  97. package/package.json +399 -3
  98. package/parser/_exports.d.ts +4 -0
  99. package/parser/_exports.d.ts.map +1 -0
  100. package/parser/index.d.ts +3 -0
  101. package/parser/index.d.ts.map +1 -0
  102. package/{src/parser/index.ts → parser/index.js} +0 -1
  103. package/parser/number.d.ts +21 -0
  104. package/parser/number.d.ts.map +1 -0
  105. package/parser/number.js +44 -0
  106. package/parser/percent.d.ts +4 -0
  107. package/parser/percent.d.ts.map +1 -0
  108. package/parser/percent.js +4 -0
  109. package/parser/string.d.ts +7 -0
  110. package/parser/string.d.ts.map +1 -0
  111. package/parser/string.js +14 -0
  112. package/price.d.ts +6 -0
  113. package/price.d.ts.map +1 -0
  114. package/price.js +17 -0
  115. package/random.d.ts +9 -0
  116. package/random.d.ts.map +1 -0
  117. package/random.js +14 -0
  118. package/react/hooks/index.d.ts +22 -0
  119. package/react/hooks/index.d.ts.map +1 -0
  120. package/react/hooks/use-abort-controller.d.ts +2 -0
  121. package/react/hooks/use-abort-controller.d.ts.map +1 -0
  122. package/react/hooks/use-abort-controller.js +11 -0
  123. package/react/hooks/use-abort-signal.d.ts +2 -0
  124. package/react/hooks/use-abort-signal.d.ts.map +1 -0
  125. package/{src/react/hooks/use-abort-signal.ts → react/hooks/use-abort-signal.js} +1 -2
  126. package/react/hooks/use-click-outside.d.ts +9 -0
  127. package/react/hooks/use-click-outside.d.ts.map +1 -0
  128. package/react/hooks/use-click-outside.js +13 -0
  129. package/react/hooks/use-constant.d.ts +9 -0
  130. package/react/hooks/use-constant.d.ts.map +1 -0
  131. package/{src/react/hooks/use-constant.ts → react/hooks/use-constant.js} +6 -9
  132. package/react/hooks/use-define-ref.d.ts +10 -0
  133. package/react/hooks/use-define-ref.d.ts.map +1 -0
  134. package/{src/react/hooks/use-define-ref.ts → react/hooks/use-define-ref.js} +7 -10
  135. package/react/hooks/use-element-ref.d.ts +2 -0
  136. package/react/hooks/use-element-ref.d.ts.map +1 -0
  137. package/react/hooks/use-element-ref.js +8 -0
  138. package/react/hooks/use-event-listener.d.ts +8 -0
  139. package/react/hooks/use-event-listener.d.ts.map +1 -0
  140. package/react/hooks/use-event-listener.js +13 -0
  141. package/react/hooks/use-event.d.ts +3 -0
  142. package/react/hooks/use-event.d.ts.map +1 -0
  143. package/react/hooks/use-event.js +19 -0
  144. package/react/hooks/use-flag.d.ts +8 -0
  145. package/react/hooks/use-flag.d.ts.map +1 -0
  146. package/react/hooks/use-flag.js +15 -0
  147. package/react/hooks/use-force-update.d.ts +2 -0
  148. package/react/hooks/use-force-update.d.ts.map +1 -0
  149. package/react/hooks/use-force-update.js +7 -0
  150. package/react/hooks/use-initial-height.d.ts +5 -0
  151. package/react/hooks/use-initial-height.d.ts.map +1 -0
  152. package/react/hooks/use-initial-height.js +11 -0
  153. package/react/hooks/use-instance.d.ts +27 -0
  154. package/react/hooks/use-instance.d.ts.map +1 -0
  155. package/{src/react/hooks/use-instance.ts → react/hooks/use-instance.js} +7 -29
  156. package/react/hooks/use-intersection-observer.d.ts +2 -0
  157. package/react/hooks/use-intersection-observer.d.ts.map +1 -0
  158. package/react/hooks/use-intersection-observer.js +10 -0
  159. package/react/hooks/use-last-defined-value.d.ts +2 -0
  160. package/react/hooks/use-last-defined-value.d.ts.map +1 -0
  161. package/react/hooks/use-last-defined-value.js +8 -0
  162. package/react/hooks/use-last-value-ref.d.ts +2 -0
  163. package/react/hooks/use-last-value-ref.d.ts.map +1 -0
  164. package/react/hooks/use-last-value-ref.js +8 -0
  165. package/react/hooks/use-life-cycle.d.ts +5 -0
  166. package/react/hooks/use-life-cycle.d.ts.map +1 -0
  167. package/react/hooks/use-life-cycle.js +10 -0
  168. package/react/hooks/use-resize-observer.d.ts +2 -0
  169. package/react/hooks/use-resize-observer.d.ts.map +1 -0
  170. package/react/hooks/use-resize-observer.js +11 -0
  171. package/react/hooks/use-sync-ref.d.ts +2 -0
  172. package/react/hooks/use-sync-ref.d.ts.map +1 -0
  173. package/react/hooks/use-sync-ref.js +6 -0
  174. package/react/hooks/use-toggle.d.ts +2 -0
  175. package/react/hooks/use-toggle.d.ts.map +1 -0
  176. package/react/hooks/use-toggle.js +6 -0
  177. package/react/hooks/use-value.d.ts +5 -0
  178. package/react/hooks/use-value.d.ts.map +1 -0
  179. package/react/hooks/use-value.js +8 -0
  180. package/react/hooks/use-visibility-state.d.ts +2 -0
  181. package/react/hooks/use-visibility-state.d.ts.map +1 -0
  182. package/react/hooks/use-visibility-state.js +14 -0
  183. package/react/index.d.ts +2 -0
  184. package/react/index.d.ts.map +1 -0
  185. package/sound.d.ts +7 -0
  186. package/sound.d.ts.map +1 -0
  187. package/sound.js +12 -0
  188. package/storage.d.ts +39 -0
  189. package/storage.d.ts.map +1 -0
  190. package/storage.js +43 -0
  191. package/text.d.ts +15 -0
  192. package/text.d.ts.map +1 -0
  193. package/text.js +48 -0
  194. package/type-guard/_exports.d.ts +86 -0
  195. package/type-guard/_exports.d.ts.map +1 -0
  196. package/type-guard/_exports.js +125 -0
  197. package/type-guard/index.d.ts +3 -0
  198. package/type-guard/index.d.ts.map +1 -0
  199. package/{src/type-guard/index.ts → type-guard/index.js} +0 -1
  200. package/utility-types.d.ts +395 -0
  201. package/utils/types.d.ts +395 -0
  202. package/utils/types.d.ts.map +1 -0
  203. package/utils/types.js +1 -0
  204. package/vibrate.d.ts +5 -0
  205. package/vibrate.d.ts.map +1 -0
  206. package/vibrate.js +8 -0
  207. package/.changeset/README.md +0 -8
  208. package/.changeset/config.json +0 -11
  209. package/.github/FUNDING.yml +0 -1
  210. package/.github/workflows/main.yml +0 -34
  211. package/.github/workflows/version-or-publish.yml +0 -45
  212. package/.nvmrc +0 -1
  213. package/.vscode/settings.json +0 -19
  214. package/CHANGELOG.md +0 -215
  215. package/CONTRIBUTING.md +0 -8
  216. package/Makefile +0 -7
  217. package/biome.json +0 -3
  218. package/commitfmt.toml +0 -18
  219. package/lefthook.yml +0 -14
  220. package/scripts/post-build.ts +0 -71
  221. package/src/async.ts +0 -86
  222. package/src/complex/counter.test.ts +0 -41
  223. package/src/complex/counter.ts +0 -40
  224. package/src/complex/global-config.ts +0 -55
  225. package/src/complex/modules-factory.ts +0 -65
  226. package/src/cookie.ts +0 -11
  227. package/src/css.ts +0 -60
  228. package/src/data.test.ts +0 -99
  229. package/src/data.ts +0 -65
  230. package/src/date-time.test.ts +0 -119
  231. package/src/date-time.ts +0 -236
  232. package/src/device.ts +0 -42
  233. package/src/encodings.ts +0 -270
  234. package/src/errors.ts +0 -40
  235. package/src/file.ts +0 -25
  236. package/src/format/number.test.ts +0 -16
  237. package/src/format/number.ts +0 -96
  238. package/src/format/percent.ts +0 -40
  239. package/src/format/skip-spaces.ts +0 -4
  240. package/src/html.ts +0 -238
  241. package/src/imports.ts +0 -52
  242. package/src/math.ts +0 -20
  243. package/src/media.ts +0 -134
  244. package/src/mobx/apply-observable.ts +0 -20
  245. package/src/mobx/create-enhanced-atom.ts +0 -28
  246. package/src/mobx/deep-observable-struct.test.ts +0 -69
  247. package/src/mobx/deep-observable-struct.ts +0 -69
  248. package/src/mobx/get-mobx-administration.ts +0 -10
  249. package/src/mobx/lazy-observe.ts +0 -59
  250. package/src/ms.ts +0 -20
  251. package/src/number.ts +0 -14
  252. package/src/parser/number.test.ts +0 -38
  253. package/src/parser/number.ts +0 -73
  254. package/src/parser/percent.ts +0 -11
  255. package/src/parser/string.ts +0 -29
  256. package/src/price.ts +0 -33
  257. package/src/random.ts +0 -27
  258. package/src/react/hooks/use-abort-controller.ts +0 -15
  259. package/src/react/hooks/use-click-outside.ts +0 -27
  260. package/src/react/hooks/use-element-ref.ts +0 -11
  261. package/src/react/hooks/use-event-listener.ts +0 -29
  262. package/src/react/hooks/use-event.ts +0 -23
  263. package/src/react/hooks/use-flag.ts +0 -27
  264. package/src/react/hooks/use-force-update.ts +0 -9
  265. package/src/react/hooks/use-initial-height.ts +0 -16
  266. package/src/react/hooks/use-intersection-observer.ts +0 -18
  267. package/src/react/hooks/use-last-defined-value.ts +0 -9
  268. package/src/react/hooks/use-last-value-ref.ts +0 -11
  269. package/src/react/hooks/use-life-cycle.ts +0 -17
  270. package/src/react/hooks/use-resize-observer.ts +0 -14
  271. package/src/react/hooks/use-sync-ref.ts +0 -7
  272. package/src/react/hooks/use-toggle.ts +0 -9
  273. package/src/react/hooks/use-value.ts +0 -10
  274. package/src/react/hooks/use-visibility-state.ts +0 -19
  275. package/src/sound.ts +0 -15
  276. package/src/storage.ts +0 -137
  277. package/src/text.test.ts +0 -91
  278. package/src/text.ts +0 -60
  279. package/src/type-guard/_exports.ts +0 -154
  280. package/src/type-guard/index.test.ts +0 -127
  281. package/src/vibrate.ts +0 -8
  282. package/tsconfig.json +0 -26
  283. package/tsconfig.test.json +0 -33
  284. package/vitest.config.ts +0 -20
  285. /package/{src/complex/index.ts → complex/index.js} +0 -0
  286. /package/{src/format/_exports.ts → format/_exports.js} +0 -0
  287. /package/{src/mobx/index.ts → mobx/index.js} +0 -0
  288. /package/{src/parser/_exports.ts → parser/_exports.js} +0 -0
  289. /package/{src/react/hooks/index.ts → react/hooks/index.js} +0 -0
  290. /package/{src/react/index.ts → react/index.js} +0 -0
package/src/ms.ts DELETED
@@ -1,20 +0,0 @@
1
- export const unitsToMs = {
2
- ms: 1,
3
- sec: 1000,
4
- min: 1000 * 60,
5
- hour: 1000 * 60 * 60,
6
- day: 1000 * 60 * 60 * 24,
7
- week: 1000 * 60 * 60 * 24 * 7,
8
- } as const;
9
-
10
- /**
11
- * Переводит значение в юнитах в миллисекунды
12
- *
13
- * @example
14
- * ```ts
15
- * ms(1, 'min') // 60_000
16
- * ms(30, 'sec') // 30_000
17
- * ```
18
- */
19
- export const ms = (value: number, unit: keyof typeof unitsToMs = 'ms') =>
20
- value * unitsToMs[unit];
package/src/number.ts DELETED
@@ -1,14 +0,0 @@
1
- /**
2
- * Works like `parseFloat(number.toFixed(4))` but performance better
3
- *
4
- * @example
5
- * round(191.212999999999999999999999, 4) // 191.213
6
- */
7
- export function round(value: number, decimalPlaces: number = 0): number {
8
- if (!decimalPlaces) {
9
- return Math.round(value);
10
- }
11
-
12
- const factor = 10 ** decimalPlaces;
13
- return Math.round(value * factor) / factor;
14
- }
@@ -1,38 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { number } from './number';
3
-
4
- describe('parser.number', () => {
5
- test('empty string should return 0', () => {
6
- expect(number('')).toBe(0);
7
- });
8
-
9
- test('empty string with fallback should return fallback', () => {
10
- expect(number('', { fallback: 'kek' })).toBe('kek');
11
- });
12
-
13
- test('Checking the logic of the function', () => {
14
- expect(number(1)).toBe(1);
15
- expect(number(100)).toBe(100);
16
- expect(number(500)).toBe(500);
17
- expect(number(1, { clamped: [400] })).toBe(400);
18
- expect(number(1001, { clamped: [null, 1000] })).toBe(1000);
19
- });
20
-
21
- test('Rounding down', () => {
22
- expect(number(5.9, { floor: true })).toBe(5);
23
- });
24
-
25
- test('Rounding up', () => {
26
- expect(number(5.1, { ceil: true })).toBe(6);
27
- });
28
-
29
- test('Processing invalid values', () => {
30
- expect(number(null)).toBe(0);
31
- expect(number(undefined)).toBe(0);
32
- expect(number('-')).toBe(0);
33
- expect(number('test')).toBe(0);
34
-
35
- expect(number(null, null)).toBe(0);
36
- expect(number(undefined, undefined)).toBe(0);
37
- });
38
- });
@@ -1,73 +0,0 @@
1
- import { skipSpaces } from '../format/skip-spaces.js';
2
- import { typeGuard } from '../type-guard/index.js';
3
- import type { Maybe } from '../utils/types.js';
4
-
5
- export interface NumberParserSettings<TFallback = number> {
6
- digits?: number;
7
- fallback?: TFallback;
8
- /**
9
- * Round to upper boundary
10
- * 5.1 -> 6
11
- */
12
- ceil?: boolean;
13
- /**
14
- * Round to bottom boundary
15
- * 5.9 -> 5
16
- */
17
- floor?: boolean;
18
- clamped?: [min?: Maybe<number>, max?: Maybe<number>];
19
- }
20
-
21
- export const number = <TFallback = number>(
22
- input: Maybe<unknown>,
23
- userSettings?: Maybe<NumberParserSettings<TFallback>>,
24
- ): number | TFallback => {
25
- const settings = {
26
- ...number.defaultSettings,
27
- ...userSettings,
28
- };
29
-
30
- const fallback = settings?.fallback ?? 0;
31
-
32
- let result: number;
33
-
34
- if (typeGuard.isNumber(input)) {
35
- result = input;
36
- } else if (typeGuard.isString(input)) {
37
- const formattedInput = skipSpaces(input).replace(',', '.');
38
- if (formattedInput === '') {
39
- result = fallback as any;
40
- } else {
41
- result = Number(formattedInput);
42
- }
43
- } else {
44
- result = fallback as any;
45
- }
46
-
47
- if (typeGuard.isNumber(result)) {
48
- if (settings?.clamped != null) {
49
- result = Math.max(
50
- settings.clamped[0] ?? -Infinity,
51
- Math.min(result, settings.clamped[1] ?? Infinity),
52
- );
53
- }
54
-
55
- if (settings?.ceil != null) {
56
- result = Math.ceil(result);
57
- }
58
-
59
- if (settings?.floor != null) {
60
- result = Math.floor(result);
61
- }
62
-
63
- if (settings?.digits != null) {
64
- result = +result.toFixed(settings.digits);
65
- }
66
-
67
- return result;
68
- } else {
69
- return fallback;
70
- }
71
- };
72
-
73
- number.defaultSettings = {} as NumberParserSettings;
@@ -1,11 +0,0 @@
1
- import type { Maybe } from '../utils/types.js';
2
-
3
- import { type NumberParserSettings, number } from './number.js';
4
-
5
- export const percent = <TFallback = number>(
6
- value: Maybe<string | number>,
7
- maxValue?: Maybe<string | number>,
8
- settings?: Maybe<NumberParserSettings<TFallback>>,
9
- ) => {
10
- return number<TFallback>((Number(value) / Number(maxValue)) * 100, settings);
11
- };
@@ -1,29 +0,0 @@
1
- import { typeGuard } from '../type-guard/index.js';
2
- import type { Maybe } from '../utils/types.js';
3
-
4
- export interface StringParserSettings<TFallback = string> {
5
- fallback?: TFallback;
6
- prettyJson?: boolean;
7
- }
8
-
9
- export const string = <TFallback = string>(
10
- input: Maybe<unknown>,
11
- settings?: Maybe<StringParserSettings<TFallback>>,
12
- ): string | TFallback => {
13
- const fallback =
14
- settings && 'fallback' in settings ? (settings.fallback as TFallback) : '';
15
-
16
- if (input == null) {
17
- return fallback;
18
- }
19
-
20
- if (typeGuard.isObject(input)) {
21
- if (settings?.prettyJson) {
22
- return JSON.stringify(input, null, 2);
23
- }
24
-
25
- return JSON.stringify(input);
26
- }
27
-
28
- return String(input);
29
- };
package/src/price.ts DELETED
@@ -1,33 +0,0 @@
1
- export interface PriceFormatOptions
2
- extends Partial<Omit<Intl.NumberFormatOptions, 'currency'>> {
3
- withoutSymbol?: boolean;
4
- customSymbol?: string;
5
- }
6
-
7
- export const formatPrice = (
8
- price: number,
9
- locale: string,
10
- currency?: string,
11
- { withoutSymbol, customSymbol, ...options }: PriceFormatOptions = {},
12
- ) => {
13
- const priceFormatter = new Intl.NumberFormat(locale, {
14
- style: 'currency',
15
- currency,
16
- minimumFractionDigits: 0,
17
- currencyDisplay: 'narrowSymbol',
18
- ...options,
19
- });
20
-
21
- const zeroPrice = priceFormatter.format(0);
22
- const currencySymbol = zeroPrice.replace('0', '');
23
- const rawPrice = priceFormatter.format(price);
24
- const priceWithoutCurrency = rawPrice.replace(currencySymbol, '');
25
-
26
- if (withoutSymbol) {
27
- return priceWithoutCurrency;
28
- }
29
-
30
- return `${priceWithoutCurrency} ${
31
- customSymbol ?? (currency === 'RUB' ? 'р' : currencySymbol)
32
- }`.replace(/\s{2,}/, ' ');
33
- };
package/src/random.ts DELETED
@@ -1,27 +0,0 @@
1
- export const getRandomFloat = <T extends number = number>(
2
- min = 0,
3
- max = 1,
4
- ): T => (Math.random() * (max - min) + min) as T;
5
-
6
- export const getRandomInt = <T extends number = number>(min = 0, max = 1): T =>
7
- min === max ? (min as T) : (Math.round(getRandomFloat(min, max)) as T);
8
-
9
- export const getRandomChoice = <T>(arr: T[]): T =>
10
- arr[getRandomInt(0, arr.length - 1)];
11
-
12
- export const getRandomSizeArray = (min = 0, max = 10) =>
13
- Array.from({ length: getRandomInt(min, max) }).fill(null);
14
-
15
- export const getRandomBool = () => getRandomInt(0, 1) === 1;
16
-
17
- export const getMajorRandomBool = () => {
18
- return getRandomInt(0, 10) <= 6;
19
- };
20
-
21
- export const getMinorRandomBool = () => {
22
- return !getMajorRandomBool();
23
- };
24
-
25
- export const getFrequencyValue = (frequency: number) => {
26
- return Math.random() < frequency;
27
- };
@@ -1,15 +0,0 @@
1
- import { useEffect } from 'react';
2
-
3
- import { useConstant } from './use-constant.js';
4
-
5
- export const useAbortController = () => {
6
- const controller = useConstant(() => new AbortController());
7
-
8
- useEffect(() => {
9
- return () => {
10
- controller.abort();
11
- };
12
- }, []);
13
-
14
- return controller;
15
- };
@@ -1,27 +0,0 @@
1
- import type { MutableRefObject } from 'react';
2
- import { useEventListener } from './use-event-listener.js';
3
-
4
- type ClickOutsideInput = {
5
- contentRef: MutableRefObject<HTMLElement | null>;
6
- onClick: VoidFunction;
7
- options?: AddEventListenerOptions;
8
- };
9
-
10
- export const useClickOutside = ({
11
- contentRef,
12
- onClick,
13
- options,
14
- }: ClickOutsideInput) => {
15
- useEventListener({
16
- event: 'mousedown',
17
- handler: (event) => {
18
- if (
19
- contentRef.current &&
20
- !contentRef.current.contains(event.target as Node)
21
- ) {
22
- onClick();
23
- }
24
- },
25
- options,
26
- });
27
- };
@@ -1,11 +0,0 @@
1
- import { useLayoutEffect, useRef } from 'react';
2
-
3
- export const useElementRef = <T extends HTMLElement>(selector: () => T) => {
4
- const ref = useRef<T>();
5
-
6
- useLayoutEffect(() => {
7
- ref.current = selector();
8
- }, []);
9
-
10
- return ref;
11
- };
@@ -1,29 +0,0 @@
1
- /* eslint-disable @typescript-eslint/ban-ts-comment */
2
- import { useEffect } from 'react';
3
- import { useSyncRef } from './use-sync-ref.js';
4
-
5
- export const useEventListener = <EventName extends keyof HTMLElementEventMap>({
6
- event,
7
- handler,
8
- options,
9
- deps = [],
10
- node = document,
11
- }: {
12
- event: EventName;
13
- handler: (e: HTMLElementEventMap[EventName]) => void;
14
- options?: boolean | AddEventListenerOptions;
15
- deps?: unknown[];
16
- node?: HTMLElement | Document | Window;
17
- }) => {
18
- const handlerRef = useSyncRef(handler);
19
-
20
- useEffect(() => {
21
- const handleEvent = (e: HTMLElementEventMap[EventName]) =>
22
- handlerRef.current(e);
23
-
24
- // @ts-expect-error
25
- node.addEventListener(event, handleEvent, options);
26
- // @ts-expect-error
27
- return () => node.removeEventListener(event, handleEvent, options);
28
- }, deps);
29
- };
@@ -1,23 +0,0 @@
1
- /**
2
- * A Hook to define an event handler with an always-stable function identity.
3
- *
4
- * borrowed from @gaeron
5
- * https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md
6
- */
7
- import { useCallback, useLayoutEffect, useRef } from 'react';
8
- import type { AnyFunction } from '../../utils/types.js';
9
-
10
- export const useEvent = <H extends AnyFunction>(handler: H): H => {
11
- const handlerRef = useRef<H>(handler);
12
-
13
- // In a real implementation, this would run before layout effects
14
- useLayoutEffect(() => {
15
- handlerRef.current = handler;
16
- });
17
-
18
- return useCallback((...args: unknown[]) => {
19
- // In a real implementation, this would throw if called during render
20
- const fn = handlerRef.current as AnyFunction;
21
- return fn(...args);
22
- }, []) as unknown as H;
23
- };
@@ -1,27 +0,0 @@
1
- import { useCallback, useRef, useState } from 'react';
2
-
3
- export interface FlagHook {
4
- enabled: boolean;
5
- toggle: VoidFunction;
6
- enable: VoidFunction;
7
- disable: VoidFunction;
8
- }
9
-
10
- export const useFlag = (defaultValue = false): FlagHook => {
11
- const [enabled, setEnabled] = useState(defaultValue);
12
-
13
- const toggle = useCallback(() => setEnabled((value) => !value), []);
14
- const enable = useCallback(() => setEnabled(true), []);
15
- const disable = useCallback(() => setEnabled(false), []);
16
-
17
- const flagObjRef = useRef<FlagHook>({
18
- enabled,
19
- toggle,
20
- enable,
21
- disable,
22
- });
23
-
24
- flagObjRef.current.enabled = enabled;
25
-
26
- return flagObjRef.current;
27
- };
@@ -1,9 +0,0 @@
1
- import { useCallback, useState } from 'react';
2
-
3
- export const useForceUpdate = () => {
4
- const [, setState] = useState<unknown>(null);
5
-
6
- return useCallback(() => {
7
- setState({});
8
- }, []);
9
- };
@@ -1,16 +0,0 @@
1
- import { useEffect, useRef, useState } from 'react';
2
-
3
- export const useInitialHeight = <T extends HTMLElement>() => {
4
- const ref = useRef<T | null>(null);
5
- const [initialHeight, setInitialHeight] = useState<number | undefined>(
6
- undefined,
7
- );
8
-
9
- useEffect(() => {
10
- if (ref.current && !initialHeight) {
11
- setInitialHeight(ref.current.offsetHeight);
12
- }
13
- }, [initialHeight]);
14
-
15
- return { ref, initialHeight };
16
- };
@@ -1,18 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
-
3
- export const useIntersectionObserver = (
4
- callback: IntersectionObserverCallback,
5
- options?: IntersectionObserverInit,
6
- ) => {
7
- const [intersectionObserver] = useState(
8
- () => new IntersectionObserver(callback, options),
9
- );
10
-
11
- useEffect(() => {
12
- return () => {
13
- intersectionObserver.disconnect();
14
- };
15
- }, []);
16
-
17
- return intersectionObserver;
18
- };
@@ -1,9 +0,0 @@
1
- import { useRef } from 'react';
2
-
3
- export const useLastDefinedValue = <T>(value: T) => {
4
- const ref = useRef(value);
5
- if (value != null) {
6
- ref.current = value;
7
- }
8
- return ref.current;
9
- };
@@ -1,11 +0,0 @@
1
- import { useRef } from 'react';
2
-
3
- export const useLastValueRef = <T>(value: T | null | undefined) => {
4
- const ref = useRef(value);
5
-
6
- if (value != null) {
7
- ref.current = value;
8
- }
9
-
10
- return ref;
11
- };
@@ -1,17 +0,0 @@
1
- import { useEffect } from 'react';
2
- import { useSyncRef } from './use-sync-ref.js';
3
-
4
- export const useLifeCycle = (
5
- fn: () => {
6
- mount?: VoidFunction;
7
- unmount?: VoidFunction;
8
- },
9
- ) => {
10
- const fnRef = useSyncRef(fn);
11
-
12
- useEffect(() => {
13
- const fnOperation = fnRef.current();
14
- fnOperation.mount?.();
15
- return fnOperation.unmount?.();
16
- }, []);
17
- };
@@ -1,14 +0,0 @@
1
- import { useLayoutEffect } from 'react';
2
- import { useDefineRef } from './use-define-ref.js';
3
-
4
- export const useResizeObserver = (callback: ResizeObserverCallback) => {
5
- const resizeObserverRef = useDefineRef(() => new ResizeObserver(callback));
6
-
7
- useLayoutEffect(() => {
8
- return () => {
9
- resizeObserverRef.current.disconnect();
10
- };
11
- }, []);
12
-
13
- return resizeObserverRef;
14
- };
@@ -1,7 +0,0 @@
1
- import { useRef } from 'react';
2
-
3
- export const useSyncRef = <T>(value: T) => {
4
- const ref = useRef(value);
5
- ref.current = value;
6
- return ref;
7
- };
@@ -1,9 +0,0 @@
1
- import { useCallback, useState } from 'react';
2
-
3
- export const useToggle = (initialState?: boolean) => {
4
- const [toggled, setToggled] = useState(!!initialState);
5
-
6
- const toggle = useCallback(() => setToggled((toggled) => !toggled), []);
7
-
8
- return [toggled, toggle, setToggled] as const;
9
- };
@@ -1,10 +0,0 @@
1
- import { useState } from 'react';
2
-
3
- export const useValue = <T>(defaults: T | (() => T)) => {
4
- const [value, setValue] = useState<T>(defaults);
5
-
6
- return {
7
- value,
8
- set: setValue,
9
- };
10
- };
@@ -1,19 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
-
3
- export const useVisibilityState = () => {
4
- const [state, setState] = useState<DocumentVisibilityState>();
5
-
6
- useEffect(() => {
7
- const handleVisibilityChange = () => {
8
- setState(document.visibilityState);
9
- };
10
-
11
- document.addEventListener('visibilitychange', handleVisibilityChange);
12
-
13
- return () => {
14
- document.removeEventListener('visibilitychange', handleVisibilityChange);
15
- };
16
- }, []);
17
-
18
- return state;
19
- };
package/src/sound.ts DELETED
@@ -1,15 +0,0 @@
1
- /**
2
- * Воспроизводит звук из файла
3
- */
4
- export const playSound = async (
5
- file: string,
6
- { volume = 1 }: { volume?: number } = {},
7
- ) => {
8
- let audio = new Audio(file);
9
- audio.volume = volume;
10
- audio.muted = !volume;
11
- await audio.play();
12
- audio.remove();
13
- // @ts-expect-error
14
- audio = null;
15
- };