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/css.ts DELETED
@@ -1,60 +0,0 @@
1
- import { cva as cvaLib } from 'class-variance-authority';
2
- import clsx, { type ClassValue } from 'clsx';
3
- import { twMerge } from 'tailwind-merge';
4
-
5
- type ClassProp = {
6
- class?: ClassValue;
7
- className?: ClassValue;
8
- };
9
-
10
- type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
11
-
12
- /**
13
- * Перевод значения в пикселях в rem строковое
14
- */
15
- export const toRem = (px: number, remValue = 16) => `${px / remValue}rem`;
16
-
17
- /**
18
- * classNames/clsx но с примесями tailwind-merge
19
- */
20
- export const cx = (...args: Parameters<typeof clsx>) => twMerge(clsx(...args));
21
-
22
- type ConfigSchema = Record<string, Record<string, ClassValue>>;
23
- type ConfigVariants<T extends ConfigSchema> = {
24
- [Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | null | undefined;
25
- };
26
- type ConfigVariantsMulti<T extends ConfigSchema> = {
27
- [Variant in keyof T]?:
28
- | StringToBoolean<keyof T[Variant]>
29
- | StringToBoolean<keyof T[Variant]>[]
30
- | undefined;
31
- };
32
- type Config<T> = T extends ConfigSchema
33
- ? {
34
- variants?: T;
35
- defaultVariants?: ConfigVariants<T>;
36
- compoundVariants?: (T extends ConfigSchema
37
- ? (ConfigVariants<T> | ConfigVariantsMulti<T>) & ClassProp
38
- : ClassProp)[];
39
- }
40
- : never;
41
-
42
- type Props<T> = T extends ConfigSchema
43
- ? ConfigVariants<T> & ClassProp
44
- : ClassProp;
45
-
46
- /**
47
- * Class Variance Authority но с примесями tailwind-merge
48
- *
49
- * https://cva.style/docs
50
- */
51
- export const cva = ((...args: any[]) => {
52
- const schema = cvaLib(...args);
53
- return (...inputArgs: any[]) => twMerge(schema(...inputArgs));
54
- }) as any as <T>(
55
- base?: ClassValue,
56
- config?: Config<T>,
57
- ) => (props?: Props<T>) => string;
58
-
59
- export type { VariantProps } from 'class-variance-authority';
60
- export type { ClassValue } from 'clsx';
package/src/data.test.ts DELETED
@@ -1,99 +0,0 @@
1
- import { describe } from 'node:test';
2
- import { expect, it } from 'vitest';
3
-
4
- import { isShallowEqual } from './data';
5
-
6
- describe('data tests', () => {
7
- describe('isShallowEqual', () => {
8
- it('two nulls', () => {
9
- expect(isShallowEqual(null, null)).toBeTruthy();
10
- });
11
-
12
- it('two undefineds', () => {
13
- expect(isShallowEqual(undefined, undefined)).toBeTruthy();
14
- });
15
-
16
- it('two empty objects', () => {
17
- expect(isShallowEqual({}, {})).toBeTruthy();
18
- });
19
-
20
- it('two empty arrays', () => {
21
- expect(isShallowEqual([], [])).toBeTruthy();
22
- });
23
-
24
- it('two empty arrays with different length', () => {
25
- expect(isShallowEqual([1], [])).toBeFalsy();
26
- });
27
-
28
- it('two arrays with same values', () => {
29
- expect(isShallowEqual([1, 2, 3], [1, 2, 3])).toBeTruthy();
30
- });
31
-
32
- it('two arrays with different order', () => {
33
- expect(isShallowEqual([1, 2, 3], [3, 2, 1])).toBeFalsy();
34
- });
35
-
36
- it('two arrays with different length', () => {
37
- expect(isShallowEqual([1, 2, 3], [1, 2, 3, 4])).toBeFalsy();
38
- });
39
-
40
- it('two objects with same keys and values', () => {
41
- expect(isShallowEqual({ a: 1, b: 2 }, { a: 1, b: 2 })).toBeTruthy();
42
- });
43
-
44
- it('two objects with same keys and values in different order', () => {
45
- expect(isShallowEqual({ a: 1, b: 2 }, { b: 2, a: 1 })).toBeTruthy();
46
- });
47
-
48
- it('two objects with different keys', () => {
49
- expect(isShallowEqual({ a: 1, b: 2 }, { a: 1, c: 2 })).toBeFalsy();
50
- });
51
-
52
- it('two objects with same keys and different values', () => {
53
- expect(isShallowEqual({ a: 1, b: 2 }, { a: 1, b: 3 })).toBeFalsy();
54
- });
55
-
56
- it('two objects with same keys, different values and different order', () => {
57
- expect(isShallowEqual({ a: 1, b: 2 }, { b: 3, a: 1 })).toBeFalsy();
58
- });
59
-
60
- it('two objects with extra key on first object', () => {
61
- expect(isShallowEqual({ a: 1, b: 2, c: 3 }, { a: 1, b: 2 })).toBeFalsy();
62
- });
63
-
64
- it('two objects with extra key on second object', () => {
65
- expect(isShallowEqual({ a: 1, b: 2 }, { a: 1, b: 2, c: 3 })).toBeFalsy();
66
- });
67
- it('first is null, second is object', () => {
68
- expect(isShallowEqual(null, { a: 1 })).toBeFalsy();
69
- });
70
-
71
- it('first is object, second is null', () => {
72
- expect(isShallowEqual({ a: 1 }, null)).toBeFalsy();
73
- });
74
-
75
- it('first is undefined, second is object', () => {
76
- expect(isShallowEqual(undefined, { a: 1 })).toBeFalsy();
77
- });
78
-
79
- it('first is object, second is undefined', () => {
80
- expect(isShallowEqual({ a: 1 }, undefined)).toBeFalsy();
81
- });
82
-
83
- it('two objects with different class but same keys and values', () => {
84
- class A {
85
- constructor(
86
- public a: number,
87
- public b: number,
88
- ) {}
89
- }
90
- class B {
91
- constructor(
92
- public a: number,
93
- public b: number,
94
- ) {}
95
- }
96
- expect(isShallowEqual(new A(1, 2), new B(1, 2))).toBeFalsy();
97
- });
98
- });
99
- });
package/src/data.ts DELETED
@@ -1,65 +0,0 @@
1
- import type { AnyObject } from './utils/types.js';
2
-
3
- export const isShallowEqual = (a: unknown, b: unknown): boolean => {
4
- if (a === b) return true;
5
-
6
- if (
7
- typeof a !== 'object' ||
8
- typeof b !== 'object' ||
9
- a === null ||
10
- b === null
11
- ) {
12
- return false;
13
- }
14
-
15
- if (a.constructor !== b.constructor) return false;
16
-
17
- const isArrayA = Array.isArray(a);
18
-
19
- if (isArrayA !== Array.isArray(b)) return false;
20
-
21
- if (isArrayA) {
22
- const arrA = a as unknown[];
23
- const arrB = b as unknown[];
24
- if (arrA.length !== arrB.length) return false;
25
-
26
- for (const [i, element] of arrA.entries()) {
27
- if (element !== arrB[i]) return false;
28
- }
29
- return true;
30
- }
31
-
32
- if (a instanceof Date) return a.getTime() === (b as Date).getTime();
33
-
34
- if (a instanceof RegExp) return a.toString() === (b as RegExp).toString();
35
-
36
- const aKeys = Object.keys(a);
37
- const bKeys = Object.keys(b);
38
-
39
- if (aKeys.length !== bKeys.length) return false;
40
-
41
- const bObj = b as AnyObject;
42
- for (const key of aKeys) {
43
- if (!Object.hasOwn(bObj, key) || (a as AnyObject)[key] !== bObj[key]) {
44
- return false;
45
- }
46
- }
47
-
48
- return true;
49
- };
50
-
51
- export const flatMapDeep = <TSource, TNewValue>(
52
- arr: TSource | TSource[],
53
- fn: (value: TSource, i: number, arr: TSource[]) => TNewValue,
54
- ): TNewValue[] =>
55
- Array.isArray(arr)
56
- ? arr.flatMap((c: TSource): TNewValue[] => flatMapDeep(c, fn))
57
- : [fn(arr, 0, [arr])];
58
-
59
- export const safeJsonParse = (json: string) => {
60
- try {
61
- return JSON.parse(json);
62
- } catch {
63
- return null;
64
- }
65
- };
@@ -1,119 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
-
3
- import {
4
- changeDate,
5
- dayTimeDuration,
6
- getFormatDuration,
7
- timeDuration,
8
- } from './date-time.js';
9
- import { unitsToMs } from './ms.js';
10
-
11
- describe('date-time', () => {
12
- describe('dayTimeDuration', () => {
13
- test('-1 minute', () => {
14
- expect(dayTimeDuration(-unitsToMs.min)).toStrictEqual({
15
- days: 0,
16
- hours: 0,
17
- seconds: 0,
18
- minutes: 0,
19
- milliseconds: 0,
20
- });
21
- });
22
-
23
- test('1 minute', () => {
24
- expect(dayTimeDuration(unitsToMs.min)).toStrictEqual({
25
- days: 0,
26
- hours: 0,
27
- seconds: 0,
28
- minutes: 1,
29
- milliseconds: 0,
30
- });
31
- });
32
-
33
- test('30 minutes 45 seconds', () => {
34
- expect(
35
- dayTimeDuration(unitsToMs.min * 30 + unitsToMs.sec * 45),
36
- ).toStrictEqual({
37
- days: 0,
38
- hours: 0,
39
- seconds: 45,
40
- minutes: 30,
41
- milliseconds: 0,
42
- });
43
- });
44
-
45
- test('34 days 59 minutes 59 seconds', () => {
46
- expect(
47
- dayTimeDuration(
48
- 34 * unitsToMs.day + unitsToMs.min * 59 + unitsToMs.sec * 59,
49
- ),
50
- ).toStrictEqual({
51
- days: 34,
52
- hours: 0,
53
- minutes: 59,
54
- seconds: 59,
55
- milliseconds: 0,
56
- });
57
- });
58
- });
59
- describe('timeDuration', () => {
60
- test('-1 minute', () => {
61
- expect(timeDuration(-unitsToMs.min)).toStrictEqual({
62
- hours: 0,
63
- seconds: 0,
64
- minutes: 0,
65
- milliseconds: 0,
66
- });
67
- });
68
-
69
- test('1 minute', () => {
70
- expect(timeDuration(unitsToMs.min)).toStrictEqual({
71
- hours: 0,
72
- seconds: 0,
73
- minutes: 1,
74
- milliseconds: 0,
75
- });
76
- });
77
-
78
- test('30 minutes 45 seconds', () => {
79
- expect(
80
- timeDuration(unitsToMs.min * 30 + unitsToMs.sec * 45),
81
- ).toStrictEqual({
82
- hours: 0,
83
- seconds: 45,
84
- minutes: 30,
85
- milliseconds: 0,
86
- });
87
- });
88
-
89
- test('34 days 59 minutes 59 seconds', () => {
90
- expect(
91
- timeDuration(
92
- 34 * unitsToMs.day + unitsToMs.min * 59 + unitsToMs.sec * 59,
93
- ),
94
- ).toStrictEqual({
95
- hours: 2_937_600_000,
96
- minutes: 59,
97
- seconds: 59,
98
- milliseconds: 0,
99
- });
100
- });
101
- });
102
- describe('getFormatDuration', () => {
103
- test('30 minutes', () => {
104
- const dateA = new Date(`2025-02-10T09:53:00.000Z`);
105
- const dateB = changeDate(dateA, 30, 'minutes');
106
- expect(getFormatDuration(dateA, dateB)).toBe('30 минут');
107
- });
108
- test('2 hours 45 minutes 10 seconds', () => {
109
- const dateA = new Date(`2025-02-10T09:53:00.000Z`);
110
- const dateB = changeDate(dateA, 2, 'hours', 45, 'minutes', 10, 'seconds');
111
- expect(getFormatDuration(dateA, dateB)).toBe('2 часа 45 минут 10 секунд');
112
- });
113
- test('2 hours 45 minutes 10 seconds (compact)', () => {
114
- const dateA = new Date(`2025-02-10T09:53:00.000Z`);
115
- const dateB = changeDate(dateA, 2, 'hours', 45, 'minutes', 10, 'seconds');
116
- expect(getFormatDuration(dateA, dateB, true)).toBe('2 ч 45 мин 10 сек');
117
- });
118
- });
119
- });
package/src/date-time.ts DELETED
@@ -1,236 +0,0 @@
1
- import dayjs, { type Dayjs, type ManipulateType } from 'dayjs';
2
- import duration from 'dayjs/plugin/duration.js';
3
- import relativeTime from 'dayjs/plugin/relativeTime.js';
4
-
5
- import { format } from './format/index.js';
6
- import { unitsToMs } from './ms.js';
7
- import { declension } from './text.js';
8
- import { typeGuard } from './type-guard/index.js';
9
- import type { Maybe } from './utils/types.js';
10
-
11
- import 'dayjs/locale/ru.js';
12
-
13
- dayjs.extend(relativeTime);
14
- dayjs.extend(duration);
15
- dayjs.locale('ru');
16
-
17
- const toLibFormat = (
18
- value: Maybe<RawDateToFormat>,
19
- asTime?: boolean,
20
- ): Dayjs => {
21
- if (typeGuard.isNumber(value)) {
22
- if (asTime) {
23
- return dayjs.duration(value) as unknown as Dayjs;
24
- }
25
- return dayjs(value);
26
- } else if (dayjs.isDayjs(value)) {
27
- return value;
28
- } else {
29
- return dayjs(value);
30
- }
31
- };
32
-
33
- export type RawDateToFormat = Date | string | number | Dayjs;
34
-
35
- export const formatDate = (
36
- value: Maybe<RawDateToFormat>,
37
- settings?: Maybe<{
38
- format?:
39
- | 'human'
40
- | 'full'
41
- | 'short'
42
- | 'day'
43
- | 'day-only'
44
- | 'date'
45
- | 'month'
46
- | 'spent-time'
47
- | 'time'
48
- | 'time-short';
49
- pattern?: string;
50
- asTime?: boolean;
51
- }>,
52
- ) => {
53
- const dateFormat = settings?.format;
54
- const datePattern = settings?.pattern;
55
- const asTime = settings?.asTime;
56
-
57
- value = toLibFormat(value, asTime);
58
-
59
- if (typeGuard.isUndefined(value) || !value.isValid()) {
60
- return format.NO_VALUE;
61
- }
62
-
63
- if (datePattern) {
64
- return value.format(datePattern);
65
- }
66
-
67
- switch (dateFormat) {
68
- case 'human': {
69
- return value.fromNow();
70
- }
71
- case 'spent-time': {
72
- return value.fromNow(true);
73
- }
74
- case 'full': {
75
- return value.format('DD MMM YYYY HH:mm:ss');
76
- }
77
- case 'short': {
78
- return value.format('DD MMM HH:mm');
79
- }
80
- case 'time': {
81
- return value.format('HH:mm:ss');
82
- }
83
- case 'time-short': {
84
- return value.format('HH:mm');
85
- }
86
- case 'day': {
87
- return value.format('DD MMM YYYY');
88
- }
89
- case 'month': {
90
- return value.format('MMMM YYYY');
91
- }
92
- default: {
93
- return value.format('DD.MM.YYYY');
94
- }
95
- }
96
- };
97
-
98
- export const dayTimeDuration = (timeInMs: number) => {
99
- let left = Math.max(timeInMs, 0);
100
-
101
- const days = Math.floor(left / unitsToMs.day);
102
- left = left % unitsToMs.day;
103
-
104
- const hours = Math.floor(left / unitsToMs.hour);
105
- left = left % unitsToMs.hour;
106
-
107
- const minutes = Math.floor(left / unitsToMs.min);
108
- left = left % unitsToMs.min;
109
-
110
- const seconds = Math.floor(left / unitsToMs.sec);
111
- left = left % unitsToMs.sec;
112
-
113
- const milliseconds = Math.floor(left);
114
-
115
- return {
116
- days,
117
- hours,
118
- minutes,
119
- seconds,
120
- milliseconds,
121
- };
122
- };
123
-
124
- type DateChangeParam = [amount: number, unit?: Maybe<ManipulateType>];
125
-
126
- export const changeDate = (
127
- date: Maybe<RawDateToFormat>,
128
- ...args: [
129
- ...DateChangeParam,
130
- ...Partial<DateChangeParam>,
131
- ...Partial<DateChangeParam>,
132
- ...Partial<DateChangeParam>,
133
- ...Partial<DateChangeParam>,
134
- ...Partial<DateChangeParam>,
135
- ]
136
- ) => {
137
- let wrappedDate = toLibFormat(date);
138
-
139
- for (let i = 0; i < args.length; i += 2) {
140
- const amount = args[i] as DateChangeParam[0];
141
- const unit = args[i + 1] as DateChangeParam[1];
142
- if (unit != null) {
143
- wrappedDate = wrappedDate.add(amount, unit);
144
- }
145
- }
146
-
147
- return wrappedDate.toDate();
148
- };
149
-
150
- export const timeDuration = (timeInMs: number) => {
151
- const { days, hours, milliseconds, minutes, seconds } =
152
- dayTimeDuration(timeInMs);
153
-
154
- return {
155
- hours: hours + unitsToMs.day * days,
156
- milliseconds,
157
- minutes,
158
- seconds,
159
- };
160
- };
161
-
162
- const durationFormatLabels = {
163
- days: { compact: 'д', full: ['день', 'дня', 'дней'] },
164
- hours: { compact: 'ч', full: ['час', 'часа', 'часов'] },
165
- minutes: { compact: 'мин', full: ['минута', 'минуты', 'минут'] },
166
- seconds: { compact: 'сек', full: ['секунда', 'секунды', 'секунд'] },
167
- } as const;
168
-
169
- export function getFormatDuration(
170
- dateA: Date,
171
- dateB: Date,
172
- compact?: boolean,
173
- ): string;
174
- export function getFormatDuration(ms: number, compact?: boolean): string;
175
-
176
- export function getFormatDuration(...args: any[]): string {
177
- let compact = false;
178
- let diff = 0;
179
-
180
- if (args[0] instanceof Date) {
181
- const startedDate = dayjs(args[0]);
182
- const endedDate = dayjs(args[1]);
183
-
184
- diff = endedDate.diff(startedDate, 'ms');
185
- compact = args[2] === true;
186
- } else {
187
- diff = args[0];
188
- compact = args[1] === true;
189
- }
190
-
191
- const { days, hours, minutes, seconds } = dayTimeDuration(diff);
192
-
193
- const formattedParts: string[] = [];
194
-
195
- if (days) {
196
- if (compact) {
197
- formattedParts.push(`${days} ${durationFormatLabels.days.compact}`);
198
- } else {
199
- formattedParts.push(
200
- `${days} ${declension(days, durationFormatLabels.days.full)}`,
201
- );
202
- }
203
- }
204
-
205
- if (hours) {
206
- if (compact) {
207
- formattedParts.push(`${hours} ${durationFormatLabels.hours.compact}`);
208
- } else {
209
- formattedParts.push(
210
- `${hours} ${declension(hours, durationFormatLabels.hours.full)}`,
211
- );
212
- }
213
- }
214
-
215
- if (minutes) {
216
- if (compact) {
217
- formattedParts.push(`${minutes} ${durationFormatLabels.minutes.compact}`);
218
- } else {
219
- formattedParts.push(
220
- `${minutes} ${declension(minutes, durationFormatLabels.minutes.full)}`,
221
- );
222
- }
223
- }
224
-
225
- if (seconds) {
226
- if (compact) {
227
- formattedParts.push(`${seconds} ${durationFormatLabels.seconds.compact}`);
228
- } else {
229
- formattedParts.push(
230
- `${seconds} ${declension(seconds, durationFormatLabels.seconds.full)}`,
231
- );
232
- }
233
- }
234
-
235
- return formattedParts.join(' ');
236
- }
package/src/device.ts DELETED
@@ -1,42 +0,0 @@
1
- export const getUserAgent = () =>
2
- (
3
- navigator.userAgent ||
4
- navigator.vendor ||
5
- // @ts-expect-error skip opera
6
- globalThis.opera ||
7
- ''
8
- ).toLowerCase();
9
-
10
- export const checkIsMobileDevice = () => {
11
- const userAgent = getUserAgent();
12
-
13
- if (
14
- /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(
15
- userAgent || '',
16
- ) ||
17
- /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(
18
- (userAgent || '').slice(0, 4),
19
- )
20
- ) {
21
- return true;
22
- }
23
-
24
- return false;
25
- };
26
-
27
- export const checkIsTabletDevice = () => {
28
- const userAgent = getUserAgent();
29
-
30
- return /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(
31
- userAgent,
32
- );
33
- };
34
-
35
- export const checkIsTouchDevice = () =>
36
- checkIsMobileDevice() || checkIsTabletDevice();
37
-
38
- export const isMobileDevice = checkIsMobileDevice();
39
-
40
- export const isTabletDevice = checkIsTabletDevice();
41
-
42
- export const isTouchDevice = isMobileDevice || isTabletDevice;