all-you-need 0.1.0
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.
- package/LICENSE +21 -0
- package/dist/chunk-BJCELHLJ.cjs +224 -0
- package/dist/chunk-BJCELHLJ.cjs.map +1 -0
- package/dist/chunk-KA5JX4LA.js +841 -0
- package/dist/chunk-KA5JX4LA.js.map +1 -0
- package/dist/chunk-RNO7ZT65.cjs +4 -0
- package/dist/chunk-RNO7ZT65.cjs.map +1 -0
- package/dist/chunk-RV5MKKBP.js +3 -0
- package/dist/chunk-RV5MKKBP.js.map +1 -0
- package/dist/chunk-SEJ5J4LY.cjs +924 -0
- package/dist/chunk-SEJ5J4LY.cjs.map +1 -0
- package/dist/chunk-YHQI346M.js +218 -0
- package/dist/chunk-YHQI346M.js.map +1 -0
- package/dist/entities/index.cjs +28 -0
- package/dist/entities/index.cjs.map +1 -0
- package/dist/entities/index.d.cts +73 -0
- package/dist/entities/index.d.ts +73 -0
- package/dist/entities/index.js +3 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/index.cjs +358 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.cjs +6 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +114 -0
- package/dist/types/index.d.ts +114 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.cjs +336 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +185 -0
- package/dist/utils/index.d.ts +185 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +141 -0
|
@@ -0,0 +1,924 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils/string/capitalize.ts
|
|
4
|
+
function capitalize(str) {
|
|
5
|
+
if (str.length === 0) {
|
|
6
|
+
return str;
|
|
7
|
+
}
|
|
8
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/utils/string/escapeHtml.ts
|
|
12
|
+
function escapeHtml(str) {
|
|
13
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/utils/string/escapeRegExp.ts
|
|
17
|
+
function escapeRegExp(str) {
|
|
18
|
+
return str.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/utils/string/maskString.ts
|
|
22
|
+
function maskString(str, visibleStart = 0, visibleEnd = 0, maskChar = "*") {
|
|
23
|
+
if (str.length <= visibleStart + visibleEnd) {
|
|
24
|
+
return str;
|
|
25
|
+
}
|
|
26
|
+
const start = str.slice(0, visibleStart);
|
|
27
|
+
const end = visibleEnd > 0 ? str.slice(-visibleEnd) : "";
|
|
28
|
+
const masked = maskChar.repeat(str.length - visibleStart - visibleEnd);
|
|
29
|
+
return start + masked + end;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/utils/string/pluralize.ts
|
|
33
|
+
function pluralize(count, one, few, many) {
|
|
34
|
+
const abs = Math.abs(count);
|
|
35
|
+
const mod10 = abs % 10;
|
|
36
|
+
const mod100 = abs % 100;
|
|
37
|
+
if (mod10 === 1 && mod100 !== 11) {
|
|
38
|
+
return `${count} ${one}`;
|
|
39
|
+
}
|
|
40
|
+
if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) {
|
|
41
|
+
return `${count} ${few}`;
|
|
42
|
+
}
|
|
43
|
+
return `${count} ${many}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/utils/string/slugify.ts
|
|
47
|
+
function slugify(str) {
|
|
48
|
+
return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/[^a-z0-9\s-]/g, "").replace(/[\s_]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/utils/string/template.ts
|
|
52
|
+
function template(str, data) {
|
|
53
|
+
return str.replace(/\{(\w+)\}/g, (match, key) => {
|
|
54
|
+
if (key in data) {
|
|
55
|
+
return String(data[key]);
|
|
56
|
+
}
|
|
57
|
+
return match;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/utils/string/toCamelCase.ts
|
|
62
|
+
function toCamelCase(str) {
|
|
63
|
+
return str.replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase()).replace(/^[A-Z]/, (char) => char.toLowerCase());
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/utils/string/toKebabCase.ts
|
|
67
|
+
function toKebabCase(str) {
|
|
68
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").replace(/[^a-zA-Z0-9-]/g, "").toLowerCase();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/utils/string/toPascalCase.ts
|
|
72
|
+
function toPascalCase(str) {
|
|
73
|
+
return str.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/utils/string/toSnakeCase.ts
|
|
77
|
+
function toSnakeCase(str) {
|
|
78
|
+
return str.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/[\s-]+/g, "_").replace(/[^a-zA-Z0-9_]/g, "").toLowerCase();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/utils/string/truncate.ts
|
|
82
|
+
function truncate(str, maxLength, suffix = "...") {
|
|
83
|
+
if (str.length <= maxLength) {
|
|
84
|
+
return str;
|
|
85
|
+
}
|
|
86
|
+
return str.slice(0, maxLength - suffix.length) + suffix;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/utils/string/unescapeHtml.ts
|
|
90
|
+
function unescapeHtml(str) {
|
|
91
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/utils/array/chunk.ts
|
|
95
|
+
function chunk(arr, size) {
|
|
96
|
+
if (size <= 0) {
|
|
97
|
+
throw new RangeError("chunk size must be greater than 0");
|
|
98
|
+
}
|
|
99
|
+
const result = [];
|
|
100
|
+
for (let i = 0; i < arr.length; i += size) {
|
|
101
|
+
result.push(arr.slice(i, i + size));
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/utils/array/compact.ts
|
|
107
|
+
function compact(arr) {
|
|
108
|
+
return arr.filter(Boolean);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/utils/array/difference.ts
|
|
112
|
+
function difference(a, b) {
|
|
113
|
+
const set = new Set(b);
|
|
114
|
+
return a.filter((item) => !set.has(item));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/utils/array/first.ts
|
|
118
|
+
function first(arr) {
|
|
119
|
+
return arr[0];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/utils/array/flatten.ts
|
|
123
|
+
function flatten(arr) {
|
|
124
|
+
return arr.flat(Infinity);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/utils/array/groupBy.ts
|
|
128
|
+
function groupBy(arr, keyFn) {
|
|
129
|
+
return arr.reduce(
|
|
130
|
+
(acc, item) => {
|
|
131
|
+
const key = keyFn(item);
|
|
132
|
+
if (!acc[key]) {
|
|
133
|
+
acc[key] = [];
|
|
134
|
+
}
|
|
135
|
+
acc[key].push(item);
|
|
136
|
+
return acc;
|
|
137
|
+
},
|
|
138
|
+
{}
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/utils/array/intersection.ts
|
|
143
|
+
function intersection(a, b) {
|
|
144
|
+
const set = new Set(b);
|
|
145
|
+
return a.filter((item) => set.has(item));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/utils/array/last.ts
|
|
149
|
+
function last(arr) {
|
|
150
|
+
return arr[arr.length - 1];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/utils/array/range.ts
|
|
154
|
+
function range(start, end, step = 1) {
|
|
155
|
+
if (step === 0) {
|
|
156
|
+
throw new RangeError("step must not be 0");
|
|
157
|
+
}
|
|
158
|
+
const result = [];
|
|
159
|
+
if (step > 0) {
|
|
160
|
+
for (let i = start; i < end; i += step) {
|
|
161
|
+
result.push(i);
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
for (let i = start; i > end; i += step) {
|
|
165
|
+
result.push(i);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/utils/array/shuffle.ts
|
|
172
|
+
function shuffle(arr) {
|
|
173
|
+
const result = [...arr];
|
|
174
|
+
for (let i = result.length - 1; i > 0; i--) {
|
|
175
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
176
|
+
[result[i], result[j]] = [result[j], result[i]];
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/utils/array/sortBy.ts
|
|
182
|
+
function sortBy(arr, keyFn) {
|
|
183
|
+
return [...arr].sort((a, b) => {
|
|
184
|
+
const ka = keyFn(a);
|
|
185
|
+
const kb = keyFn(b);
|
|
186
|
+
if (ka < kb) {
|
|
187
|
+
return -1;
|
|
188
|
+
}
|
|
189
|
+
if (ka > kb) {
|
|
190
|
+
return 1;
|
|
191
|
+
}
|
|
192
|
+
return 0;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// src/utils/array/unique.ts
|
|
197
|
+
function unique(arr) {
|
|
198
|
+
return [...new Set(arr)];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// src/utils/array/uniqueBy.ts
|
|
202
|
+
function uniqueBy(arr, keyFn) {
|
|
203
|
+
const seen = /* @__PURE__ */ new Set();
|
|
204
|
+
return arr.filter((item) => {
|
|
205
|
+
const key = keyFn(item);
|
|
206
|
+
if (seen.has(key)) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
seen.add(key);
|
|
210
|
+
return true;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/utils/array/zip.ts
|
|
215
|
+
function zip(a, b) {
|
|
216
|
+
const length = Math.min(a.length, b.length);
|
|
217
|
+
const result = [];
|
|
218
|
+
for (let i = 0; i < length; i++) {
|
|
219
|
+
result.push([a[i], b[i]]);
|
|
220
|
+
}
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// src/utils/object/deepClone.ts
|
|
225
|
+
function deepClone(value) {
|
|
226
|
+
return structuredClone(value);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// src/utils/object/deepEqual.ts
|
|
230
|
+
function deepEqual(a, b) {
|
|
231
|
+
if (a === b) {
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
if (a instanceof Date && b instanceof Date) {
|
|
235
|
+
return a.getTime() === b.getTime();
|
|
236
|
+
}
|
|
237
|
+
if (a instanceof RegExp && b instanceof RegExp) {
|
|
238
|
+
return a.source === b.source && a.flags === b.flags;
|
|
239
|
+
}
|
|
240
|
+
if (a === null || b === null || typeof a !== "object" || typeof b !== "object") {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
if (Array.isArray(a) !== Array.isArray(b)) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
247
|
+
if (a.length !== b.length) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
return a.every((item, index) => deepEqual(item, b[index]));
|
|
251
|
+
}
|
|
252
|
+
const keysA = Object.keys(a);
|
|
253
|
+
const keysB = Object.keys(b);
|
|
254
|
+
if (keysA.length !== keysB.length) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
return keysA.every(
|
|
258
|
+
(key) => Object.prototype.hasOwnProperty.call(b, key) && deepEqual(
|
|
259
|
+
a[key],
|
|
260
|
+
b[key]
|
|
261
|
+
)
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// src/utils/object/deepMerge.ts
|
|
266
|
+
function isPlainObject(value) {
|
|
267
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
268
|
+
}
|
|
269
|
+
function deepMerge(target, source) {
|
|
270
|
+
const result = { ...target };
|
|
271
|
+
for (const key of Object.keys(source)) {
|
|
272
|
+
const targetVal = result[key];
|
|
273
|
+
const sourceVal = source[key];
|
|
274
|
+
if (isPlainObject(targetVal) && isPlainObject(sourceVal)) {
|
|
275
|
+
result[key] = deepMerge(targetVal, sourceVal);
|
|
276
|
+
} else {
|
|
277
|
+
result[key] = sourceVal;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return result;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// src/utils/object/diff.ts
|
|
284
|
+
function diff(original, changed) {
|
|
285
|
+
const result = {};
|
|
286
|
+
for (const key of Object.keys(changed)) {
|
|
287
|
+
if (changed[key] !== original[key]) {
|
|
288
|
+
result[key] = changed[key];
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return result;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// src/utils/object/flattenObject.ts
|
|
295
|
+
function flattenObject(obj, prefix = "", separator = ".") {
|
|
296
|
+
const result = {};
|
|
297
|
+
for (const key of Object.keys(obj)) {
|
|
298
|
+
const fullKey = prefix ? `${prefix}${separator}${key}` : key;
|
|
299
|
+
const value = obj[key];
|
|
300
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !(value instanceof RegExp)) {
|
|
301
|
+
Object.assign(
|
|
302
|
+
result,
|
|
303
|
+
flattenObject(value, fullKey, separator)
|
|
304
|
+
);
|
|
305
|
+
} else {
|
|
306
|
+
result[fullKey] = value;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return result;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// src/utils/object/isEmpty.ts
|
|
313
|
+
function isEmpty(value) {
|
|
314
|
+
if (value === null || value === void 0) {
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
if (typeof value === "string") {
|
|
318
|
+
return value.trim().length === 0;
|
|
319
|
+
}
|
|
320
|
+
if (Array.isArray(value)) {
|
|
321
|
+
return value.length === 0;
|
|
322
|
+
}
|
|
323
|
+
if (typeof value === "object") {
|
|
324
|
+
return Object.keys(value).length === 0;
|
|
325
|
+
}
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// src/utils/object/mapKeys.ts
|
|
330
|
+
function mapKeys(obj, fn) {
|
|
331
|
+
const result = {};
|
|
332
|
+
for (const key of Object.keys(obj)) {
|
|
333
|
+
result[fn(key)] = obj[key];
|
|
334
|
+
}
|
|
335
|
+
return result;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// src/utils/object/mapValues.ts
|
|
339
|
+
function mapValues(obj, fn) {
|
|
340
|
+
const result = {};
|
|
341
|
+
for (const key of Object.keys(obj)) {
|
|
342
|
+
result[key] = fn(obj[key], key);
|
|
343
|
+
}
|
|
344
|
+
return result;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// src/utils/object/omit.ts
|
|
348
|
+
function omit(obj, keys) {
|
|
349
|
+
const result = { ...obj };
|
|
350
|
+
for (const key of keys) {
|
|
351
|
+
delete result[key];
|
|
352
|
+
}
|
|
353
|
+
return result;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// src/utils/object/pick.ts
|
|
357
|
+
function pick(obj, keys) {
|
|
358
|
+
const result = {};
|
|
359
|
+
for (const key of keys) {
|
|
360
|
+
if (key in obj) {
|
|
361
|
+
result[key] = obj[key];
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return result;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/utils/number/average.ts
|
|
368
|
+
function average(arr) {
|
|
369
|
+
if (arr.length === 0) {
|
|
370
|
+
return 0;
|
|
371
|
+
}
|
|
372
|
+
return arr.reduce((acc, val) => acc + val, 0) / arr.length;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/utils/number/clamp.ts
|
|
376
|
+
function clamp(value, min, max) {
|
|
377
|
+
return Math.min(Math.max(value, min), max);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// src/utils/number/formatBytes.ts
|
|
381
|
+
function formatBytes(bytes, decimals = 2) {
|
|
382
|
+
if (bytes === 0) {
|
|
383
|
+
return "0 B";
|
|
384
|
+
}
|
|
385
|
+
const k = 1024;
|
|
386
|
+
const units = ["B", "KB", "MB", "GB", "TB", "PB"];
|
|
387
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
388
|
+
const value = bytes / Math.pow(k, i);
|
|
389
|
+
return `${parseFloat(value.toFixed(decimals))} ${units[i]}`;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// src/utils/number/formatCurrency.ts
|
|
393
|
+
function formatCurrency(value, currency = "RUB", locale = "ru-RU") {
|
|
394
|
+
return new Intl.NumberFormat(locale, {
|
|
395
|
+
style: "currency",
|
|
396
|
+
currency
|
|
397
|
+
}).format(value);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// src/utils/number/formatNumber.ts
|
|
401
|
+
function formatNumber(value, locale = "ru-RU") {
|
|
402
|
+
return new Intl.NumberFormat(locale).format(value);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// src/utils/number/median.ts
|
|
406
|
+
function median(arr) {
|
|
407
|
+
if (arr.length === 0) {
|
|
408
|
+
return 0;
|
|
409
|
+
}
|
|
410
|
+
const sorted = [...arr].sort((a, b) => a - b);
|
|
411
|
+
const mid = Math.floor(sorted.length / 2);
|
|
412
|
+
if (sorted.length % 2 === 0) {
|
|
413
|
+
return (sorted[mid - 1] + sorted[mid]) / 2;
|
|
414
|
+
}
|
|
415
|
+
return sorted[mid];
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// src/utils/number/percentage.ts
|
|
419
|
+
function percentage(value, total) {
|
|
420
|
+
if (total === 0) {
|
|
421
|
+
return 0;
|
|
422
|
+
}
|
|
423
|
+
return value / total * 100;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// src/utils/number/randomInt.ts
|
|
427
|
+
function randomInt(min, max) {
|
|
428
|
+
min = Math.ceil(min);
|
|
429
|
+
max = Math.floor(max);
|
|
430
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// src/utils/number/round.ts
|
|
434
|
+
function round(value, decimals = 0) {
|
|
435
|
+
const factor = 10 ** decimals;
|
|
436
|
+
return Math.round(value * factor) / factor;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// src/utils/number/sum.ts
|
|
440
|
+
function sum(arr) {
|
|
441
|
+
return arr.reduce((acc, val) => acc + val, 0);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// src/utils/date/formatDate.ts
|
|
445
|
+
function formatDate(date, options = {
|
|
446
|
+
day: "2-digit",
|
|
447
|
+
month: "2-digit",
|
|
448
|
+
year: "numeric"
|
|
449
|
+
}, locale = "ru-RU") {
|
|
450
|
+
return new Intl.DateTimeFormat(locale, options).format(date);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// src/utils/date/daysBetween.ts
|
|
454
|
+
function daysBetween(a, b) {
|
|
455
|
+
const MS_PER_DAY = 864e5;
|
|
456
|
+
const utcA = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
|
|
457
|
+
const utcB = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());
|
|
458
|
+
return Math.abs(Math.floor((utcB - utcA) / MS_PER_DAY));
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// src/utils/date/isToday.ts
|
|
462
|
+
function isToday(date) {
|
|
463
|
+
const now = /* @__PURE__ */ new Date();
|
|
464
|
+
return date.getFullYear() === now.getFullYear() && date.getMonth() === now.getMonth() && date.getDate() === now.getDate();
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// src/utils/date/isYesterday.ts
|
|
468
|
+
function isYesterday(date) {
|
|
469
|
+
const yesterday = /* @__PURE__ */ new Date();
|
|
470
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
471
|
+
return date.getFullYear() === yesterday.getFullYear() && date.getMonth() === yesterday.getMonth() && date.getDate() === yesterday.getDate();
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// src/utils/date/addDays.ts
|
|
475
|
+
function addDays(date, days) {
|
|
476
|
+
const result = new Date(date);
|
|
477
|
+
result.setDate(result.getDate() + days);
|
|
478
|
+
return result;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// src/utils/date/addMonths.ts
|
|
482
|
+
function addMonths(date, months) {
|
|
483
|
+
const result = new Date(date);
|
|
484
|
+
result.setMonth(result.getMonth() + months);
|
|
485
|
+
return result;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// src/utils/date/relativeTime.ts
|
|
489
|
+
function relativeTime(date, locale = "ru-RU") {
|
|
490
|
+
const now = Date.now();
|
|
491
|
+
const diffMs = date.getTime() - now;
|
|
492
|
+
const absDiffMs = Math.abs(diffMs);
|
|
493
|
+
const rtf = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
|
|
494
|
+
const SECOND = 1e3;
|
|
495
|
+
const MINUTE = 60 * SECOND;
|
|
496
|
+
const HOUR = 60 * MINUTE;
|
|
497
|
+
const DAY = 24 * HOUR;
|
|
498
|
+
const MONTH = 30 * DAY;
|
|
499
|
+
const YEAR = 365 * DAY;
|
|
500
|
+
if (absDiffMs < MINUTE) {
|
|
501
|
+
return rtf.format(Math.round(diffMs / SECOND), "second");
|
|
502
|
+
}
|
|
503
|
+
if (absDiffMs < HOUR) {
|
|
504
|
+
return rtf.format(Math.round(diffMs / MINUTE), "minute");
|
|
505
|
+
}
|
|
506
|
+
if (absDiffMs < DAY) {
|
|
507
|
+
return rtf.format(Math.round(diffMs / HOUR), "hour");
|
|
508
|
+
}
|
|
509
|
+
if (absDiffMs < MONTH) {
|
|
510
|
+
return rtf.format(Math.round(diffMs / DAY), "day");
|
|
511
|
+
}
|
|
512
|
+
if (absDiffMs < YEAR) {
|
|
513
|
+
return rtf.format(Math.round(diffMs / MONTH), "month");
|
|
514
|
+
}
|
|
515
|
+
return rtf.format(Math.round(diffMs / YEAR), "year");
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// src/utils/async/sleep.ts
|
|
519
|
+
function sleep(ms) {
|
|
520
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// src/utils/async/retry.ts
|
|
524
|
+
async function retry(fn, options = {}) {
|
|
525
|
+
const { attempts = 3, delay = 1e3, factor = 2 } = options;
|
|
526
|
+
let lastError;
|
|
527
|
+
let currentDelay = delay;
|
|
528
|
+
for (let i = 0; i < attempts; i++) {
|
|
529
|
+
try {
|
|
530
|
+
return await fn();
|
|
531
|
+
} catch (error) {
|
|
532
|
+
lastError = error;
|
|
533
|
+
if (i < attempts - 1) {
|
|
534
|
+
await new Promise((resolve) => setTimeout(resolve, currentDelay));
|
|
535
|
+
currentDelay *= factor;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
throw lastError;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// src/utils/async/debounce.ts
|
|
543
|
+
function debounce(fn, ms) {
|
|
544
|
+
let timeoutId;
|
|
545
|
+
return (...args) => {
|
|
546
|
+
if (timeoutId !== void 0) {
|
|
547
|
+
clearTimeout(timeoutId);
|
|
548
|
+
}
|
|
549
|
+
timeoutId = setTimeout(() => fn(...args), ms);
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// src/utils/async/throttle.ts
|
|
554
|
+
function throttle(fn, ms) {
|
|
555
|
+
let lastCall = 0;
|
|
556
|
+
let timeoutId;
|
|
557
|
+
return (...args) => {
|
|
558
|
+
const now = Date.now();
|
|
559
|
+
const remaining = ms - (now - lastCall);
|
|
560
|
+
if (remaining <= 0) {
|
|
561
|
+
if (timeoutId !== void 0) {
|
|
562
|
+
clearTimeout(timeoutId);
|
|
563
|
+
timeoutId = void 0;
|
|
564
|
+
}
|
|
565
|
+
lastCall = now;
|
|
566
|
+
fn(...args);
|
|
567
|
+
} else if (timeoutId === void 0) {
|
|
568
|
+
timeoutId = setTimeout(() => {
|
|
569
|
+
lastCall = Date.now();
|
|
570
|
+
timeoutId = void 0;
|
|
571
|
+
fn(...args);
|
|
572
|
+
}, remaining);
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// src/utils/async/timeout.ts
|
|
578
|
+
function timeout(promise, ms) {
|
|
579
|
+
return new Promise((resolve, reject) => {
|
|
580
|
+
const timer = setTimeout(
|
|
581
|
+
() => reject(new Error(`Timed out after ${ms}ms`)),
|
|
582
|
+
ms
|
|
583
|
+
);
|
|
584
|
+
promise.then(
|
|
585
|
+
(value) => {
|
|
586
|
+
clearTimeout(timer);
|
|
587
|
+
resolve(value);
|
|
588
|
+
},
|
|
589
|
+
(error) => {
|
|
590
|
+
clearTimeout(timer);
|
|
591
|
+
reject(error);
|
|
592
|
+
}
|
|
593
|
+
);
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// src/utils/async/tryCatch.ts
|
|
598
|
+
async function tryCatch(fn) {
|
|
599
|
+
try {
|
|
600
|
+
const value = await fn();
|
|
601
|
+
return [null, value];
|
|
602
|
+
} catch (error) {
|
|
603
|
+
if (error instanceof Error) {
|
|
604
|
+
return [error, null];
|
|
605
|
+
}
|
|
606
|
+
return [new Error(String(error)), null];
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
function tryCatchSync(fn) {
|
|
610
|
+
try {
|
|
611
|
+
const value = fn();
|
|
612
|
+
return [null, value];
|
|
613
|
+
} catch (error) {
|
|
614
|
+
if (error instanceof Error) {
|
|
615
|
+
return [error, null];
|
|
616
|
+
}
|
|
617
|
+
return [new Error(String(error)), null];
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// src/utils/async/pLimit.ts
|
|
622
|
+
function pLimit(concurrency) {
|
|
623
|
+
let activeCount = 0;
|
|
624
|
+
const queue = [];
|
|
625
|
+
function next() {
|
|
626
|
+
if (queue.length > 0 && activeCount < concurrency) {
|
|
627
|
+
activeCount++;
|
|
628
|
+
const run = queue.shift();
|
|
629
|
+
run();
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
return (fn) => {
|
|
633
|
+
return new Promise((resolve, reject) => {
|
|
634
|
+
const run = () => {
|
|
635
|
+
fn().then(
|
|
636
|
+
(value) => {
|
|
637
|
+
resolve(value);
|
|
638
|
+
activeCount--;
|
|
639
|
+
next();
|
|
640
|
+
},
|
|
641
|
+
(error) => {
|
|
642
|
+
reject(error);
|
|
643
|
+
activeCount--;
|
|
644
|
+
next();
|
|
645
|
+
}
|
|
646
|
+
);
|
|
647
|
+
};
|
|
648
|
+
if (activeCount < concurrency) {
|
|
649
|
+
activeCount++;
|
|
650
|
+
run();
|
|
651
|
+
} else {
|
|
652
|
+
queue.push(run);
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// src/utils/async/pSettle.ts
|
|
659
|
+
function pSettle(promises) {
|
|
660
|
+
return Promise.all(
|
|
661
|
+
promises.map(
|
|
662
|
+
(promise) => promise.then(
|
|
663
|
+
(value) => ({ status: "fulfilled", value }),
|
|
664
|
+
(reason) => ({ status: "rejected", reason })
|
|
665
|
+
)
|
|
666
|
+
)
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// src/utils/validation/isEmail.ts
|
|
671
|
+
var EMAIL_RE = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
672
|
+
function isEmail(str) {
|
|
673
|
+
return EMAIL_RE.test(str);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
// src/utils/validation/isURL.ts
|
|
677
|
+
function isURL(str) {
|
|
678
|
+
try {
|
|
679
|
+
new URL(str);
|
|
680
|
+
return true;
|
|
681
|
+
} catch {
|
|
682
|
+
return false;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// src/utils/validation/isPhone.ts
|
|
687
|
+
var PHONE_RE = /^\+?[0-9\s\-().]{7,20}$/;
|
|
688
|
+
function isPhone(str) {
|
|
689
|
+
const digits = str.replace(/\D/g, "");
|
|
690
|
+
return PHONE_RE.test(str) && digits.length >= 7 && digits.length <= 15;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
// src/utils/validation/isINN.ts
|
|
694
|
+
function isINN(str) {
|
|
695
|
+
if (!/^\d{10}$|^\d{12}$/.test(str)) {
|
|
696
|
+
return false;
|
|
697
|
+
}
|
|
698
|
+
const digits = str.split("").map(Number);
|
|
699
|
+
if (digits.length === 10) {
|
|
700
|
+
const weights = [2, 4, 10, 3, 5, 9, 4, 6, 8];
|
|
701
|
+
const sum2 = weights.reduce((acc, w, i) => acc + w * digits[i], 0);
|
|
702
|
+
return sum2 % 11 % 10 === digits[9];
|
|
703
|
+
}
|
|
704
|
+
const weights11 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8];
|
|
705
|
+
const weights12 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8];
|
|
706
|
+
const sum11 = weights11.reduce((acc, w, i) => acc + w * digits[i], 0);
|
|
707
|
+
const sum12 = weights12.reduce((acc, w, i) => acc + w * digits[i], 0);
|
|
708
|
+
return sum11 % 11 % 10 === digits[10] && sum12 % 11 % 10 === digits[11];
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// src/utils/validation/isStrongPassword.ts
|
|
712
|
+
function isStrongPassword(str, options = {}) {
|
|
713
|
+
const {
|
|
714
|
+
minLength = 8,
|
|
715
|
+
lowercase = true,
|
|
716
|
+
uppercase = true,
|
|
717
|
+
digits = true,
|
|
718
|
+
special = true
|
|
719
|
+
} = options;
|
|
720
|
+
if (str.length < minLength) {
|
|
721
|
+
return false;
|
|
722
|
+
}
|
|
723
|
+
if (lowercase && !/[a-z]/.test(str)) {
|
|
724
|
+
return false;
|
|
725
|
+
}
|
|
726
|
+
if (uppercase && !/[A-Z]/.test(str)) {
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
729
|
+
if (digits && !/\d/.test(str)) {
|
|
730
|
+
return false;
|
|
731
|
+
}
|
|
732
|
+
if (special && !/[^a-zA-Z0-9]/.test(str)) {
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
735
|
+
return true;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// src/utils/guards/isString.ts
|
|
739
|
+
function isString(value) {
|
|
740
|
+
return typeof value === "string";
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// src/utils/guards/isNumber.ts
|
|
744
|
+
function isNumber(value) {
|
|
745
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// src/utils/guards/isBoolean.ts
|
|
749
|
+
function isBoolean(value) {
|
|
750
|
+
return typeof value === "boolean";
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// src/utils/guards/isNonNullable.ts
|
|
754
|
+
function isNonNullable(value) {
|
|
755
|
+
return value !== null && value !== void 0;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// src/utils/guards/isArray.ts
|
|
759
|
+
function isArray(value) {
|
|
760
|
+
return Array.isArray(value);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// src/utils/guards/isObject.ts
|
|
764
|
+
function isObject(value) {
|
|
765
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// src/utils/guards/isFunction.ts
|
|
769
|
+
function isFunction(value) {
|
|
770
|
+
return typeof value === "function";
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
// src/utils/guards/isDefined.ts
|
|
774
|
+
function isDefined(value) {
|
|
775
|
+
return value !== void 0;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// src/utils/guards/hasProperty.ts
|
|
779
|
+
function hasProperty(obj, key) {
|
|
780
|
+
return typeof obj === "object" && obj !== null && key in obj;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
// src/utils/env/isBrowser.ts
|
|
784
|
+
function isBrowser() {
|
|
785
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// src/utils/env/isNode.ts
|
|
789
|
+
function isNode() {
|
|
790
|
+
return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
// src/utils/env/isSSR.ts
|
|
794
|
+
function isSSR() {
|
|
795
|
+
return isNode() && !isBrowser();
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// src/utils/id/nanoid.ts
|
|
799
|
+
var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
|
|
800
|
+
function nanoid(size = 21) {
|
|
801
|
+
let id = "";
|
|
802
|
+
const bytes = new Uint8Array(size);
|
|
803
|
+
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
804
|
+
crypto.getRandomValues(bytes);
|
|
805
|
+
} else {
|
|
806
|
+
for (let i = 0; i < size; i++) {
|
|
807
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
for (let i = 0; i < size; i++) {
|
|
811
|
+
id += ALPHABET[bytes[i] & 63];
|
|
812
|
+
}
|
|
813
|
+
return id;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
// src/utils/id/uuid.ts
|
|
817
|
+
function uuid() {
|
|
818
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
819
|
+
return crypto.randomUUID();
|
|
820
|
+
}
|
|
821
|
+
const bytes = new Uint8Array(16);
|
|
822
|
+
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
823
|
+
crypto.getRandomValues(bytes);
|
|
824
|
+
} else {
|
|
825
|
+
for (let i = 0; i < 16; i++) {
|
|
826
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
830
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
831
|
+
const hex = Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
832
|
+
return [
|
|
833
|
+
hex.slice(0, 8),
|
|
834
|
+
hex.slice(8, 12),
|
|
835
|
+
hex.slice(12, 16),
|
|
836
|
+
hex.slice(16, 20),
|
|
837
|
+
hex.slice(20, 32)
|
|
838
|
+
].join("-");
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
exports.addDays = addDays;
|
|
842
|
+
exports.addMonths = addMonths;
|
|
843
|
+
exports.average = average;
|
|
844
|
+
exports.capitalize = capitalize;
|
|
845
|
+
exports.chunk = chunk;
|
|
846
|
+
exports.clamp = clamp;
|
|
847
|
+
exports.compact = compact;
|
|
848
|
+
exports.daysBetween = daysBetween;
|
|
849
|
+
exports.debounce = debounce;
|
|
850
|
+
exports.deepClone = deepClone;
|
|
851
|
+
exports.deepEqual = deepEqual;
|
|
852
|
+
exports.deepMerge = deepMerge;
|
|
853
|
+
exports.diff = diff;
|
|
854
|
+
exports.difference = difference;
|
|
855
|
+
exports.escapeHtml = escapeHtml;
|
|
856
|
+
exports.escapeRegExp = escapeRegExp;
|
|
857
|
+
exports.first = first;
|
|
858
|
+
exports.flatten = flatten;
|
|
859
|
+
exports.flattenObject = flattenObject;
|
|
860
|
+
exports.formatBytes = formatBytes;
|
|
861
|
+
exports.formatCurrency = formatCurrency;
|
|
862
|
+
exports.formatDate = formatDate;
|
|
863
|
+
exports.formatNumber = formatNumber;
|
|
864
|
+
exports.groupBy = groupBy;
|
|
865
|
+
exports.hasProperty = hasProperty;
|
|
866
|
+
exports.intersection = intersection;
|
|
867
|
+
exports.isArray = isArray;
|
|
868
|
+
exports.isBoolean = isBoolean;
|
|
869
|
+
exports.isBrowser = isBrowser;
|
|
870
|
+
exports.isDefined = isDefined;
|
|
871
|
+
exports.isEmail = isEmail;
|
|
872
|
+
exports.isEmpty = isEmpty;
|
|
873
|
+
exports.isFunction = isFunction;
|
|
874
|
+
exports.isINN = isINN;
|
|
875
|
+
exports.isNode = isNode;
|
|
876
|
+
exports.isNonNullable = isNonNullable;
|
|
877
|
+
exports.isNumber = isNumber;
|
|
878
|
+
exports.isObject = isObject;
|
|
879
|
+
exports.isPhone = isPhone;
|
|
880
|
+
exports.isSSR = isSSR;
|
|
881
|
+
exports.isString = isString;
|
|
882
|
+
exports.isStrongPassword = isStrongPassword;
|
|
883
|
+
exports.isToday = isToday;
|
|
884
|
+
exports.isURL = isURL;
|
|
885
|
+
exports.isYesterday = isYesterday;
|
|
886
|
+
exports.last = last;
|
|
887
|
+
exports.mapKeys = mapKeys;
|
|
888
|
+
exports.mapValues = mapValues;
|
|
889
|
+
exports.maskString = maskString;
|
|
890
|
+
exports.median = median;
|
|
891
|
+
exports.nanoid = nanoid;
|
|
892
|
+
exports.omit = omit;
|
|
893
|
+
exports.pLimit = pLimit;
|
|
894
|
+
exports.pSettle = pSettle;
|
|
895
|
+
exports.percentage = percentage;
|
|
896
|
+
exports.pick = pick;
|
|
897
|
+
exports.pluralize = pluralize;
|
|
898
|
+
exports.randomInt = randomInt;
|
|
899
|
+
exports.range = range;
|
|
900
|
+
exports.relativeTime = relativeTime;
|
|
901
|
+
exports.retry = retry;
|
|
902
|
+
exports.round = round;
|
|
903
|
+
exports.shuffle = shuffle;
|
|
904
|
+
exports.sleep = sleep;
|
|
905
|
+
exports.slugify = slugify;
|
|
906
|
+
exports.sortBy = sortBy;
|
|
907
|
+
exports.sum = sum;
|
|
908
|
+
exports.template = template;
|
|
909
|
+
exports.throttle = throttle;
|
|
910
|
+
exports.timeout = timeout;
|
|
911
|
+
exports.toCamelCase = toCamelCase;
|
|
912
|
+
exports.toKebabCase = toKebabCase;
|
|
913
|
+
exports.toPascalCase = toPascalCase;
|
|
914
|
+
exports.toSnakeCase = toSnakeCase;
|
|
915
|
+
exports.truncate = truncate;
|
|
916
|
+
exports.tryCatch = tryCatch;
|
|
917
|
+
exports.tryCatchSync = tryCatchSync;
|
|
918
|
+
exports.unescapeHtml = unescapeHtml;
|
|
919
|
+
exports.unique = unique;
|
|
920
|
+
exports.uniqueBy = uniqueBy;
|
|
921
|
+
exports.uuid = uuid;
|
|
922
|
+
exports.zip = zip;
|
|
923
|
+
//# sourceMappingURL=chunk-SEJ5J4LY.cjs.map
|
|
924
|
+
//# sourceMappingURL=chunk-SEJ5J4LY.cjs.map
|