@karta.io/utils 0.33.8 → 0.34.0-alpha.1
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/dist/index.cjs +110 -113
- package/dist/index.d.ts +142 -142
- package/dist/index.mjs +87 -102
- package/package.json +17 -14
package/dist/index.cjs
CHANGED
|
@@ -15,15 +15,26 @@ const customParseFormat = require('dayjs/plugin/customParseFormat.js');
|
|
|
15
15
|
const detectBrowser = require('detect-browser');
|
|
16
16
|
const logdown = require('logdown');
|
|
17
17
|
|
|
18
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
19
|
+
|
|
20
|
+
const camelCase__default = /*#__PURE__*/_interopDefaultCompat(camelCase);
|
|
21
|
+
const snakeCase__default = /*#__PURE__*/_interopDefaultCompat(snakeCase);
|
|
22
|
+
const dayjs__default = /*#__PURE__*/_interopDefaultCompat(dayjs);
|
|
23
|
+
const utc__default = /*#__PURE__*/_interopDefaultCompat(utc);
|
|
24
|
+
const tz__default = /*#__PURE__*/_interopDefaultCompat(tz);
|
|
25
|
+
const updateLocale__default = /*#__PURE__*/_interopDefaultCompat(updateLocale);
|
|
26
|
+
const isToday__default = /*#__PURE__*/_interopDefaultCompat(isToday);
|
|
27
|
+
const customParseFormat__default = /*#__PURE__*/_interopDefaultCompat(customParseFormat);
|
|
28
|
+
const logdown__default = /*#__PURE__*/_interopDefaultCompat(logdown);
|
|
29
|
+
|
|
18
30
|
function camelizeKeys(object) {
|
|
19
|
-
if (Array.isArray(object))
|
|
31
|
+
if (Array.isArray(object))
|
|
20
32
|
return object.map((v) => camelizeKeys(v));
|
|
21
|
-
}
|
|
22
33
|
if (object !== null && object.constructor === Object) {
|
|
23
34
|
return Object.keys(object).reduce(
|
|
24
35
|
(result, key) => ({
|
|
25
36
|
...result,
|
|
26
|
-
[
|
|
37
|
+
[camelCase__default(key)]: camelizeKeys(object[key])
|
|
27
38
|
}),
|
|
28
39
|
{}
|
|
29
40
|
);
|
|
@@ -34,15 +45,15 @@ function camelizeKeys(object) {
|
|
|
34
45
|
function createClassName(className) {
|
|
35
46
|
return function f(...classNames) {
|
|
36
47
|
const result = classNames.join("");
|
|
37
|
-
|
|
48
|
+
const create = (...args) => args.length ? f.apply(null, [result, ...args])() : result;
|
|
49
|
+
return create;
|
|
38
50
|
}(className);
|
|
39
51
|
}
|
|
40
52
|
|
|
41
53
|
function formatMoney(value, currency = commonData.CURRENCY_DEFAULT, options = {}) {
|
|
42
|
-
|
|
43
|
-
if (value === null || Number.isNaN(convertedValue))
|
|
54
|
+
const convertedValue = Number(value);
|
|
55
|
+
if (value === null || Number.isNaN(convertedValue))
|
|
44
56
|
return "";
|
|
45
|
-
}
|
|
46
57
|
const { locale = "en-US", ...otherOptions } = options;
|
|
47
58
|
const formatter = new Intl.NumberFormat(locale, {
|
|
48
59
|
style: "currency",
|
|
@@ -55,10 +66,7 @@ function formatMoney(value, currency = commonData.CURRENCY_DEFAULT, options = {}
|
|
|
55
66
|
}
|
|
56
67
|
|
|
57
68
|
function genLoadingTableRows(columns, limit) {
|
|
58
|
-
const row = columns.reduce(
|
|
59
|
-
(acc, curr) => ({ ...acc, [curr.key]: void 0 }),
|
|
60
|
-
{}
|
|
61
|
-
);
|
|
69
|
+
const row = columns.reduce((acc, curr) => ({ ...acc, [curr.key]: void 0 }), {});
|
|
62
70
|
return Array.from(Array(limit).keys()).map((item) => ({ id: item, ...row }));
|
|
63
71
|
}
|
|
64
72
|
|
|
@@ -67,7 +75,8 @@ function genRandomNumber(min, max) {
|
|
|
67
75
|
}
|
|
68
76
|
|
|
69
77
|
function genUUID() {
|
|
70
|
-
let d = new Date().getTime()
|
|
78
|
+
let d = (/* @__PURE__ */ new Date()).getTime();
|
|
79
|
+
let d2 = performance && performance.now && performance.now() * 1e3 || 0;
|
|
71
80
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
72
81
|
let r = Math.random() * 16;
|
|
73
82
|
if (d > 0) {
|
|
@@ -140,9 +149,7 @@ function getPaginationParams({
|
|
|
140
149
|
offset: validatedPage * validatedLimit - validatedLimit
|
|
141
150
|
};
|
|
142
151
|
}
|
|
143
|
-
function getPaginationLimit({
|
|
144
|
-
limit
|
|
145
|
-
}) {
|
|
152
|
+
function getPaginationLimit({ limit }) {
|
|
146
153
|
return validateNumber(limit, LIMIT_DEFAULT);
|
|
147
154
|
}
|
|
148
155
|
function getPaginationOffset({
|
|
@@ -164,22 +171,20 @@ function parsePhone(phone) {
|
|
|
164
171
|
if (!phone || typeof phone !== "string")
|
|
165
172
|
return "";
|
|
166
173
|
const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
|
|
167
|
-
if (replacedPhone.length === 1 && replacedPhone !== "+")
|
|
174
|
+
if (replacedPhone.length === 1 && replacedPhone !== "+")
|
|
168
175
|
return `+${replacedPhone}`;
|
|
169
|
-
}
|
|
170
176
|
const phoneNumber = libphonenumberJs.parsePhoneNumberFromString(replacedPhone);
|
|
171
177
|
return phoneNumber ? phoneNumber.formatInternational() : replacedPhone;
|
|
172
178
|
}
|
|
173
179
|
|
|
174
180
|
function snakelizeKeys(prop) {
|
|
175
|
-
if (Array.isArray(prop))
|
|
181
|
+
if (Array.isArray(prop))
|
|
176
182
|
return prop.map((item) => snakelizeKeys(item));
|
|
177
|
-
}
|
|
178
183
|
if (prop !== null && prop !== void 0 && prop.constructor === Object) {
|
|
179
184
|
return Object.keys(prop).reduce(
|
|
180
185
|
(accum, current) => ({
|
|
181
186
|
...accum,
|
|
182
|
-
[
|
|
187
|
+
[snakeCase__default(current)]: snakelizeKeys(prop[current])
|
|
183
188
|
}),
|
|
184
189
|
{}
|
|
185
190
|
);
|
|
@@ -203,27 +208,21 @@ function unformatNumber(value) {
|
|
|
203
208
|
const commasCount = (string.match(/,/g) || []).length;
|
|
204
209
|
if (!Number.isNaN(Number(string)))
|
|
205
210
|
return Number(string);
|
|
206
|
-
if (hasSpace && hasComma && commaIndex > spaceIndex)
|
|
211
|
+
if (hasSpace && hasComma && commaIndex > spaceIndex)
|
|
207
212
|
locale = LOCALE_RU;
|
|
208
|
-
|
|
209
|
-
if (hasSpace && !hasComma && !hasDot) {
|
|
213
|
+
if (hasSpace && !hasComma && !hasDot)
|
|
210
214
|
locale = LOCALE_RU;
|
|
211
|
-
|
|
212
|
-
if (hasComma && hasDot && dotIndex > commaIndex) {
|
|
215
|
+
if (hasComma && hasDot && dotIndex > commaIndex)
|
|
213
216
|
locale = LOCALE_EN;
|
|
214
|
-
|
|
215
|
-
if (hasComma && !hasSpace && !hasDot && commasCount > 1) {
|
|
217
|
+
if (hasComma && !hasSpace && !hasDot && commasCount > 1)
|
|
216
218
|
locale = LOCALE_EN;
|
|
217
|
-
}
|
|
218
219
|
if (commasCount === 1 && !hasSpace && !hasDot) {
|
|
219
220
|
locale = string.length - 1 - commaIndex === 3 ? LOCALE_EN : LOCALE_RU;
|
|
220
221
|
}
|
|
221
|
-
if (locale === LOCALE_RU)
|
|
222
|
+
if (locale === LOCALE_RU)
|
|
222
223
|
return Number(string.replaceAll(" ", "").replace(",", "."));
|
|
223
|
-
|
|
224
|
-
if (locale === LOCALE_EN) {
|
|
224
|
+
if (locale === LOCALE_EN)
|
|
225
225
|
return Number(string.replaceAll(",", ""));
|
|
226
|
-
}
|
|
227
226
|
return value;
|
|
228
227
|
}
|
|
229
228
|
|
|
@@ -232,9 +231,8 @@ function UiComponentsResolver(options = {}) {
|
|
|
232
231
|
return (name) => {
|
|
233
232
|
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
234
233
|
const isUiComponent = componentName.startsWith("Ui");
|
|
235
|
-
if (isUiComponent)
|
|
234
|
+
if (isUiComponent)
|
|
236
235
|
return { name: componentName, from: "@karta.io/ui-components" };
|
|
237
|
-
}
|
|
238
236
|
};
|
|
239
237
|
}
|
|
240
238
|
|
|
@@ -242,9 +240,8 @@ function useAbortController(callback) {
|
|
|
242
240
|
let controller = null;
|
|
243
241
|
return {
|
|
244
242
|
async call(...args) {
|
|
245
|
-
if (controller)
|
|
243
|
+
if (controller)
|
|
246
244
|
controller.abort();
|
|
247
|
-
}
|
|
248
245
|
controller = new AbortController();
|
|
249
246
|
let response;
|
|
250
247
|
if (args.length > 0) {
|
|
@@ -284,11 +281,7 @@ function useAsyncMultiselect({
|
|
|
284
281
|
const page = vue.ref(1);
|
|
285
282
|
const options = vue.computed(() => [...items.value.values()]);
|
|
286
283
|
const hasNextPage = vue.computed(() => count.value > items.value.size);
|
|
287
|
-
const {
|
|
288
|
-
call: apiMethodWAC,
|
|
289
|
-
abort,
|
|
290
|
-
isAborted
|
|
291
|
-
} = useAbortController(apiMethod);
|
|
284
|
+
const { call: apiMethodWAC, abort, isAborted } = useAbortController(apiMethod);
|
|
292
285
|
const handleSearch = async (value) => {
|
|
293
286
|
if (search.value === value)
|
|
294
287
|
return;
|
|
@@ -306,12 +299,10 @@ function useAsyncMultiselect({
|
|
|
306
299
|
});
|
|
307
300
|
count.value = itemsCount;
|
|
308
301
|
if (isSearch) {
|
|
309
|
-
const cashedMapItems = selectedValues.value.map(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
]
|
|
314
|
-
);
|
|
302
|
+
const cashedMapItems = selectedValues.value.map((selectedValue) => [
|
|
303
|
+
selectedValue,
|
|
304
|
+
items.value.get(selectedValue)
|
|
305
|
+
]);
|
|
315
306
|
items.value = new Map([...cashedMapItems]);
|
|
316
307
|
}
|
|
317
308
|
const resultsForMap = results.map(mapResultCallback);
|
|
@@ -355,11 +346,7 @@ function useAsyncSelect({
|
|
|
355
346
|
const page = vue.ref(1);
|
|
356
347
|
const options = vue.computed(() => [...items.value.values()]);
|
|
357
348
|
const hasNextPage = vue.computed(() => count.value > items.value.size);
|
|
358
|
-
const {
|
|
359
|
-
call: apiMethodWAC,
|
|
360
|
-
abort,
|
|
361
|
-
isAborted
|
|
362
|
-
} = useAbortController(apiMethod);
|
|
349
|
+
const { call: apiMethodWAC, abort, isAborted } = useAbortController(apiMethod);
|
|
363
350
|
const handleSearch = async (value) => {
|
|
364
351
|
if (search.value === value)
|
|
365
352
|
return;
|
|
@@ -376,9 +363,8 @@ function useAsyncSelect({
|
|
|
376
363
|
...params
|
|
377
364
|
});
|
|
378
365
|
count.value = itemsCount;
|
|
379
|
-
if (isSearch)
|
|
366
|
+
if (isSearch)
|
|
380
367
|
items.value = /* @__PURE__ */ new Map();
|
|
381
|
-
}
|
|
382
368
|
const resultsForMap = results.map(mapResultCallback);
|
|
383
369
|
items.value = new Map([...items.value, ...resultsForMap]);
|
|
384
370
|
page.value += 1;
|
|
@@ -407,23 +393,19 @@ function useAsyncSelect({
|
|
|
407
393
|
};
|
|
408
394
|
}
|
|
409
395
|
|
|
410
|
-
|
|
396
|
+
function _bem(block, blockSuffix, element, modifier, modifierValue) {
|
|
411
397
|
let cls = block;
|
|
412
|
-
if (blockSuffix)
|
|
398
|
+
if (blockSuffix)
|
|
413
399
|
cls += `-${blockSuffix}`;
|
|
414
|
-
|
|
415
|
-
if (element) {
|
|
400
|
+
if (element)
|
|
416
401
|
cls += `__${element}`;
|
|
417
|
-
|
|
418
|
-
if (modifier) {
|
|
402
|
+
if (modifier)
|
|
419
403
|
cls += `_${modifier}`;
|
|
420
|
-
|
|
421
|
-
if (modifierValue) {
|
|
404
|
+
if (modifierValue)
|
|
422
405
|
cls += `_${modifierValue}`;
|
|
423
|
-
}
|
|
424
406
|
return cls;
|
|
425
|
-
}
|
|
426
|
-
|
|
407
|
+
}
|
|
408
|
+
function useClassName(block) {
|
|
427
409
|
const b = (blockSuffix = "") => _bem(block, blockSuffix, "", "", "");
|
|
428
410
|
const e = (element) => element ? _bem(block, "", element, "", "") : "";
|
|
429
411
|
const m = (modifier, condition = true) => modifier && condition ? _bem(block, "", "", modifier, "") : "";
|
|
@@ -431,9 +413,8 @@ const useClassName = (block) => {
|
|
|
431
413
|
const mv = (modifier, modifierValue, condition = true) => modifier && modifierValue && condition ? _bem(block, "", "", modifier, modifierValue) : "";
|
|
432
414
|
const cssVar = (object) => {
|
|
433
415
|
const styles = {};
|
|
434
|
-
for (const key in object)
|
|
416
|
+
for (const key in object)
|
|
435
417
|
styles[`--${block}-${key}`] = object[key];
|
|
436
|
-
}
|
|
437
418
|
return styles;
|
|
438
419
|
};
|
|
439
420
|
const cssVarName = (name) => `--${block}-${name}`;
|
|
@@ -447,32 +428,34 @@ const useClassName = (block) => {
|
|
|
447
428
|
cssVar,
|
|
448
429
|
cssVarName
|
|
449
430
|
};
|
|
450
|
-
}
|
|
431
|
+
}
|
|
451
432
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
433
|
+
dayjs__default.extend(utc__default);
|
|
434
|
+
dayjs__default.extend(tz__default);
|
|
435
|
+
dayjs__default.extend(updateLocale__default);
|
|
436
|
+
dayjs__default.extend(isToday__default);
|
|
437
|
+
dayjs__default.extend(customParseFormat__default);
|
|
457
438
|
function useDayjs(timezone) {
|
|
458
|
-
|
|
439
|
+
dayjs__default.updateLocale("en", {
|
|
459
440
|
weekStart: 1
|
|
460
441
|
});
|
|
461
|
-
if (!timezone)
|
|
462
|
-
return
|
|
463
|
-
|
|
464
|
-
const dayjsExtended = (date, format, locale, strict) => dayjs(date, format, locale, strict).tz(timezone);
|
|
442
|
+
if (!timezone)
|
|
443
|
+
return dayjs__default;
|
|
444
|
+
const dayjsExtended = (date, format, locale, strict) => dayjs__default(date, format, locale, strict).tz(timezone);
|
|
465
445
|
return dayjsExtended;
|
|
466
446
|
}
|
|
467
447
|
|
|
468
448
|
function parseVersion(version) {
|
|
469
449
|
if (typeof version !== "string" && typeof version !== "number") {
|
|
470
|
-
throw new TypeError(
|
|
471
|
-
"Browser version must be type of string, number or negative boolean"
|
|
472
|
-
);
|
|
450
|
+
throw new TypeError("Browser version must be type of string, number or negative boolean");
|
|
473
451
|
}
|
|
474
452
|
const [major, minor = 0, patch = 0, build = 0] = typeof version === "string" ? version.split(".").map(Number) : [version];
|
|
475
|
-
return {
|
|
453
|
+
return {
|
|
454
|
+
major,
|
|
455
|
+
minor,
|
|
456
|
+
patch,
|
|
457
|
+
build
|
|
458
|
+
};
|
|
476
459
|
}
|
|
477
460
|
function isVersionLower(minimum, target) {
|
|
478
461
|
for (const k of ["major", "minor", "patch"]) {
|
|
@@ -517,7 +500,7 @@ function isEnabled(options) {
|
|
|
517
500
|
}
|
|
518
501
|
const isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
519
502
|
if (isNode) {
|
|
520
|
-
const debug = process.env
|
|
503
|
+
const debug = process.env.NODE_DEBUG;
|
|
521
504
|
if (debug === "true")
|
|
522
505
|
return true;
|
|
523
506
|
if (debug === "false")
|
|
@@ -527,7 +510,7 @@ function isEnabled(options) {
|
|
|
527
510
|
}
|
|
528
511
|
function useLogger(scope, options) {
|
|
529
512
|
const prefix = options?.tag ? `[${scope.toUpperCase()}.${options.tag}]:` : `[${scope.toUpperCase()}]:`;
|
|
530
|
-
const logger =
|
|
513
|
+
const logger = logdown__default(prefix, { prefixColor: options?.color });
|
|
531
514
|
logger.state.isEnabled = isEnabled(options);
|
|
532
515
|
return logger;
|
|
533
516
|
}
|
|
@@ -539,35 +522,49 @@ function validatePhone(rule, value) {
|
|
|
539
522
|
return phoneNumber ? phoneNumber.isValid() : false;
|
|
540
523
|
}
|
|
541
524
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
}
|
|
525
|
+
function isRequired(value = true, message = "This field is required") {
|
|
526
|
+
return {
|
|
527
|
+
required: value,
|
|
528
|
+
message
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
function isMax(value = 255, message) {
|
|
532
|
+
return {
|
|
533
|
+
max: value,
|
|
534
|
+
message: message ?? `Length must be no more than ${value} characters`
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
function isMin(value = 3, message) {
|
|
538
|
+
return {
|
|
539
|
+
min: value,
|
|
540
|
+
message: message ?? `Length must be at least ${value} characters`
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
function isTypeEmail(message = "Invalid format") {
|
|
544
|
+
return {
|
|
545
|
+
type: "email",
|
|
546
|
+
message
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
function isTypeUrl(message = "The url is invalid") {
|
|
550
|
+
return {
|
|
551
|
+
type: "url",
|
|
552
|
+
message
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
function isTypeNumber(value = 1, message) {
|
|
556
|
+
return {
|
|
557
|
+
type: "number",
|
|
558
|
+
min: value,
|
|
559
|
+
message: message ?? `Must be at least ${value}`
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
function isStrictLength(value = 3, message) {
|
|
563
|
+
return {
|
|
564
|
+
len: value,
|
|
565
|
+
message: message ?? `Length must be exactly ${value} characters`
|
|
566
|
+
};
|
|
567
|
+
}
|
|
571
568
|
|
|
572
569
|
exports.UiComponentsResolver = UiComponentsResolver;
|
|
573
570
|
exports.camelizeKeys = camelizeKeys;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,195 +5,195 @@ import { Browser } from 'detect-browser';
|
|
|
5
5
|
import logdown from 'logdown';
|
|
6
6
|
import { RuleItem } from 'async-validator';
|
|
7
7
|
|
|
8
|
-
interface Dictionary {
|
|
9
|
-
[keys: string | number]: any;
|
|
10
|
-
}
|
|
11
|
-
interface ResponseError {
|
|
12
|
-
status: number;
|
|
13
|
-
statusMessage: string;
|
|
14
|
-
message: string;
|
|
15
|
-
data: Record<string, string | string[]> | null;
|
|
8
|
+
interface Dictionary {
|
|
9
|
+
[keys: string | number]: any;
|
|
10
|
+
}
|
|
11
|
+
interface ResponseError {
|
|
12
|
+
status: number;
|
|
13
|
+
statusMessage: string;
|
|
14
|
+
message: string;
|
|
15
|
+
data: Record<string, string | string[]> | null;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
declare function camelizeKeys(object: Dictionary): Dictionary;
|
|
19
19
|
|
|
20
20
|
declare function createClassName(className: string): (...classNames: string[]) => string;
|
|
21
21
|
|
|
22
|
-
interface Options$2 extends Intl.NumberFormatOptions {
|
|
23
|
-
locale?: string;
|
|
24
|
-
}
|
|
22
|
+
interface Options$2 extends Intl.NumberFormatOptions {
|
|
23
|
+
locale?: string;
|
|
24
|
+
}
|
|
25
25
|
declare function formatMoney(value: string | number | null | undefined, currency?: string, options?: Options$2): string;
|
|
26
26
|
|
|
27
|
-
declare function genLoadingTableRows(columns: Dictionary[], limit: number): {
|
|
28
|
-
id: number | undefined;
|
|
29
|
-
key?: undefined;
|
|
27
|
+
declare function genLoadingTableRows(columns: Dictionary[], limit: number): {
|
|
28
|
+
id: number | undefined;
|
|
29
|
+
key?: undefined;
|
|
30
30
|
}[];
|
|
31
31
|
|
|
32
32
|
declare function genRandomNumber(min: number, max: number): number;
|
|
33
33
|
|
|
34
34
|
declare function genUUID(): string;
|
|
35
35
|
|
|
36
|
-
interface Options$1 {
|
|
37
|
-
hasOnlyLast4: boolean;
|
|
38
|
-
isHidden: boolean;
|
|
39
|
-
dot: string;
|
|
40
|
-
}
|
|
36
|
+
interface Options$1 {
|
|
37
|
+
hasOnlyLast4: boolean;
|
|
38
|
+
isHidden: boolean;
|
|
39
|
+
dot: string;
|
|
40
|
+
}
|
|
41
41
|
declare function getCardNumber(number: string, options?: Partial<Options$1>): string;
|
|
42
42
|
|
|
43
43
|
declare function getCountryFromPhone(phone: string): string;
|
|
44
44
|
|
|
45
|
-
declare function isElementIgnored({ ignoredClasses, event, }?: {
|
|
46
|
-
ignoredClasses?: string[];
|
|
47
|
-
event?: Event;
|
|
45
|
+
declare function isElementIgnored({ ignoredClasses, event, }?: {
|
|
46
|
+
ignoredClasses?: string[];
|
|
47
|
+
event?: Event;
|
|
48
48
|
}): boolean;
|
|
49
49
|
|
|
50
|
-
declare function isEmptyObject(object:
|
|
51
|
-
|
|
52
|
-
declare function getPaginationParams({ page, limit, }: {
|
|
53
|
-
page: string | number;
|
|
54
|
-
limit: string | number;
|
|
55
|
-
}): {
|
|
56
|
-
limit: number;
|
|
57
|
-
offset: number;
|
|
58
|
-
};
|
|
59
|
-
declare function getPaginationLimit({ limit
|
|
60
|
-
limit: string | number;
|
|
61
|
-
}): number;
|
|
62
|
-
declare function getPaginationOffset({ page, limit, }: {
|
|
63
|
-
page: string | number;
|
|
64
|
-
limit: string | number;
|
|
65
|
-
}): number;
|
|
66
|
-
declare function getPaginationPages({ count, limit, }: {
|
|
67
|
-
count: number;
|
|
68
|
-
limit: string | number;
|
|
50
|
+
declare function isEmptyObject(object: object): boolean;
|
|
51
|
+
|
|
52
|
+
declare function getPaginationParams({ page, limit, }: {
|
|
53
|
+
page: string | number;
|
|
54
|
+
limit: string | number;
|
|
55
|
+
}): {
|
|
56
|
+
limit: number;
|
|
57
|
+
offset: number;
|
|
58
|
+
};
|
|
59
|
+
declare function getPaginationLimit({ limit }: {
|
|
60
|
+
limit: string | number;
|
|
61
|
+
}): number;
|
|
62
|
+
declare function getPaginationOffset({ page, limit, }: {
|
|
63
|
+
page: string | number;
|
|
64
|
+
limit: string | number;
|
|
65
|
+
}): number;
|
|
66
|
+
declare function getPaginationPages({ count, limit, }: {
|
|
67
|
+
count: number;
|
|
68
|
+
limit: string | number;
|
|
69
69
|
}): number;
|
|
70
70
|
|
|
71
71
|
declare function parsePhone(phone: string | null | undefined): string;
|
|
72
72
|
|
|
73
|
-
type SnakelizeKeysProp = Record<string | number, any>;
|
|
73
|
+
type SnakelizeKeysProp = Record<string | number, any>;
|
|
74
74
|
declare function snakelizeKeys(prop: SnakelizeKeysProp): SnakelizeKeysProp;
|
|
75
75
|
|
|
76
|
-
/**
|
|
77
|
-
* Принимает на вход число в виде строки или числа,
|
|
78
|
-
* возвращает корректное значение типа Number (убирает лишние пробелы и запятые)
|
|
79
|
-
* @example
|
|
80
|
-
* // returns 1000
|
|
81
|
-
* unformatNumber('1 000');
|
|
82
|
-
* @example
|
|
83
|
-
* // returns 1000
|
|
84
|
-
* unformatNumber('1,000')
|
|
85
|
-
* @example
|
|
86
|
-
* // returns 1000.123
|
|
87
|
-
* unformatNummber('1 000,123')
|
|
88
|
-
* @example
|
|
89
|
-
* // returns 1000.123
|
|
90
|
-
* unformatNummber('1,000.123')
|
|
91
|
-
* @param value
|
|
92
|
-
* @return number
|
|
93
|
-
*/
|
|
76
|
+
/**
|
|
77
|
+
* Принимает на вход число в виде строки или числа,
|
|
78
|
+
* возвращает корректное значение типа Number (убирает лишние пробелы и запятые)
|
|
79
|
+
* @example
|
|
80
|
+
* // returns 1000
|
|
81
|
+
* unformatNumber('1 000');
|
|
82
|
+
* @example
|
|
83
|
+
* // returns 1000
|
|
84
|
+
* unformatNumber('1,000')
|
|
85
|
+
* @example
|
|
86
|
+
* // returns 1000.123
|
|
87
|
+
* unformatNummber('1 000,123')
|
|
88
|
+
* @example
|
|
89
|
+
* // returns 1000.123
|
|
90
|
+
* unformatNummber('1,000.123')
|
|
91
|
+
* @param value
|
|
92
|
+
* @return number
|
|
93
|
+
*/
|
|
94
94
|
declare function unformatNumber(value: string | number): string | number;
|
|
95
95
|
|
|
96
96
|
declare function validateNumber(value: string | number, defaultValue: number): number;
|
|
97
97
|
|
|
98
|
-
interface UiComponentsResolverOptions {
|
|
99
|
-
prefix?: string;
|
|
100
|
-
}
|
|
98
|
+
interface UiComponentsResolverOptions {
|
|
99
|
+
prefix?: string;
|
|
100
|
+
}
|
|
101
101
|
declare function UiComponentsResolver(options?: UiComponentsResolverOptions): any;
|
|
102
102
|
|
|
103
|
-
declare function useAbortController<T extends (...args: any[]) => any>(callback: T): {
|
|
104
|
-
call(...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
105
|
-
abort(): void;
|
|
106
|
-
isAborted(error: ResponseError): boolean;
|
|
103
|
+
declare function useAbortController<T extends (...args: any[]) => any>(callback: T): {
|
|
104
|
+
call(...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
105
|
+
abort(): void;
|
|
106
|
+
isAborted(error: ResponseError): boolean;
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
-
declare function useAsyncMultiselect<T extends (...args: any[]) => any, K extends (params: Awaited<ReturnType<T>>['results'][0]) => any>({ apiMethod, mapResultCallback, selectedValues, params, }: {
|
|
110
|
-
apiMethod: T;
|
|
111
|
-
mapResultCallback: K;
|
|
112
|
-
selectedValues: ComputedRef<Parameters<T>[0]['includedIds']> | WritableComputedRef<Parameters<T>[0]['includedIds']>;
|
|
113
|
-
params?: Parameters<T>[0];
|
|
114
|
-
}): {
|
|
115
|
-
search: vue.Ref<string>;
|
|
116
|
-
options: ComputedRef<ReturnType<K>[1][]>;
|
|
117
|
-
loading: vue.Ref<boolean>;
|
|
118
|
-
hasNextPage: ComputedRef<boolean>;
|
|
119
|
-
items: vue.Ref<Map<ReturnType<K>[0], ReturnType<K>[1]>>;
|
|
120
|
-
loadItems: (isSearch?: boolean) => Promise<void>;
|
|
121
|
-
handleSearch: (value: string) => Promise<void>;
|
|
109
|
+
declare function useAsyncMultiselect<T extends (...args: any[]) => any, K extends (params: Awaited<ReturnType<T>>['results'][0]) => any>({ apiMethod, mapResultCallback, selectedValues, params, }: {
|
|
110
|
+
apiMethod: T;
|
|
111
|
+
mapResultCallback: K;
|
|
112
|
+
selectedValues: ComputedRef<Parameters<T>[0]['includedIds']> | WritableComputedRef<Parameters<T>[0]['includedIds']>;
|
|
113
|
+
params?: Parameters<T>[0];
|
|
114
|
+
}): {
|
|
115
|
+
search: vue.Ref<string>;
|
|
116
|
+
options: ComputedRef<ReturnType<K>[1][]>;
|
|
117
|
+
loading: vue.Ref<boolean>;
|
|
118
|
+
hasNextPage: ComputedRef<boolean>;
|
|
119
|
+
items: vue.Ref<Map<ReturnType<K>[0], ReturnType<K>[1]>>;
|
|
120
|
+
loadItems: (isSearch?: boolean) => Promise<void>;
|
|
121
|
+
handleSearch: (value: string) => Promise<void>;
|
|
122
122
|
};
|
|
123
123
|
|
|
124
|
-
declare function useAsyncSelect<T extends (...args: any[]) => any, K extends (params: Awaited<ReturnType<T>>['results'][0]) => any>({ apiMethod, mapResultCallback, includedIds, params, }: {
|
|
125
|
-
apiMethod: T;
|
|
126
|
-
mapResultCallback: K;
|
|
127
|
-
includedIds?: Parameters<T>[0]['includedIds'];
|
|
128
|
-
params?: Parameters<T>[0];
|
|
129
|
-
}): {
|
|
130
|
-
search: vue.Ref<string>;
|
|
131
|
-
options: vue.ComputedRef<ReturnType<K>[1][]>;
|
|
132
|
-
loading: vue.Ref<boolean>;
|
|
133
|
-
hasNextPage: vue.ComputedRef<boolean>;
|
|
134
|
-
items: vue.Ref<Map<ReturnType<K>[0], ReturnType<K>[1]>>;
|
|
135
|
-
loadItems: (isSearch?: boolean) => Promise<void>;
|
|
136
|
-
handleSearch: (value: string) => Promise<void>;
|
|
124
|
+
declare function useAsyncSelect<T extends (...args: any[]) => any, K extends (params: Awaited<ReturnType<T>>['results'][0]) => any>({ apiMethod, mapResultCallback, includedIds, params, }: {
|
|
125
|
+
apiMethod: T;
|
|
126
|
+
mapResultCallback: K;
|
|
127
|
+
includedIds?: Parameters<T>[0]['includedIds'];
|
|
128
|
+
params?: Parameters<T>[0];
|
|
129
|
+
}): {
|
|
130
|
+
search: vue.Ref<string>;
|
|
131
|
+
options: vue.ComputedRef<ReturnType<K>[1][]>;
|
|
132
|
+
loading: vue.Ref<boolean>;
|
|
133
|
+
hasNextPage: vue.ComputedRef<boolean>;
|
|
134
|
+
items: vue.Ref<Map<ReturnType<K>[0], ReturnType<K>[1]>>;
|
|
135
|
+
loadItems: (isSearch?: boolean) => Promise<void>;
|
|
136
|
+
handleSearch: (value: string) => Promise<void>;
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
-
declare
|
|
140
|
-
b: (blockSuffix?: string) => string;
|
|
141
|
-
e: (element?: string) => string;
|
|
142
|
-
m: (modifier?: string, condition?: boolean) => string;
|
|
143
|
-
em: (element?: string, modifier?: string, condition?: boolean) => string;
|
|
144
|
-
mv: (modifier: string, modifierValue: string, condition?: boolean) => string;
|
|
145
|
-
cssVar: (object: Record<string, string>) => Record<string, string>;
|
|
146
|
-
cssVarName: (name: string) => string;
|
|
139
|
+
declare function useClassName(block: string): {
|
|
140
|
+
b: (blockSuffix?: string) => string;
|
|
141
|
+
e: (element?: string) => string;
|
|
142
|
+
m: (modifier?: string, condition?: boolean) => string;
|
|
143
|
+
em: (element?: string, modifier?: string, condition?: boolean) => string;
|
|
144
|
+
mv: (modifier: string, modifierValue: string, condition?: boolean) => string;
|
|
145
|
+
cssVar: (object: Record<string, string>) => Record<string, string>;
|
|
146
|
+
cssVarName: (name: string) => string;
|
|
147
147
|
};
|
|
148
148
|
|
|
149
|
-
/**
|
|
150
|
-
* Обертка над dayjs, позволяющая задавать timezone
|
|
151
|
-
* @see https://day.js.org/en/
|
|
152
|
-
*
|
|
153
|
-
* Использовать параметр timezone нужно крайне аккуратно,
|
|
154
|
-
* может привести к утечкам памяти
|
|
155
|
-
* @todo Подумать как сделать оптимальнее
|
|
156
|
-
*/
|
|
149
|
+
/**
|
|
150
|
+
* Обертка над dayjs, позволяющая задавать timezone
|
|
151
|
+
* @see https://day.js.org/en/
|
|
152
|
+
*
|
|
153
|
+
* Использовать параметр timezone нужно крайне аккуратно,
|
|
154
|
+
* может привести к утечкам памяти
|
|
155
|
+
* @todo Подумать как сделать оптимальнее
|
|
156
|
+
*/
|
|
157
157
|
declare function useDayjs(timezone?: string): (date?: dayjs.ConfigType, format?: dayjs.OptionType, locale?: string, strict?: boolean) => dayjs.Dayjs;
|
|
158
158
|
|
|
159
|
-
interface BrowserInfo {
|
|
160
|
-
isDeprecated?: boolean;
|
|
161
|
-
name?: string;
|
|
162
|
-
version?: string;
|
|
163
|
-
os?: string;
|
|
164
|
-
type?: string;
|
|
165
|
-
options?: any;
|
|
166
|
-
}
|
|
167
|
-
type VersionsList = {
|
|
168
|
-
[key in Browser]?: string | boolean;
|
|
169
|
-
};
|
|
159
|
+
interface BrowserInfo {
|
|
160
|
+
isDeprecated?: boolean;
|
|
161
|
+
name?: string;
|
|
162
|
+
version?: string;
|
|
163
|
+
os?: string;
|
|
164
|
+
type?: string;
|
|
165
|
+
options?: any;
|
|
166
|
+
}
|
|
167
|
+
type VersionsList = {
|
|
168
|
+
[key in Browser]?: string | boolean;
|
|
169
|
+
};
|
|
170
170
|
declare function useDetectBrowser(versions: VersionsList, userAgent?: any): BrowserInfo;
|
|
171
171
|
|
|
172
|
-
/**
|
|
173
|
-
* @see https://github.com/caiogondim/logdown.js#readme
|
|
174
|
-
*/
|
|
175
|
-
|
|
176
|
-
interface Options {
|
|
177
|
-
tag?: string;
|
|
178
|
-
color?: string;
|
|
179
|
-
debug?: boolean;
|
|
180
|
-
}
|
|
172
|
+
/**
|
|
173
|
+
* @see https://github.com/caiogondim/logdown.js#readme
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
interface Options {
|
|
177
|
+
tag?: string;
|
|
178
|
+
color?: string;
|
|
179
|
+
debug?: boolean;
|
|
180
|
+
}
|
|
181
181
|
declare function useLogger(scope: string, options?: Options): logdown.Logger;
|
|
182
182
|
|
|
183
183
|
declare function validatePhone(rule: string, value: string): boolean;
|
|
184
184
|
|
|
185
|
-
declare
|
|
186
|
-
declare
|
|
187
|
-
max: number;
|
|
188
|
-
message: string;
|
|
189
|
-
};
|
|
190
|
-
declare
|
|
191
|
-
min: number;
|
|
192
|
-
message: string;
|
|
193
|
-
};
|
|
194
|
-
declare
|
|
195
|
-
declare
|
|
196
|
-
declare
|
|
197
|
-
declare
|
|
185
|
+
declare function isRequired(value?: boolean, message?: string): RuleItem;
|
|
186
|
+
declare function isMax(value?: number, message?: string): {
|
|
187
|
+
max: number;
|
|
188
|
+
message: string;
|
|
189
|
+
};
|
|
190
|
+
declare function isMin(value?: number, message?: string): {
|
|
191
|
+
min: number;
|
|
192
|
+
message: string;
|
|
193
|
+
};
|
|
194
|
+
declare function isTypeEmail(message?: string): RuleItem;
|
|
195
|
+
declare function isTypeUrl(message?: string): RuleItem;
|
|
196
|
+
declare function isTypeNumber(value?: number, message?: string): RuleItem;
|
|
197
|
+
declare function isStrictLength(value?: number, message?: string): RuleItem;
|
|
198
198
|
|
|
199
199
|
export { BrowserInfo, Dictionary, ResponseError, UiComponentsResolver, VersionsList, camelizeKeys, createClassName, formatMoney, genLoadingTableRows, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, isElementIgnored, isEmptyObject, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncMultiselect, useAsyncSelect, useClassName, useDayjs, useDetectBrowser, useLogger, validateNumber, validatePhone };
|
package/dist/index.mjs
CHANGED
|
@@ -14,9 +14,8 @@ import { detect } from 'detect-browser';
|
|
|
14
14
|
import logdown from 'logdown';
|
|
15
15
|
|
|
16
16
|
function camelizeKeys(object) {
|
|
17
|
-
if (Array.isArray(object))
|
|
17
|
+
if (Array.isArray(object))
|
|
18
18
|
return object.map((v) => camelizeKeys(v));
|
|
19
|
-
}
|
|
20
19
|
if (object !== null && object.constructor === Object) {
|
|
21
20
|
return Object.keys(object).reduce(
|
|
22
21
|
(result, key) => ({
|
|
@@ -32,15 +31,15 @@ function camelizeKeys(object) {
|
|
|
32
31
|
function createClassName(className) {
|
|
33
32
|
return function f(...classNames) {
|
|
34
33
|
const result = classNames.join("");
|
|
35
|
-
|
|
34
|
+
const create = (...args) => args.length ? f.apply(null, [result, ...args])() : result;
|
|
35
|
+
return create;
|
|
36
36
|
}(className);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
function formatMoney(value, currency = CURRENCY_DEFAULT, options = {}) {
|
|
40
|
-
|
|
41
|
-
if (value === null || Number.isNaN(convertedValue))
|
|
40
|
+
const convertedValue = Number(value);
|
|
41
|
+
if (value === null || Number.isNaN(convertedValue))
|
|
42
42
|
return "";
|
|
43
|
-
}
|
|
44
43
|
const { locale = "en-US", ...otherOptions } = options;
|
|
45
44
|
const formatter = new Intl.NumberFormat(locale, {
|
|
46
45
|
style: "currency",
|
|
@@ -53,10 +52,7 @@ function formatMoney(value, currency = CURRENCY_DEFAULT, options = {}) {
|
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
function genLoadingTableRows(columns, limit) {
|
|
56
|
-
const row = columns.reduce(
|
|
57
|
-
(acc, curr) => ({ ...acc, [curr.key]: void 0 }),
|
|
58
|
-
{}
|
|
59
|
-
);
|
|
55
|
+
const row = columns.reduce((acc, curr) => ({ ...acc, [curr.key]: void 0 }), {});
|
|
60
56
|
return Array.from(Array(limit).keys()).map((item) => ({ id: item, ...row }));
|
|
61
57
|
}
|
|
62
58
|
|
|
@@ -65,7 +61,8 @@ function genRandomNumber(min, max) {
|
|
|
65
61
|
}
|
|
66
62
|
|
|
67
63
|
function genUUID() {
|
|
68
|
-
let d = new Date().getTime()
|
|
64
|
+
let d = (/* @__PURE__ */ new Date()).getTime();
|
|
65
|
+
let d2 = performance && performance.now && performance.now() * 1e3 || 0;
|
|
69
66
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
70
67
|
let r = Math.random() * 16;
|
|
71
68
|
if (d > 0) {
|
|
@@ -138,9 +135,7 @@ function getPaginationParams({
|
|
|
138
135
|
offset: validatedPage * validatedLimit - validatedLimit
|
|
139
136
|
};
|
|
140
137
|
}
|
|
141
|
-
function getPaginationLimit({
|
|
142
|
-
limit
|
|
143
|
-
}) {
|
|
138
|
+
function getPaginationLimit({ limit }) {
|
|
144
139
|
return validateNumber(limit, LIMIT_DEFAULT);
|
|
145
140
|
}
|
|
146
141
|
function getPaginationOffset({
|
|
@@ -162,17 +157,15 @@ function parsePhone(phone) {
|
|
|
162
157
|
if (!phone || typeof phone !== "string")
|
|
163
158
|
return "";
|
|
164
159
|
const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
|
|
165
|
-
if (replacedPhone.length === 1 && replacedPhone !== "+")
|
|
160
|
+
if (replacedPhone.length === 1 && replacedPhone !== "+")
|
|
166
161
|
return `+${replacedPhone}`;
|
|
167
|
-
}
|
|
168
162
|
const phoneNumber = parsePhoneNumberFromString(replacedPhone);
|
|
169
163
|
return phoneNumber ? phoneNumber.formatInternational() : replacedPhone;
|
|
170
164
|
}
|
|
171
165
|
|
|
172
166
|
function snakelizeKeys(prop) {
|
|
173
|
-
if (Array.isArray(prop))
|
|
167
|
+
if (Array.isArray(prop))
|
|
174
168
|
return prop.map((item) => snakelizeKeys(item));
|
|
175
|
-
}
|
|
176
169
|
if (prop !== null && prop !== void 0 && prop.constructor === Object) {
|
|
177
170
|
return Object.keys(prop).reduce(
|
|
178
171
|
(accum, current) => ({
|
|
@@ -201,27 +194,21 @@ function unformatNumber(value) {
|
|
|
201
194
|
const commasCount = (string.match(/,/g) || []).length;
|
|
202
195
|
if (!Number.isNaN(Number(string)))
|
|
203
196
|
return Number(string);
|
|
204
|
-
if (hasSpace && hasComma && commaIndex > spaceIndex)
|
|
197
|
+
if (hasSpace && hasComma && commaIndex > spaceIndex)
|
|
205
198
|
locale = LOCALE_RU;
|
|
206
|
-
|
|
207
|
-
if (hasSpace && !hasComma && !hasDot) {
|
|
199
|
+
if (hasSpace && !hasComma && !hasDot)
|
|
208
200
|
locale = LOCALE_RU;
|
|
209
|
-
|
|
210
|
-
if (hasComma && hasDot && dotIndex > commaIndex) {
|
|
201
|
+
if (hasComma && hasDot && dotIndex > commaIndex)
|
|
211
202
|
locale = LOCALE_EN;
|
|
212
|
-
|
|
213
|
-
if (hasComma && !hasSpace && !hasDot && commasCount > 1) {
|
|
203
|
+
if (hasComma && !hasSpace && !hasDot && commasCount > 1)
|
|
214
204
|
locale = LOCALE_EN;
|
|
215
|
-
}
|
|
216
205
|
if (commasCount === 1 && !hasSpace && !hasDot) {
|
|
217
206
|
locale = string.length - 1 - commaIndex === 3 ? LOCALE_EN : LOCALE_RU;
|
|
218
207
|
}
|
|
219
|
-
if (locale === LOCALE_RU)
|
|
208
|
+
if (locale === LOCALE_RU)
|
|
220
209
|
return Number(string.replaceAll(" ", "").replace(",", "."));
|
|
221
|
-
|
|
222
|
-
if (locale === LOCALE_EN) {
|
|
210
|
+
if (locale === LOCALE_EN)
|
|
223
211
|
return Number(string.replaceAll(",", ""));
|
|
224
|
-
}
|
|
225
212
|
return value;
|
|
226
213
|
}
|
|
227
214
|
|
|
@@ -230,9 +217,8 @@ function UiComponentsResolver(options = {}) {
|
|
|
230
217
|
return (name) => {
|
|
231
218
|
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
232
219
|
const isUiComponent = componentName.startsWith("Ui");
|
|
233
|
-
if (isUiComponent)
|
|
220
|
+
if (isUiComponent)
|
|
234
221
|
return { name: componentName, from: "@karta.io/ui-components" };
|
|
235
|
-
}
|
|
236
222
|
};
|
|
237
223
|
}
|
|
238
224
|
|
|
@@ -240,9 +226,8 @@ function useAbortController(callback) {
|
|
|
240
226
|
let controller = null;
|
|
241
227
|
return {
|
|
242
228
|
async call(...args) {
|
|
243
|
-
if (controller)
|
|
229
|
+
if (controller)
|
|
244
230
|
controller.abort();
|
|
245
|
-
}
|
|
246
231
|
controller = new AbortController();
|
|
247
232
|
let response;
|
|
248
233
|
if (args.length > 0) {
|
|
@@ -282,11 +267,7 @@ function useAsyncMultiselect({
|
|
|
282
267
|
const page = ref(1);
|
|
283
268
|
const options = computed(() => [...items.value.values()]);
|
|
284
269
|
const hasNextPage = computed(() => count.value > items.value.size);
|
|
285
|
-
const {
|
|
286
|
-
call: apiMethodWAC,
|
|
287
|
-
abort,
|
|
288
|
-
isAborted
|
|
289
|
-
} = useAbortController(apiMethod);
|
|
270
|
+
const { call: apiMethodWAC, abort, isAborted } = useAbortController(apiMethod);
|
|
290
271
|
const handleSearch = async (value) => {
|
|
291
272
|
if (search.value === value)
|
|
292
273
|
return;
|
|
@@ -304,12 +285,10 @@ function useAsyncMultiselect({
|
|
|
304
285
|
});
|
|
305
286
|
count.value = itemsCount;
|
|
306
287
|
if (isSearch) {
|
|
307
|
-
const cashedMapItems = selectedValues.value.map(
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
]
|
|
312
|
-
);
|
|
288
|
+
const cashedMapItems = selectedValues.value.map((selectedValue) => [
|
|
289
|
+
selectedValue,
|
|
290
|
+
items.value.get(selectedValue)
|
|
291
|
+
]);
|
|
313
292
|
items.value = new Map([...cashedMapItems]);
|
|
314
293
|
}
|
|
315
294
|
const resultsForMap = results.map(mapResultCallback);
|
|
@@ -353,11 +332,7 @@ function useAsyncSelect({
|
|
|
353
332
|
const page = ref(1);
|
|
354
333
|
const options = computed(() => [...items.value.values()]);
|
|
355
334
|
const hasNextPage = computed(() => count.value > items.value.size);
|
|
356
|
-
const {
|
|
357
|
-
call: apiMethodWAC,
|
|
358
|
-
abort,
|
|
359
|
-
isAborted
|
|
360
|
-
} = useAbortController(apiMethod);
|
|
335
|
+
const { call: apiMethodWAC, abort, isAborted } = useAbortController(apiMethod);
|
|
361
336
|
const handleSearch = async (value) => {
|
|
362
337
|
if (search.value === value)
|
|
363
338
|
return;
|
|
@@ -374,9 +349,8 @@ function useAsyncSelect({
|
|
|
374
349
|
...params
|
|
375
350
|
});
|
|
376
351
|
count.value = itemsCount;
|
|
377
|
-
if (isSearch)
|
|
352
|
+
if (isSearch)
|
|
378
353
|
items.value = /* @__PURE__ */ new Map();
|
|
379
|
-
}
|
|
380
354
|
const resultsForMap = results.map(mapResultCallback);
|
|
381
355
|
items.value = new Map([...items.value, ...resultsForMap]);
|
|
382
356
|
page.value += 1;
|
|
@@ -405,23 +379,19 @@ function useAsyncSelect({
|
|
|
405
379
|
};
|
|
406
380
|
}
|
|
407
381
|
|
|
408
|
-
|
|
382
|
+
function _bem(block, blockSuffix, element, modifier, modifierValue) {
|
|
409
383
|
let cls = block;
|
|
410
|
-
if (blockSuffix)
|
|
384
|
+
if (blockSuffix)
|
|
411
385
|
cls += `-${blockSuffix}`;
|
|
412
|
-
|
|
413
|
-
if (element) {
|
|
386
|
+
if (element)
|
|
414
387
|
cls += `__${element}`;
|
|
415
|
-
|
|
416
|
-
if (modifier) {
|
|
388
|
+
if (modifier)
|
|
417
389
|
cls += `_${modifier}`;
|
|
418
|
-
|
|
419
|
-
if (modifierValue) {
|
|
390
|
+
if (modifierValue)
|
|
420
391
|
cls += `_${modifierValue}`;
|
|
421
|
-
}
|
|
422
392
|
return cls;
|
|
423
|
-
}
|
|
424
|
-
|
|
393
|
+
}
|
|
394
|
+
function useClassName(block) {
|
|
425
395
|
const b = (blockSuffix = "") => _bem(block, blockSuffix, "", "", "");
|
|
426
396
|
const e = (element) => element ? _bem(block, "", element, "", "") : "";
|
|
427
397
|
const m = (modifier, condition = true) => modifier && condition ? _bem(block, "", "", modifier, "") : "";
|
|
@@ -429,9 +399,8 @@ const useClassName = (block) => {
|
|
|
429
399
|
const mv = (modifier, modifierValue, condition = true) => modifier && modifierValue && condition ? _bem(block, "", "", modifier, modifierValue) : "";
|
|
430
400
|
const cssVar = (object) => {
|
|
431
401
|
const styles = {};
|
|
432
|
-
for (const key in object)
|
|
402
|
+
for (const key in object)
|
|
433
403
|
styles[`--${block}-${key}`] = object[key];
|
|
434
|
-
}
|
|
435
404
|
return styles;
|
|
436
405
|
};
|
|
437
406
|
const cssVarName = (name) => `--${block}-${name}`;
|
|
@@ -445,7 +414,7 @@ const useClassName = (block) => {
|
|
|
445
414
|
cssVar,
|
|
446
415
|
cssVarName
|
|
447
416
|
};
|
|
448
|
-
}
|
|
417
|
+
}
|
|
449
418
|
|
|
450
419
|
dayjs.extend(utc);
|
|
451
420
|
dayjs.extend(tz);
|
|
@@ -456,21 +425,23 @@ function useDayjs(timezone) {
|
|
|
456
425
|
dayjs.updateLocale("en", {
|
|
457
426
|
weekStart: 1
|
|
458
427
|
});
|
|
459
|
-
if (!timezone)
|
|
428
|
+
if (!timezone)
|
|
460
429
|
return dayjs;
|
|
461
|
-
}
|
|
462
430
|
const dayjsExtended = (date, format, locale, strict) => dayjs(date, format, locale, strict).tz(timezone);
|
|
463
431
|
return dayjsExtended;
|
|
464
432
|
}
|
|
465
433
|
|
|
466
434
|
function parseVersion(version) {
|
|
467
435
|
if (typeof version !== "string" && typeof version !== "number") {
|
|
468
|
-
throw new TypeError(
|
|
469
|
-
"Browser version must be type of string, number or negative boolean"
|
|
470
|
-
);
|
|
436
|
+
throw new TypeError("Browser version must be type of string, number or negative boolean");
|
|
471
437
|
}
|
|
472
438
|
const [major, minor = 0, patch = 0, build = 0] = typeof version === "string" ? version.split(".").map(Number) : [version];
|
|
473
|
-
return {
|
|
439
|
+
return {
|
|
440
|
+
major,
|
|
441
|
+
minor,
|
|
442
|
+
patch,
|
|
443
|
+
build
|
|
444
|
+
};
|
|
474
445
|
}
|
|
475
446
|
function isVersionLower(minimum, target) {
|
|
476
447
|
for (const k of ["major", "minor", "patch"]) {
|
|
@@ -515,7 +486,7 @@ function isEnabled(options) {
|
|
|
515
486
|
}
|
|
516
487
|
const isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
517
488
|
if (isNode) {
|
|
518
|
-
const debug = process.env
|
|
489
|
+
const debug = process.env.NODE_DEBUG;
|
|
519
490
|
if (debug === "true")
|
|
520
491
|
return true;
|
|
521
492
|
if (debug === "false")
|
|
@@ -537,34 +508,48 @@ function validatePhone(rule, value) {
|
|
|
537
508
|
return phoneNumber ? phoneNumber.isValid() : false;
|
|
538
509
|
}
|
|
539
510
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
}
|
|
511
|
+
function isRequired(value = true, message = "This field is required") {
|
|
512
|
+
return {
|
|
513
|
+
required: value,
|
|
514
|
+
message
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
function isMax(value = 255, message) {
|
|
518
|
+
return {
|
|
519
|
+
max: value,
|
|
520
|
+
message: message ?? `Length must be no more than ${value} characters`
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
function isMin(value = 3, message) {
|
|
524
|
+
return {
|
|
525
|
+
min: value,
|
|
526
|
+
message: message ?? `Length must be at least ${value} characters`
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
function isTypeEmail(message = "Invalid format") {
|
|
530
|
+
return {
|
|
531
|
+
type: "email",
|
|
532
|
+
message
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
function isTypeUrl(message = "The url is invalid") {
|
|
536
|
+
return {
|
|
537
|
+
type: "url",
|
|
538
|
+
message
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
function isTypeNumber(value = 1, message) {
|
|
542
|
+
return {
|
|
543
|
+
type: "number",
|
|
544
|
+
min: value,
|
|
545
|
+
message: message ?? `Must be at least ${value}`
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
function isStrictLength(value = 3, message) {
|
|
549
|
+
return {
|
|
550
|
+
len: value,
|
|
551
|
+
message: message ?? `Length must be exactly ${value} characters`
|
|
552
|
+
};
|
|
553
|
+
}
|
|
569
554
|
|
|
570
555
|
export { UiComponentsResolver, camelizeKeys, createClassName, formatMoney, genLoadingTableRows, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, isElementIgnored, isEmptyObject, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncMultiselect, useAsyncSelect, useClassName, useDayjs, useDetectBrowser, useLogger, validateNumber, validatePhone };
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karta.io/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0-alpha.1",
|
|
4
4
|
"description": "karta.io utils for admin and application",
|
|
5
5
|
"author": "Vitaly Blokhin <karambafe@gmail.com>",
|
|
6
6
|
"homepage": "",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"sideEffects": false,
|
|
9
|
+
"type": "module",
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
11
12
|
"require": "./dist/index.cjs",
|
|
@@ -20,34 +21,36 @@
|
|
|
20
21
|
"dist"
|
|
21
22
|
],
|
|
22
23
|
"peerDependencies": {
|
|
23
|
-
"vue": "3.
|
|
24
|
+
"vue": "3.3.x"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
|
-
"@karta.io/common-data": "^0.
|
|
27
|
+
"@karta.io/common-data": "^0.34.0-alpha.1",
|
|
27
28
|
"@vueuse/core": "9.13.0",
|
|
28
29
|
"async-validator": "4.2.5",
|
|
29
|
-
"dayjs": "1.11.
|
|
30
|
+
"dayjs": "1.11.8",
|
|
30
31
|
"detect-browser": "5.3.0",
|
|
31
|
-
"libphonenumber-js": "1.
|
|
32
|
+
"libphonenumber-js": "1.10.36",
|
|
32
33
|
"lodash": "4.17.21",
|
|
33
34
|
"logdown": "3.3.1"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@qvant/prettier-config": "0.1.0",
|
|
37
|
-
"eslint": "
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "5.60.1",
|
|
39
|
+
"@typescript-eslint/parser": "5.60.1",
|
|
40
|
+
"eslint": "8.43.0",
|
|
38
41
|
"eslint-config-airbnb-base": "15.0.0",
|
|
39
|
-
"eslint-plugin-import": "2.
|
|
40
|
-
"prettier": "2.8.
|
|
41
|
-
"typescript": "
|
|
42
|
-
"unbuild": "1.
|
|
43
|
-
"vitest": "0.
|
|
44
|
-
"vue": "3.
|
|
42
|
+
"eslint-plugin-import": "2.27.5",
|
|
43
|
+
"prettier": "2.8.8",
|
|
44
|
+
"typescript": "5.0.4",
|
|
45
|
+
"unbuild": "1.2.1",
|
|
46
|
+
"vitest": "0.32.2",
|
|
47
|
+
"vue": "3.3.4"
|
|
45
48
|
},
|
|
46
49
|
"scripts": {
|
|
47
50
|
"dev": "vitest",
|
|
48
51
|
"build": "unbuild",
|
|
49
|
-
"lint": "eslint \"**/*.{ts,js}\"
|
|
50
|
-
"lint:fix": "eslint --fix \"**/*.{ts,js}\"
|
|
52
|
+
"lint": "eslint \"**/*.{ts,js}\"",
|
|
53
|
+
"lint:fix": "eslint --fix \"**/*.{ts,js}\"",
|
|
51
54
|
"test": "pnpm lint && vitest run",
|
|
52
55
|
"prettier": "prettier --check --ignore-unknown \"**/*\"",
|
|
53
56
|
"prettier:fix": "prettier --write --ignore-unknown \"**/*\"",
|