@karta.io/utils 1.0.0-beta.18 → 1.0.0-beta.2

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.mjs CHANGED
@@ -24,16 +24,14 @@ function AppComponentsResolver(options = {}) {
24
24
  return (name) => {
25
25
  const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
26
26
  const isAppComponent = componentName.startsWith("App");
27
- if (isAppComponent) {
27
+ if (isAppComponent)
28
28
  return { name: componentName, from: "@karta.io/app-components" };
29
- }
30
29
  };
31
30
  }
32
31
 
33
32
  function camelizeKeys(object) {
34
- if (Array.isArray(object)) {
33
+ if (Array.isArray(object))
35
34
  return object.map((v) => camelizeKeys(v));
36
- }
37
35
  if (object !== null && object.constructor === Object) {
38
36
  return Object.keys(object).reduce(
39
37
  (result, key) => ({
@@ -77,7 +75,7 @@ function formatMoney(value, currency = CURRENCY_DEFAULT, options = {}) {
77
75
  ...otherOptions
78
76
  });
79
77
  return formatter.format(convertedValue);
80
- } catch (_error) {
78
+ } catch (error) {
81
79
  return defaultValue;
82
80
  }
83
81
  }
@@ -107,7 +105,7 @@ function genUUID() {
107
105
  r = (d2 + r) % 16 | 0;
108
106
  d2 = Math.floor(d2 / 16);
109
107
  }
110
- return (c === "x" ? r : r & 7 | 8).toString(16);
108
+ return (c == "x" ? r : r & 7 | 8).toString(16);
111
109
  });
112
110
  }
113
111
 
@@ -187,9 +185,7 @@ function getPaginationParams({
187
185
  offset: validatedPage * validatedLimit - validatedLimit
188
186
  };
189
187
  }
