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/date-time.js ADDED
@@ -0,0 +1,160 @@
1
+ import dayjs from 'dayjs';
2
+ import duration from 'dayjs/plugin/duration.js';
3
+ import relativeTime from 'dayjs/plugin/relativeTime.js';
4
+ import { format } from './format/index.js';
5
+ import { unitsToMs } from './ms.js';
6
+ import { declension } from './text.js';
7
+ import { typeGuard } from './type-guard/index.js';
8
+ import 'dayjs/locale/ru.js';
9
+ dayjs.extend(relativeTime);
10
+ dayjs.extend(duration);
11
+ dayjs.locale('ru');
12
+ const toLibFormat = (value, asTime) => {
13
+ if (typeGuard.isNumber(value)) {
14
+ if (asTime) {
15
+ return dayjs.duration(value);
16
+ }
17
+ return dayjs(value);
18
+ }
19
+ else if (dayjs.isDayjs(value)) {
20
+ return value;
21
+ }
22
+ else {
23
+ return dayjs(value);
24
+ }
25
+ };
26
+ export const formatDate = (value, settings) => {
27
+ const dateFormat = settings?.format;
28
+ const datePattern = settings?.pattern;
29
+ const asTime = settings?.asTime;
30
+ value = toLibFormat(value, asTime);
31
+ if (typeGuard.isUndefined(value) || !value.isValid()) {
32
+ return format.NO_VALUE;
33
+ }
34
+ if (datePattern) {
35
+ return value.format(datePattern);
36
+ }
37
+ switch (dateFormat) {
38
+ case 'human': {
39
+ return value.fromNow();
40
+ }
41
+ case 'spent-time': {
42
+ return value.fromNow(true);
43
+ }
44
+ case 'full': {
45
+ return value.format('DD MMM YYYY HH:mm:ss');
46
+ }
47
+ case 'short': {
48
+ return value.format('DD MMM HH:mm');
49
+ }
50
+ case 'time': {
51
+ return value.format('HH:mm:ss');
52
+ }
53
+ case 'time-short': {
54
+ return value.format('HH:mm');
55
+ }
56
+ case 'day': {
57
+ return value.format('DD MMM YYYY');
58
+ }
59
+ case 'month': {
60
+ return value.format('MMMM YYYY');
61
+ }
62
+ default: {
63
+ return value.format('DD.MM.YYYY');
64
+ }
65
+ }
66
+ };
67
+ export const dayTimeDuration = (timeInMs) => {
68
+ let left = Math.max(timeInMs, 0);
69
+ const days = Math.floor(left / unitsToMs.day);
70
+ left = left % unitsToMs.day;
71
+ const hours = Math.floor(left / unitsToMs.hour);
72
+ left = left % unitsToMs.hour;
73
+ const minutes = Math.floor(left / unitsToMs.min);
74
+ left = left % unitsToMs.min;
75
+ const seconds = Math.floor(left / unitsToMs.sec);
76
+ left = left % unitsToMs.sec;
77
+ const milliseconds = Math.floor(left);
78
+ return {
79
+ days,
80
+ hours,
81
+ minutes,
82
+ seconds,
83
+ milliseconds,
84
+ };
85
+ };
86
+ export const changeDate = (date, ...args) => {
87
+ let wrappedDate = toLibFormat(date);
88
+ for (let i = 0; i < args.length; i += 2) {
89
+ const amount = args[i];
90
+ const unit = args[i + 1];
91
+ if (unit != null) {
92
+ wrappedDate = wrappedDate.add(amount, unit);
93
+ }
94
+ }
95
+ return wrappedDate.toDate();
96
+ };
97
+ export const timeDuration = (timeInMs) => {
98
+ const { days, hours, milliseconds, minutes, seconds } = dayTimeDuration(timeInMs);
99
+ return {
100
+ hours: hours + unitsToMs.day * days,
101
+ milliseconds,
102
+ minutes,
103
+ seconds,
104
+ };
105
+ };
106
+ const durationFormatLabels = {
107
+ days: { compact: 'д', full: ['день', 'дня', 'дней'] },
108
+ hours: { compact: 'ч', full: ['час', 'часа', 'часов'] },
109
+ minutes: { compact: 'мин', full: ['минута', 'минуты', 'минут'] },
110
+ seconds: { compact: 'сек', full: ['секунда', 'секунды', 'секунд'] },
111
+ };
112
+ export function getFormatDuration(...args) {
113
+ let compact = false;
114
+ let diff = 0;
115
+ if (args[0] instanceof Date) {
116
+ const startedDate = dayjs(args[0]);
117
+ const endedDate = dayjs(args[1]);
118
+ diff = endedDate.diff(startedDate, 'ms');
119
+ compact = args[2] === true;
120
+ }
121
+ else {
122
+ diff = args[0];
123
+ compact = args[1] === true;
124
+ }
125
+ const { days, hours, minutes, seconds } = dayTimeDuration(diff);
126
+ const formattedParts = [];
127
+ if (days) {
128
+ if (compact) {
129
+ formattedParts.push(`${days} ${durationFormatLabels.days.compact}`);
130
+ }
131
+ else {
132
+ formattedParts.push(`${days} ${declension(days, durationFormatLabels.days.full)}`);
133
+ }
134
+ }
135
+ if (hours) {
136
+ if (compact) {
137
+ formattedParts.push(`${hours} ${durationFormatLabels.hours.compact}`);
138
+ }
139
+ else {
140
+ formattedParts.push(`${hours} ${declension(hours, durationFormatLabels.hours.full)}`);
141
+ }
142
+ }
143
+ if (minutes) {
144
+ if (compact) {
145
+ formattedParts.push(`${minutes} ${durationFormatLabels.minutes.compact}`);
146
+ }
147
+ else {
148
+ formattedParts.push(`${minutes} ${declension(minutes, durationFormatLabels.minutes.full)}`);
149
+ }
150
+ }
151
+ if (seconds) {
152
+ if (compact) {
153
+ formattedParts.push(`${seconds} ${durationFormatLabels.seconds.compact}`);
154
+ }
155
+ else {
156
+ formattedParts.push(`${seconds} ${declension(seconds, durationFormatLabels.seconds.full)}`);
157
+ }
158
+ }
159
+ return formattedParts.join(' ');
160
+ }
package/device.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export declare const getUserAgent: () => any;
2
+ export declare const checkIsMobileDevice: () => boolean;
3
+ export declare const checkIsTabletDevice: () => boolean;
4
+ export declare const checkIsTouchDevice: () => boolean;
5
+ export declare const isMobileDevice: boolean;
6
+ export declare const isTabletDevice: boolean;
7
+ export declare const isTouchDevice: boolean;
8
+ //# sourceMappingURL=device.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,WAOR,CAAC;AAElB,eAAO,MAAM,mBAAmB,eAe/B,CAAC;AAEF,eAAO,MAAM,mBAAmB,eAM/B,CAAC;AAEF,eAAO,MAAM,kBAAkB,eACiB,CAAC;AAEjD,eAAO,MAAM,cAAc,SAAwB,CAAC;AAEpD,eAAO,MAAM,cAAc,SAAwB,CAAC;AAEpD,eAAO,MAAM,aAAa,SAAmC,CAAC"}
package/device.js ADDED
@@ -0,0 +1,21 @@
1
+ export const getUserAgent = () => (navigator.userAgent ||
2
+ navigator.vendor ||
3
+ // @ts-expect-error skip opera
4
+ globalThis.opera ||
5
+ '').toLowerCase();
6
+ export const checkIsMobileDevice = () => {
7
+ const userAgent = getUserAgent();
8
+ if (/(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(userAgent || '') ||
9
+ /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((userAgent || '').slice(0, 4))) {
10
+ return true;
11
+ }
12
+ return false;
13
+ };
14
+ export const checkIsTabletDevice = () => {
15
+ const userAgent = getUserAgent();
16
+ return /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(userAgent);
17
+ };
18
+ export const checkIsTouchDevice = () => checkIsMobileDevice() || checkIsTabletDevice();
19
+ export const isMobileDevice = checkIsMobileDevice();
20
+ export const isTabletDevice = checkIsTabletDevice();
21
+ export const isTouchDevice = isMobileDevice || isTabletDevice;
package/encodings.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function unicodeToWin1251(s: string): string;
2
+ //# sourceMappingURL=encodings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encodings.d.ts","sourceRoot":"","sources":["../src/encodings.ts"],"names":[],"mappings":"AAoQA,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,UASzC"}
package/encodings.js ADDED
@@ -0,0 +1,267 @@
1
+ const DMap = {
2
+ 0: 0,
3
+ 1: 1,
4
+ 2: 2,
5
+ 3: 3,
6
+ 4: 4,
7
+ 5: 5,
8
+ 6: 6,
9
+ 7: 7,
10
+ 8: 8,
11
+ 9: 9,
12
+ 10: 10,
13
+ 11: 11,
14
+ 12: 12,
15
+ 13: 13,
16
+ 14: 14,
17
+ 15: 15,
18
+ 16: 16,
19
+ 17: 17,
20
+ 18: 18,
21
+ 19: 19,
22
+ 20: 20,
23
+ 21: 21,
24
+ 22: 22,
25
+ 23: 23,
26
+ 24: 24,
27
+ 25: 25,
28
+ 26: 26,
29
+ 27: 27,
30
+ 28: 28,
31
+ 29: 29,
32
+ 30: 30,
33
+ 31: 31,
34
+ 32: 32,
35
+ 33: 33,
36
+ 34: 34,
37
+ 35: 35,
38
+ 36: 36,
39
+ 37: 37,
40
+ 38: 38,
41
+ 39: 39,
42
+ 40: 40,
43
+ 41: 41,
44
+ 42: 42,
45
+ 43: 43,
46
+ 44: 44,
47
+ 45: 45,
48
+ 46: 46,
49
+ 47: 47,
50
+ 48: 48,
51
+ 49: 49,
52
+ 50: 50,
53
+ 51: 51,
54
+ 52: 52,
55
+ 53: 53,
56
+ 54: 54,
57
+ 55: 55,
58
+ 56: 56,
59
+ 57: 57,
60
+ 58: 58,
61
+ 59: 59,
62
+ 60: 60,
63
+ 61: 61,
64
+ 62: 62,
65
+ 63: 63,
66
+ 64: 64,
67
+ 65: 65,
68
+ 66: 66,
69
+ 67: 67,
70
+ 68: 68,
71
+ 69: 69,
72
+ 70: 70,
73
+ 71: 71,
74
+ 72: 72,
75
+ 73: 73,
76
+ 74: 74,
77
+ 75: 75,
78
+ 76: 76,
79
+ 77: 77,
80
+ 78: 78,
81
+ 79: 79,
82
+ 80: 80,
83
+ 81: 81,
84
+ 82: 82,
85
+ 83: 83,
86
+ 84: 84,
87
+ 85: 85,
88
+ 86: 86,
89
+ 87: 87,
90
+ 88: 88,
91
+ 89: 89,
92
+ 90: 90,
93
+ 91: 91,
94
+ 92: 92,
95
+ 93: 93,
96
+ 94: 94,
97
+ 95: 95,
98
+ 96: 96,
99
+ 97: 97,
100
+ 98: 98,
101
+ 99: 99,
102
+ 100: 100,
103
+ 101: 101,
104
+ 102: 102,
105
+ 103: 103,
106
+ 104: 104,
107
+ 105: 105,
108
+ 106: 106,
109
+ 107: 107,
110
+ 108: 108,
111
+ 109: 109,
112
+ 110: 110,
113
+ 111: 111,
114
+ 112: 112,
115
+ 113: 113,
116
+ 114: 114,
117
+ 115: 115,
118
+ 116: 116,
119
+ 117: 117,
120
+ 118: 118,
121
+ 119: 119,
122
+ 120: 120,
123
+ 121: 121,
124
+ 122: 122,
125
+ 123: 123,
126
+ 124: 124,
127
+ 125: 125,
128
+ 126: 126,
129
+ 127: 127,
130
+ 1027: 129,
131
+ 8225: 135,
132
+ 1046: 198,
133
+ 8222: 132,
134
+ 1047: 199,
135
+ 1168: 165,
136
+ 1048: 200,
137
+ 1113: 154,
138
+ 1049: 201,
139
+ 1045: 197,
140
+ 1050: 202,
141
+ 1028: 170,
142
+ 160: 160,
143
+ 1040: 192,
144
+ 1051: 203,
145
+ 164: 164,
146
+ 166: 166,
147
+ 167: 167,
148
+ 169: 169,
149
+ 171: 171,
150
+ 172: 172,
151
+ 173: 173,
152
+ 174: 174,
153
+ 1053: 205,
154
+ 176: 176,
155
+ 177: 177,
156
+ 1114: 156,
157
+ 181: 181,
158
+ 182: 182,
159
+ 183: 183,
160
+ 8221: 148,
161
+ 187: 187,
162
+ 1029: 189,
163
+ 1056: 208,
164
+ 1057: 209,
165
+ 1058: 210,
166
+ 8364: 136,
167
+ 1112: 188,
168
+ 1115: 158,
169
+ 1059: 211,
170
+ 1060: 212,
171
+ 1030: 178,
172
+ 1061: 213,
173
+ 1062: 214,
174
+ 1063: 215,
175
+ 1116: 157,
176
+ 1064: 216,
177
+ 1065: 217,
178
+ 1031: 175,
179
+ 1066: 218,
180
+ 1067: 219,
181
+ 1068: 220,
182
+ 1069: 221,
183
+ 1070: 222,
184
+ 1032: 163,
185
+ 8226: 149,
186
+ 1071: 223,
187
+ 1072: 224,
188
+ 8482: 153,
189
+ 1073: 225,
190
+ 8240: 137,
191
+ 1118: 162,
192
+ 1074: 226,
193
+ 1110: 179,
194
+ 8230: 133,
195
+ 1075: 227,
196
+ 1033: 138,
197
+ 1076: 228,
198
+ 1077: 229,
199
+ 8211: 150,
200
+ 1078: 230,
201
+ 1119: 159,
202
+ 1079: 231,
203
+ 1042: 194,
204
+ 1080: 232,
205
+ 1034: 140,
206
+ 1025: 168,
207
+ 1081: 233,
208
+ 1082: 234,
209
+ 8212: 151,
210
+ 1083: 235,
211
+ 1169: 180,
212
+ 1084: 236,
213
+ 1052: 204,
214
+ 1085: 237,
215
+ 1035: 142,
216
+ 1086: 238,
217
+ 1087: 239,
218
+ 1088: 240,
219
+ 1089: 241,
220
+ 1090: 242,
221
+ 1036: 141,
222
+ 1041: 193,
223
+ 1091: 243,
224
+ 1092: 244,
225
+ 8224: 134,
226
+ 1093: 245,
227
+ 8470: 185,
228
+ 1094: 246,
229
+ 1054: 206,
230
+ 1095: 247,
231
+ 1096: 248,
232
+ 8249: 139,
233
+ 1097: 249,
234
+ 1098: 250,
235
+ 1044: 196,
236
+ 1099: 251,
237
+ 1111: 191,
238
+ 1055: 207,
239
+ 1100: 252,
240
+ 1038: 161,
241
+ 8220: 147,
242
+ 1101: 253,
243
+ 8250: 155,
244
+ 1102: 254,
245
+ 8216: 145,
246
+ 1103: 255,
247
+ 1043: 195,
248
+ 1105: 184,
249
+ 1039: 143,
250
+ 1026: 128,
251
+ 1106: 144,
252
+ 8218: 130,
253
+ 1107: 131,
254
+ 8217: 146,
255
+ 1108: 186,
256
+ 1109: 190,
257
+ };
258
+ export function unicodeToWin1251(s) {
259
+ const L = [];
260
+ for (let i = 0; i < s.length; i++) {
261
+ const ord = s.charCodeAt(i);
262
+ if (!(ord in DMap))
263
+ throw new Error(`Character ${s.charAt(i)} isn't supported by win1251!`);
264
+ L.push(String.fromCharCode(DMap[ord]));
265
+ }
266
+ return L.join('');
267
+ }
package/errors.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import type { Maybe } from './utils/types.js';
2
+ type GetErrorTextEnhancer = (error: any) => string;
3
+ type GetErrorTextFormatErrorFn = (error: Error) => string;
4
+ /**
5
+ * Universal function for transforming any errors into readable error text
6
+ *
7
+ * This function can be enhanced with custom handlers using:
8
+ * - `getErrorText.unknownErrorText`
9
+ * - `getErrorText.formatError`
10
+ * - `getErrorText.enhance`
11
+ */
12
+ export declare const getErrorText: {
13
+ (error: unknown): string;
14
+ unknownErrorText: string;
15
+ formatError: Maybe<GetErrorTextFormatErrorFn>;
16
+ enhance: Maybe<GetErrorTextEnhancer>;
17
+ };
18
+ export {};
19
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C,KAAK,oBAAoB,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,MAAM,CAAC;AACnD,KAAK,yBAAyB,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,CAAC;AAE1D;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY;YAAW,OAAO;;;;CAqB1C,CAAC"}
package/errors.js ADDED
@@ -0,0 +1,30 @@
1
+ import { typeGuard } from './type-guard/index.js';
2
+ /**
3
+ * Universal function for transforming any errors into readable error text
4
+ *
5
+ * This function can be enhanced with custom handlers using:
6
+ * - `getErrorText.unknownErrorText`
7
+ * - `getErrorText.formatError`
8
+ * - `getErrorText.enhance`
9
+ */
10
+ export const getErrorText = (error) => {
11
+ if (!error) {
12
+ return getErrorText.unknownErrorText;
13
+ }
14
+ if (typeGuard.isString(error)) {
15
+ return error || getErrorText.unknownErrorText;
16
+ }
17
+ if (error instanceof Error) {
18
+ return ((getErrorText.formatError?.(error) ?? error.message) ||
19
+ getErrorText.unknownErrorText);
20
+ }
21
+ if (getErrorText.enhance) {
22
+ return getErrorText.enhance(error) ?? getErrorText.unknownErrorText;
23
+ }
24
+ else {
25
+ return getErrorText.unknownErrorText;
26
+ }
27
+ };
28
+ getErrorText.unknownErrorText = '';
29
+ getErrorText.formatError = null;
30
+ getErrorText.enhance = null;
package/file.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare const getBase64FromFile: (file: File) => Promise<string>;
2
+ export declare const getTextFromFile: (file: File, encoding?: string) => Promise<string>;
3
+ //# sourceMappingURL=file.d.ts.map
package/file.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,GAAI,MAAM,IAAI,oBAW3C,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,MAAM,IAAI,EAAE,WAAW,MAAM,oBAW5D,CAAC"}
package/file.js ADDED
@@ -0,0 +1,24 @@
1
+ export const getBase64FromFile = (file) => {
2
+ return new Promise((resolve, reject) => {
3
+ const reader = new FileReader();
4
+ reader.readAsDataURL(file);
5
+ reader.onload = () => {
6
+ resolve(reader.result.toString());
7
+ };
8
+ reader.onerror = (error) => {
9
+ reject(error);
10
+ };
11
+ });
12
+ };
13
+ export const getTextFromFile = (file, encoding) => {
14
+ return new Promise((resolve, reject) => {
15
+ const reader = new FileReader();
16
+ reader.readAsText(file, encoding);
17
+ reader.onload = () => {
18
+ resolve(reader.result.toString());
19
+ };
20
+ reader.onerror = (error) => {
21
+ reject(error);
22
+ };
23
+ });
24
+ };
@@ -0,0 +1,5 @@
1
+ export * from './constants.js';
2
+ export * from './number.js';
3
+ export * from './percent.js';
4
+ export * from './skip-spaces.js';
5
+ //# sourceMappingURL=_exports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_exports.d.ts","sourceRoot":"","sources":["../../src/format/_exports.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const NO_VALUE = "\u2013";
2
+ export declare const HYPHEN = "-";
3
+ export declare const INFINITY = "\u221E";
4
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/format/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,WAAM,CAAC;AAE5B,eAAO,MAAM,MAAM,MAAM,CAAC;AAE1B,eAAO,MAAM,QAAQ,WAAM,CAAC"}
@@ -1,5 +1,3 @@
1
1
  export const NO_VALUE = '–'; // en-dash
2
-
3
2
  export const HYPHEN = '-';
4
-
5
3
  export const INFINITY = '∞';
@@ -0,0 +1,3 @@
1
+ import * as format from './_exports.js';
2
+ export { format };
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/format/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -1,5 +1,4 @@
1
1
  // This way is more treeshakable than collecting
2
2
  // it into one exportable object export const format
3
3
  import * as format from './_exports.js';
4
-
5
4
  export { format };
@@ -0,0 +1,36 @@
1
+ import type { Maybe } from '../utils/types.js';
2
+ export interface NumberFormatSettings {
3
+ delimiter?: string;
4
+ /**
5
+ * digitsOnlyForFloat - Show digits after decimal point only if they are not zeros after converting to number.
6
+ * Example: "0.00" -> "0", "0.10" -> "0.1", but "0.003" -> "0.003"
7
+ *
8
+ * @default true
9
+ */
10
+ digitsOnlyForFloat?: boolean;
11
+ /**
12
+ * Text which will be returned if the value is undefined, null, NaN, Infinity or empty string.
13
+ * Example: "–" will be returned if the value is undefined and emptyText is "–".
14
+ */
15
+ emptyText?: string;
16
+ /**
17
+ * Text to append to the end of the formatted number.
18
+ * Example: if value is 1000 and postfix is "₽", result will be "1 000₽".
19
+ */
20
+ postfix?: string;
21
+ /**
22
+ * Fixed number of digits after the decimal point (number.toFixed() method)
23
+ * If set to false, the truncation is ignored!
24
+ */
25
+ digits?: number | false;
26
+ /**
27
+ * Remove trailing zeros from the end of the number
28
+ * Example: 0.010000000000000000000000000000000000000000000 -> 0.01
29
+ */
30
+ cutZeros?: boolean;
31
+ }
32
+ export declare const number: {
33
+ (rawValue: Maybe<string | number>, userSettings?: Maybe<NumberFormatSettings>): string;
34
+ defaultSettings: NumberFormatSettings;
35
+ };
36
+ //# sourceMappingURL=number.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src/format/number.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAI/C,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,eAAO,MAAM,MAAM;eACP,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,iBACjB,KAAK,CAAC,oBAAoB,CAAC,GACzC,MAAM;;CAqDR,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { number as toNumber } from '../parser/number.js';
2
+ import { typeGuard } from '../type-guard/index.js';
3
+ import { NO_VALUE } from './constants.js';
4
+ export const number = (rawValue, userSettings) => {
5
+ const settings = {
6
+ ...number.defaultSettings,
7
+ ...userSettings,
8
+ };
9
+ const digits = settings.digits ?? 0;
10
+ const cutZeros = settings?.cutZeros ?? false;
11
+ const delimiter = settings.delimiter ?? ' ';
12
+ const postfix = settings.postfix ?? '';
13
+ const emptyText = settings.emptyText ?? NO_VALUE;
14
+ const digitsOnlyForFloat = settings.digitsOnlyForFloat ?? true;
15
+ let value;
16
+ if (typeGuard.isString(rawValue)) {
17
+ value = toNumber(value, { fallback: undefined });
18
+ }
19
+ else {
20
+ value = rawValue;
21
+ }
22
+ if (typeGuard.isNumber(value)) {
23
+ let raw = `${value}`;
24
+ if (digits !== false) {
25
+ raw = value.toFixed(digits);
26
+ }
27
+ if (cutZeros) {
28
+ raw = `${+raw}`;
29
+ }
30
+ const [integerPart, decimalPart] = raw.split('.', 2);
31
+ let formattedIntegerPart = integerPart;
32
+ let formattedDecimalPart = '';
33
+ if (decimalPart && (!digitsOnlyForFloat || !/^0+$/.test(decimalPart))) {
34
+ formattedDecimalPart = `.${decimalPart}`;
35
+ }
36
+ const rgx = /(\d+)(\d{3})/;
37
+ while (rgx.test(formattedIntegerPart) && delimiter) {
38
+ formattedIntegerPart = formattedIntegerPart.replace(rgx, `$1${delimiter}$2`);
39
+ }
40
+ return formattedIntegerPart + formattedDecimalPart + postfix;
41
+ }
42
+ return emptyText;
43
+ };
44
+ number.defaultSettings = {};