190
- function getPaginationLimit({
191
- limit
192
- }) {
188
+ function getPaginationLimit({ limit }) {
193
189
  return validateNumber(limit, LIMIT_DEFAULT);
194
190
  }
195
191
  function getPaginationOffset({
@@ -211,17 +207,15 @@ function parsePhone(phone) {
211
207
  if (!phone || typeof phone !== "string")
212
208
  return "";
213
209
  const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
214
- if (replacedPhone.length === 1 && replacedPhone !== "+") {
210
+ if (replacedPhone.length === 1 && replacedPhone !== "+")
215
211
  return `+${replacedPhone}`;
216
- }
217
212
  const phoneNumber = parsePhoneNumberFromString(replacedPhone);
218
213
  return phoneNumber ? phoneNumber.formatInternational() : replacedPhone;
219
214
  }
220
215
 
221
216
  function snakelizeKeys(prop) {
222
- if (Array.isArray(prop)) {
217
+ if (Array.isArray(prop))
223
218
  return prop.map((item) => snakelizeKeys(item));
224
- }
225
219
  if (prop !== null && prop !== void 0 && prop.constructor === Object) {
226
220
  return Object.keys(prop).reduce(
227
221
  (accum, current) => ({
@@ -261,9 +255,8 @@ function unformatNumber(value) {
261
255
  if (commasCount === 1 && !hasSpace && !hasDot) {
262
256
  locale = string.length - 1 - commaIndex === 3 ? LOCALE_EN : LOCALE_RU;
263
257
  }
264
- if (locale === LOCALE_RU) {
258
+ if (locale === LOCALE_RU)
265
259
  return Number(string.replaceAll(" ", "").replace(",", "."));
266
- }
267
260
  if (locale === LOCALE_EN)
268
261
  return Number(string.replaceAll(",", ""));
269
262
  return value;
@@ -274,9 +267,8 @@ function UiComponentsResolver(options = {}) {
274
267
  return (name) => {
275
268
  const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
276
269
  const isUiComponent = componentName.startsWith("Ui");
277
- if (isUiComponent) {
270
+ if (isUiComponent)
278
271
  return { name: componentName, from: "@karta.io/ui-components" };
279
- }
280
272
  };
281
273
  }
282
274
 
@@ -324,9 +316,7 @@ function useAsyncItems({
324
316
  queryKey: getQueryKey(),
325
317
  queryFn: () => call(toValue(params), config)
326
318
  });
327
- const items = computed(
328
- () => data.value?.results || []
329
- );
319
+ const items = computed(() => data.value?.results || []);
330
320
  const count = ref(0);
331
321
  watch(
332
322
  data,
@@ -403,12 +393,7 @@ function useAsyncMultiselect({
403
393
  color: "#b54708",
404
394
  debug: true
405
395
  });
406
- const paramsForLogger = {
407
- queryKey,
408
- dataItemsKey,
409
- dataItemIdKey,
410
- dataCountKey
411
- };
396
+ const paramsForLogger = { queryKey, dataItemsKey, dataItemIdKey, dataCountKey };
412
397
  const reactiveData = reactive({
413
398
  search: "",
414
399
  page: 1,
@@ -454,9 +439,8 @@ function useAsyncMultiselect({
454
439
  );
455
440
  return;
456
441
  }
457
- if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0) {
442
+ if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0)
458
443
  return;
459
- }
460
444
  count.value = get(newValue, dataCountKey, 0);
461
445
  const newItems = get(newValue, dataItemsKey);
462
446
  itemsByPages.value = {
@@ -487,9 +471,8 @@ function useAsyncMultiselect({
487
471
  const items = computed(() => {
488
472
  if (!itemsByPages.value)
489
473
  return selectedItemsCached.value;
490
- if (!Object.keys(itemsByPages.value).length) {
474
+ if (!Object.keys(itemsByPages.value).length)
491
475
  return selectedItemsCached.value;
492
- }
493
476
  const itemsByPagesAsArray = Object.values(itemsByPages.value).reduce(
494
477
  (acc, item) => [...acc, ...item],
495
478
  []
@@ -505,7 +488,7 @@ function useAsyncMultiselect({
505
488
  if (!items.value.length)
506
489
  return [];
507
490
  if (!mapOptionCallback)
508
- return items.value;
491
+ return this.items.value;
509
492
  return items.value.map(mapOptionCallback);
510
493
  });
511
494
  const hasNextPage = computed(() => count.value > items.value.length);
@@ -524,28 +507,6 @@ function useAsyncMultiselect({
524
507
  search.value = value;
525
508
  updateSearchWithDebounce(value);
526
509
  };
527
- const queryClient = useQueryClient();
528
- const refetch = () => {
529
- if (reactiveData.page !== 1) {
530
- queryClient.invalidateQueries({
531
- queryKey: [queryKey],
532
- refetchType: "none"
533
- });
534
- loadPage(1);
535
- } else {
536
- queryClient.invalidateQueries({
537
- queryKey: [queryKey]
538
- });
539
- }
540
- };
541
- const reload = () => {
542
- if (reactiveData.page !== 1) {
543
- queryClient.removeQueries({ queryKey: [queryKey] });
544
- loadPage(1);
545
- } else {
546
- queryClient.resetQueries({ queryKey: [queryKey] });
547
- }
548
- };
549
510
  if (isRef(selectedValues)) {
550
511
  watch(selectedValues, async (newSelectedValues) => {
551
512
  if (!newSelectedValues.length) {
@@ -586,9 +547,7 @@ function useAsyncMultiselect({
586
547
  isFetching,
587
548
  isLoading,
588
549
  loadPage,
589
- updateSearch,
590
- refetch,
591
- reload
550
+ updateSearch
592
551
  };
593
552
  }
594
553
 
@@ -620,9 +579,7 @@ function useAsyncSelect({
620
579
  const loadWAC = () => call({
621
580
  page: reactiveData.page,
622
581
  search: reactiveData.search,
623
- ...reactiveData.selectedValue && {
624
- includedIds: [reactiveData.selectedValue]
625
- },
582
+ ...reactiveData.selectedValue && { includedIds: [reactiveData.selectedValue] },
626
583
  ...reactiveData.params && { ...JSON.parse(reactiveData.params) }
627
584
  });
628
585
  const { data, isFetching, isLoading } = useQuery({
@@ -650,9 +607,8 @@ function useAsyncSelect({
650
607
  );
651
608
  return;
652
609
  }
653
- if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0) {
610
+ if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0)
654
611
  return;
655
- }
656
612
  count.value = get(newValue, dataCountKey, 0);
657
613
  const newItems = get(newValue, dataItemsKey);
658
614
  itemsByPages.value = {
@@ -682,7 +638,7 @@ function useAsyncSelect({
682
638
  if (!items.value.length)
683
639
  return [];
684
640
  if (!mapOptionCallback)
685
- return items.value;
641
+ return this.items.value;
686
642
  return items.value.map(mapOptionCallback);
687
643
  });
688
644
  const hasNextPage = computed(() => count.value > items.value.length);
@@ -697,28 +653,6 @@ function useAsyncSelect({
697
653
  search.value = value;
698
654
  updateSearchWithDebounce(value);
699
655
  };
700
- const queryClient = useQueryClient();
701
- const refetch = () => {
702
- if (reactiveData.page !== 1) {
703
- queryClient.invalidateQueries({
704
- queryKey: [queryKey],
705
- refetchType: "none"
706
- });
707
- loadPage(1);
708
- } else {
709
- queryClient.invalidateQueries({
710
- queryKey: [queryKey]
711
- });
712
- }
713
- };
714
- const reload = () => {
715
- if (reactiveData.page !== 1) {
716
- queryClient.removeQueries({ queryKey: [queryKey] });
717
- loadPage(1);
718
- } else {
719
- queryClient.resetQueries({ queryKey: [queryKey] });
720
- }
721
- };
722
656
  if (isRef(selectedValue)) {
723
657
  watch(selectedValue, (newSelectedValue) => {
724
658
  reactiveData.page = 1;
@@ -742,9 +676,7 @@ function useAsyncSelect({
742
676
  isFetching,
743
677
  isLoading,
744
678
  loadPage,
745
- updateSearch,
746
- refetch,
747
- reload
679
+ updateSearch
748
680
  };
749
681
  }
750
682
 
@@ -824,9 +756,7 @@ function useDayjs(timezone) {
824
756
 
825
757
  function parseVersion(version) {
826
758
  if (typeof version !== "string" && typeof version !== "number") {
827
- throw new TypeError(
828
- "Browser version must be type of string, number or negative boolean"
829
- );
759
+ throw new TypeError("Browser version must be type of string, number or negative boolean");
830
760
  }
831
761
  const [major, minor = 0, patch = 0, build = 0] = typeof version === "string" ? version.split(".").map(Number) : [version];
832
762
  return {
@@ -906,7 +836,7 @@ function useDialog() {
906
836
  let dataFromHash;
907
837
  try {
908
838
  dataFromHash = JSON.parse(window.atob(hash.slice(HASH_PREFIX.length)));
909
- } catch (_error) {
839
+ } catch (error) {
910
840
  logger.warn("*parseHash* cant parse hash");
911
841
  }
912
842
  if (typeof dataFromHash !== "object")
@@ -1126,7 +1056,10 @@ const QS_STRINGIFY_PARAMS = {
1126
1056
  addQueryPrefix: true
1127
1057
  };
1128
1058
  const isOpen = ref(false);
1129
- function useFilters({ config, initialFilters }) {
1059
+ function useFilters({
1060
+ config,
1061
+ initialFilters
1062
+ }) {
1130
1063
  const router = useRouter();
1131
1064
  const route = useRoute();
1132
1065
  const parseRouteQuery = (query) => qs.parse(query ?? route.query);
@@ -1134,43 +1067,35 @@ function useFilters({ config, initialFilters }) {
1134
1067
  const parsedRouteQuery = parseRouteQuery();
1135
1068
  if (!parsedRouteQuery.filters)
1136
1069
  return void 0;
1137
- return Object.entries(config).reduce(
1138
- (accum, [currentKey, currentValue]) => {
1139
- if (!parsedRouteQuery.filters[currentKey])
1070
+ return Object.entries(config).reduce((accum, [currentKey, currentValue]) => {
1071
+ if (!parsedRouteQuery.filters[currentKey])
1072
+ return accum;
1073
+ if (currentValue.type === "ARRAY" /* Array */) {
1074
+ const splitValues = parsedRouteQuery.filters[currentKey].split(",");
1075
+ const checkedValue = currentValue?.possibleValues ? splitValues.filter((k) => currentValue?.possibleValues?.includes(k)) : splitValues;
1076
+ if (!checkedValue?.length)
1140
1077
  return accum;
1141
- if (currentValue.type === "ARRAY" /* Array */) {
1142
- const splitValues = parsedRouteQuery.filters[currentKey].split(",");
1143
- const checkedValue = currentValue?.possibleValues ? splitValues.filter(
1144
- (k) => currentValue?.possibleValues?.includes(k)
1145
- ) : splitValues;
1146
- if (!checkedValue?.length)
1147
- return accum;
1148
- return {
1149
- ...accum,
1150
- [currentKey]: checkedValue
1151
- };
1152
- }
1153
1078
  return {
1154
1079
  ...accum,
1155
- [currentKey]: parsedRouteQuery.filters[currentKey]
1080
+ [currentKey]: checkedValue
1156
1081
  };
1157
- },
1158
- {}
1159
- );
1082
+ }
1083
+ return {
1084
+ ...accum,
1085
+ [currentKey]: parsedRouteQuery.filters[currentKey]
1086
+ };
1087
+ }, {});
1160
1088
  });
1161
1089
  const filtersCount = computed(
1162
1090
  () => filtersFromQuery.value ? Object.keys(filtersFromQuery.value).length : 0
1163
1091
  );
1164
1092
  const setQueryFromFilters = (filters) => {
1165
1093
  const parsedRouteQuery = parseRouteQuery();
1166
- const filteredValue = Object.entries(filters).reduce(
1167
- (accum, [currentKey, currentValue]) => {
1168
- if (!currentValue?.length)
1169
- return accum;
1170
- return { ...accum, [currentKey]: currentValue };
1171
- },
1172
- {}
1173
- );
1094
+ const filteredValue = Object.entries(filters).reduce((accum, [currentKey, currentValue]) => {
1095
+ if (!currentValue?.length)
1096
+ return accum;
1097
+ return { ...accum, [currentKey]: currentValue };
1098
+ }, {});
1174
1099
  const query = qs.stringify(
1175
1100
  {
1176
1101
  ...parsedRouteQuery,
@@ -1207,15 +1132,12 @@ function useFilters({ config, initialFilters }) {
1207
1132
  });
1208
1133
  };
1209
1134
  const updateMany = (filters) => {
1210
- const newFilters = Object.entries(filters).reduce(
1211
- (accum, [currentKey, currentValue]) => {
1212
- return {
1213
- ...accum,
1214
- [currentKey]: currentValue ? String(currentValue) : void 0
1215
- };
1216
- },
1217
- {}
1218
- );
1135
+ const newFilters = Object.entries(filters).reduce((accum, [currentKey, currentValue]) => {
1136
+ return {
1137
+ ...accum,
1138
+ [currentKey]: currentValue ? String(currentValue) : void 0
1139
+ };
1140
+ }, {});
1219
1141
  setQueryFromFilters({
1220
1142
  ...filtersModel.value,
1221
1143
  ...newFilters
@@ -1391,7 +1313,7 @@ function usePanel() {
1391
1313
  let dataFromHash;
1392
1314
  try {
1393
1315
  dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
1394
- } catch (_error) {
1316
+ } catch (error) {
1395
1317
  logger.error("*watchHash* cant parse hash");
1396
1318
  }
1397
1319
  if (typeof dataFromHash !== "object")
package/package.json CHANGED
@@ -1,60 +1,61 @@
1
1
  {
2
2
  "name": "@karta.io/utils",
3
- "version": "1.0.0-beta.18",
3
+ "version": "1.0.0-beta.2",
4
4
  "description": "karta.io utils for admin and application",
5
- "type": "module",
6
- "license": "MIT",
7
- "homepage": "",
8
5
  "author": "Vitaly Blokhin <karambafe@gmail.com>",
9
- "files": [
10
- "dist"
11
- ],
12
- "main": "./dist/index.cjs",
13
- "module": "./dist/index.mjs",
14
- "types": "./dist/index.d.ts",
6
+ "homepage": "",
7
+ "license": "MIT",
8
+ "sideEffects": false,
9
+ "type": "module",
15
10
  "exports": {
16
11
  ".": {
17
- "types": "./dist/index.d.ts",
18
12
  "require": "./dist/index.cjs",
19
13
  "import": "./dist/index.mjs"
20
14
  },
21
15
  "./*": "./*"
22
16
  },
23
- "sideEffects": false,
17
+ "main": "./dist/index.cjs",
18
+ "module": "./dist/index.mjs",
19
+ "types": "./dist/index.d.ts",
20
+ "files": [
21
+ "dist"
22
+ ],
24
23
  "peerDependencies": {
25
- "vue": "3.x"
24
+ "vue": "3.3.x"
26
25
  },
27
26
  "dependencies": {
28
- "@karta.io/common-data": "^1.0.0-beta.18",
29
- "@tanstack/vue-query": "5.36.0",
30
- "@vueuse/core": "10.9.0",
27
+ "@karta.io/common-data": "^1.0.0-beta.2",
28
+ "@tanstack/vue-query": "4.33.1",
29
+ "@vueuse/core": "10.7.0",
31
30
  "async-validator": "4.2.5",
32
- "axios": "1.6.8",
33
- "dayjs": "1.11.11",
31
+ "axios": "1.4.0",
32
+ "dayjs": "1.11.8",
34
33
  "detect-browser": "5.3.0",
35
- "libphonenumber-js": "1.11.1",
34
+ "libphonenumber-js": "1.10.36",
36
35
  "lodash": "4.17.21",
37
36
  "logdown": "3.3.1",
38
- "qs": "6.12.1",
39
- "vue-router": "4.3.2"
37
+ "qs": "6.11.2",
38
+ "vue-router": "4.x.x"
40
39
  },
41
40
  "devDependencies": {
42
- "@karta.io/eslint-config": "1.1.0",
43
- "@karta.io/prettier-config": "1.0.0",
44
- "@types/lodash": "4.17.1",
45
- "eslint": "9.2.0",
46
- "prettier": "3.2.5",
47
- "typescript": "5.4.5",
48
- "unbuild": "2.0.0",
49
- "vitest": "1.2.2",
50
- "vue": "3.4.27"
41
+ "@qvant/prettier-config": "0.1.0",
42
+ "@types/lodash": "4.14.195",
43
+ "@typescript-eslint/eslint-plugin": "5.60.1",
44
+ "@typescript-eslint/parser": "5.60.1",
45
+ "eslint": "8.43.0",
46
+ "eslint-config-airbnb-base": "15.0.0",
47
+ "eslint-plugin-import": "2.27.5",
48
+ "prettier": "3.0.1",
49
+ "typescript": "5.1.6",
50
+ "unbuild": "1.2.1",
51
+ "vitest": "0.32.2",
52
+ "vue": "3.3.4"
51
53
  },
52
- "prettier": "@karta.io/prettier-config",
53
54
  "scripts": {
54
55
  "dev": "vitest",
55
56
  "build": "unbuild",
56
- "lint": "eslint .",
57
- "lint:fix": "eslint . --fix",
57
+ "lint": "eslint \"**/*.{ts,js}\"",
58
+ "lint:fix": "eslint --fix \"**/*.{ts,js}\"",
58
59
  "test": "pnpm lint && vitest run",
59
60
  "prettier": "prettier --check --ignore-unknown \"**/*\"",
60
61
  "prettier:fix": "prettier --write --ignore-unknown \"**/*\"",