@karta.io/utils 1.0.0-beta.50 → 1.0.0-beta.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/helpers/appComponentsResolver.d.ts +5 -0
  2. package/dist/helpers/camelizeKeys.d.ts +2 -0
  3. package/dist/helpers/convertEnumToOptions.d.ts +8 -0
  4. package/dist/helpers/enrichError.d.ts +8 -0
  5. package/dist/helpers/formatError.d.ts +7 -0
  6. package/dist/helpers/formatMoney.d.ts +6 -0
  7. package/dist/helpers/genHash.d.ts +1 -0
  8. package/dist/helpers/genRandomNumber.d.ts +1 -0
  9. package/dist/helpers/genUUID.d.ts +1 -0
  10. package/dist/helpers/getCardNumber.d.ts +7 -0
  11. package/dist/helpers/getCountryFromPhone.d.ts +1 -0
  12. package/dist/helpers/isElementIgnored.d.ts +4 -0
  13. package/dist/helpers/isEmptyObject.d.ts +1 -0
  14. package/dist/helpers/isHtml.d.ts +1 -0
  15. package/dist/helpers/mapDataObjectForFilters.d.ts +10 -0
  16. package/dist/helpers/pagination.d.ts +18 -0
  17. package/dist/helpers/parsePhone.d.ts +1 -0
  18. package/dist/helpers/snakelizeKeys.d.ts +3 -0
  19. package/dist/helpers/uiComponentsResolver.d.ts +5 -0
  20. package/dist/helpers/unformatNumber.d.ts +19 -0
  21. package/dist/helpers/validateNumber.d.ts +1 -0
  22. package/dist/hooks/useAbortController.d.ts +6 -0
  23. package/dist/hooks/useAsyncItems.d.ts +19 -0
  24. package/dist/hooks/useAsyncMultiselect.d.ts +31 -0
  25. package/dist/hooks/useAsyncSelect.d.ts +30 -0
  26. package/dist/hooks/useBreakpoint.d.ts +11 -0
  27. package/dist/hooks/useClassName.d.ts +9 -0
  28. package/dist/hooks/useDayjs.d.ts +10 -0
  29. package/dist/hooks/useDetectBrowser.d.ts +13 -0
  30. package/dist/hooks/useDialog.d.ts +48 -0
  31. package/dist/hooks/useFilters.d.ts +22 -0
  32. package/dist/hooks/useGlobalScroll.d.ts +6 -0
  33. package/dist/hooks/useLogger.d.ts +8 -0
  34. package/dist/hooks/usePanel.d.ts +27 -0
  35. package/dist/index.cjs +1587 -1496
  36. package/dist/index.d.ts +37 -394
  37. package/dist/index.mjs +1543 -1471
  38. package/dist/types.d.ts +11 -0
  39. package/dist/validator/formRules.d.ts +14 -0
  40. package/dist/validator/validatePhone.d.ts +1 -0
  41. package/package.json +23 -25
  42. package/dist/index.d.cts +0 -394
  43. package/dist/index.d.mts +0 -394
@@ -0,0 +1,5 @@
1
+ interface AppComponentsResolverOptions {
2
+ prefix?: string;
3
+ }
4
+ export declare function AppComponentsResolver(options?: AppComponentsResolverOptions): any;
5
+ export {};
@@ -0,0 +1,2 @@
1
+ import { Dictionary } from '../types';
2
+ export declare function camelizeKeys<T extends Record<string, any> = Dictionary>(object: Dictionary): T;
@@ -0,0 +1,8 @@
1
+ interface Options {
2
+ labelType: 'key' | 'value';
3
+ }
4
+ export declare function convertEnumToOptions(obj: any, options?: Options): {
5
+ value: unknown;
6
+ label: unknown;
7
+ }[];
8
+ export {};
@@ -0,0 +1,8 @@
1
+ interface EnrichErrorParams {
2
+ message: string;
3
+ [key: string]: any;
4
+ }
5
+ export declare class EnrichError extends Error {
6
+ constructor(data: EnrichErrorParams);
7
+ }
8
+ export {};
@@ -0,0 +1,7 @@
1
+ import { ResponseError } from '../types';
2
+ export declare function getStatusMessage(status: number): string;
3
+ export declare function formatErrorDataMessage(data?: Record<string, string | string[]>): string;
4
+ export declare function formatErrorForNotify(error: Error | ResponseError | any): {
5
+ title: string;
6
+ message: any;
7
+ };
@@ -0,0 +1,6 @@
1
+ interface Options extends Intl.NumberFormatOptions {
2
+ locale?: string;
3
+ defaultValue?: string | number;
4
+ }
5
+ export declare function formatMoney(value: string | number | null | undefined, currency?: string, options?: Options): string | number;
6
+ export {};
@@ -0,0 +1 @@
1
+ export declare function genHash(hashLength: number): string;
@@ -0,0 +1 @@
1
+ export declare function genRandomNumber(min: number, max: number): number;
@@ -0,0 +1 @@
1
+ export declare function genUUID(): string;
@@ -0,0 +1,7 @@
1
+ interface Options {
2
+ hasOnlyLast4: boolean;
3
+ isHidden: boolean;
4
+ dot: string;
5
+ }
6
+ export declare function getCardNumber(number: string, options?: Partial<Options>): string;
7
+ export {};
@@ -0,0 +1 @@
1
+ export declare function getCountryFromPhone(phone: string): string;
@@ -0,0 +1,4 @@
1
+ export declare function isElementIgnored({ ignoredClasses, event, }?: {
2
+ ignoredClasses?: string[];
3
+ event?: Event;
4
+ }): boolean;
@@ -0,0 +1 @@
1
+ export declare function isEmptyObject(object: object): boolean;
@@ -0,0 +1 @@
1
+ export declare function isHtml(data: string): boolean;
@@ -0,0 +1,10 @@
1
+ interface MapOptions {
2
+ labelKey?: string;
3
+ valueKey?: string;
4
+ excludedItems?: any[];
5
+ }
6
+ export declare function mapDataObjectForFilters<T extends Record<string, any>>(data: T, options?: MapOptions): {
7
+ label: string;
8
+ value: any;
9
+ }[];
10
+ export {};
@@ -0,0 +1,18 @@
1
+ export declare function getPaginationParams({ page, limit, }: {
2
+ page: string | number;
3
+ limit: string | number;
4
+ }): {
5
+ limit: number;
6
+ offset: number;
7
+ };
8
+ export declare function getPaginationLimit({ limit, }: {
9
+ limit: string | number;
10
+ }): number;
11
+ export declare function getPaginationOffset({ page, limit, }: {
12
+ page: string | number;
13
+ limit: string | number;
14
+ }): number;
15
+ export declare function getPaginationPages({ count, limit, }: {
16
+ count: number;
17
+ limit: string | number;
18
+ }): number;
@@ -0,0 +1 @@
1
+ export declare function parsePhone(phone: string | null | undefined): string;
@@ -0,0 +1,3 @@
1
+ type SnakelizeKeysProp = Record<string | number, any>;
2
+ export declare function snakelizeKeys<T extends Record<string, any> = SnakelizeKeysProp>(prop: SnakelizeKeysProp): T;
3
+ export {};
@@ -0,0 +1,5 @@
1
+ interface UiComponentsResolverOptions {
2
+ prefix?: string;
3
+ }
4
+ export declare function UiComponentsResolver(options?: UiComponentsResolverOptions): any;
5
+ export {};
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Принимает на вход число в виде строки или числа,
3
+ * возвращает корректное значение типа Number (убирает лишние пробелы и запятые)
4
+ * @example
5
+ * // returns 1000
6
+ * unformatNumber('1 000');
7
+ * @example
8
+ * // returns 1000
9
+ * unformatNumber('1,000')
10
+ * @example
11
+ * // returns 1000.123
12
+ * unformatNummber('1 000,123')
13
+ * @example
14
+ * // returns 1000.123
15
+ * unformatNummber('1,000.123')
16
+ * @param value
17
+ * @return number
18
+ */
19
+ export declare function unformatNumber(value: string | number): string | number;
@@ -0,0 +1 @@
1
+ export declare function validateNumber(value: string | number, defaultValue: number): number;
@@ -0,0 +1,6 @@
1
+ import { ResponseError } from '../types';
2
+ export declare function useAbortController<T extends (...args: any[]) => any>(callback: T): {
3
+ call(...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
4
+ abort(): void;
5
+ isAborted(error: ResponseError): boolean;
6
+ };
@@ -0,0 +1,19 @@
1
+ import { MaybeRef, Ref, ComputedRef } from 'vue';
2
+ import { HttpRequestConfig } from '../types';
3
+ export declare function useAsyncItems<T extends (...args: any[]) => any>({ apiMethod, queryKey, params, config, }: {
4
+ apiMethod: T;
5
+ queryKey: string;
6
+ params: MaybeRef<Parameters<T>[0]>;
7
+ config?: HttpRequestConfig;
8
+ }): {
9
+ isLoading: Ref<false, false> | Ref<true, true> | Ref<boolean, boolean>;
10
+ isFetching: Ref<boolean, boolean>;
11
+ isError: Ref<false, false> | Ref<true, true>;
12
+ data: Ref<any, any> | Ref<undefined, undefined>;
13
+ error: Ref<Error, Error> | Ref<null, null>;
14
+ items: ComputedRef<Awaited<ReturnType<T>>["results"]>;
15
+ count: Ref<number, number>;
16
+ refetch: () => void;
17
+ reload: () => void;
18
+ abort: () => void;
19
+ };
@@ -0,0 +1,31 @@
1
+ import { MaybeRef, ComputedRef, Ref } from 'vue';
2
+ interface ReactiveData {
3
+ search: string;
4
+ page: number;
5
+ selectedValues?: any[];
6
+ params?: any;
7
+ }
8
+ export declare function useAsyncMultiselect<T extends (...args: any[]) => any, K extends (params: any) => any>({ apiMethod, mapOptionCallback, selectedValues, params, queryKey, dataItemsKey, dataItemIdKey, dataCountKey, delay, onUpdated, }: {
9
+ apiMethod: T;
10
+ mapOptionCallback?: K;
11
+ selectedValues?: MaybeRef<Parameters<T>[0]['includedIds']>;
12
+ params?: MaybeRef<Partial<Parameters<T>[0]>>;
13
+ queryKey: string;
14
+ dataItemsKey?: string;
15
+ dataItemIdKey?: string;
16
+ dataCountKey?: string;
17
+ delay?: number;
18
+ onUpdated?: (data: ReactiveData) => void;
19
+ }): {
20
+ items: ComputedRef<any[]>;
21
+ options: ComputedRef<ReturnType<K>[]>;
22
+ search: Ref<string, string>;
23
+ hasNextPage: ComputedRef<boolean>;
24
+ isFetching: Ref<boolean, boolean>;
25
+ isLoading: Ref<false, false> | Ref<true, true> | Ref<boolean, boolean>;
26
+ loadPage: (newPage?: number) => void;
27
+ updateSearch: (value: string) => void;
28
+ refetch: () => void;
29
+ reload: () => void;
30
+ };
31
+ export {};
@@ -0,0 +1,30 @@
1
+ import { MaybeRef, ComputedRef, Ref } from 'vue';
2
+ interface ReactiveData {
3
+ search: string;
4
+ page: number;
5
+ selectedValue?: any[];
6
+ params?: any;
7
+ }
8
+ export declare function useAsyncSelect<T extends (...args: any[]) => any, K extends (params: any) => any>({ apiMethod, mapOptionCallback, selectedValue, params, queryKey, dataItemsKey, dataCountKey, delay, onUpdated, }: {
9
+ apiMethod: T;
10
+ mapOptionCallback?: K;
11
+ selectedValue?: MaybeRef<Parameters<T>[0]['includedIds']>;
12
+ params?: MaybeRef<Partial<Parameters<T>[0]>>;
13
+ queryKey: string;
14
+ dataItemsKey?: string;
15
+ dataCountKey?: string;
16
+ delay?: number;
17
+ onUpdated?: (data: ReactiveData) => void;
18
+ }): {
19
+ items: ComputedRef<any[]>;
20
+ options: ComputedRef<ReturnType<K>[]>;
21
+ search: Ref<string, string>;
22
+ hasNextPage: ComputedRef<boolean>;
23
+ isFetching: Ref<boolean, boolean>;
24
+ isLoading: Ref<false, false> | Ref<true, true> | Ref<boolean, boolean>;
25
+ loadPage: (newPage?: number) => void;
26
+ updateSearch: (value: string) => void;
27
+ refetch: () => void;
28
+ reload: () => void;
29
+ };
30
+ export {};
@@ -0,0 +1,11 @@
1
+ import { ComputedRef } from 'vue';
2
+ export declare function useBreakpoint(): {
3
+ isMobile: ComputedRef<boolean>;
4
+ isDesktop: ComputedRef<boolean>;
5
+ isGreaterXxs: ComputedRef<boolean>;
6
+ isGreaterXs: ComputedRef<boolean>;
7
+ isGreaterSm: ComputedRef<boolean>;
8
+ isGreaterMd: ComputedRef<boolean>;
9
+ isGreaterLg: ComputedRef<boolean>;
10
+ isGreaterXl: ComputedRef<boolean>;
11
+ };
@@ -0,0 +1,9 @@
1
+ export declare function useClassName(block: string): {
2
+ b: (blockSuffix?: string) => string;
3
+ e: (element?: string) => string;
4
+ m: (modifier?: string, condition?: boolean) => string;
5
+ em: (element?: string, modifier?: string, condition?: boolean) => string;
6
+ mv: (modifier: string, modifierValue: string, condition?: boolean) => string;
7
+ cssVar: (object: Record<string, string | number>) => Record<string, string | number>;
8
+ cssVarName: (name: string) => string;
9
+ };
@@ -0,0 +1,10 @@
1
+ import { default as dayjs } from 'dayjs';
2
+ /**
3
+ * Обертка над dayjs, позволяющая задавать timezone
4
+ * @see https://day.js.org/en/
5
+ *
6
+ * Использовать параметр timezone нужно крайне аккуратно,
7
+ * может привести к утечкам памяти
8
+ * @todo Подумать как сделать оптимальнее
9
+ */
10
+ export declare function useDayjs(timezone?: string): (date?: dayjs.ConfigType, format?: dayjs.OptionType, locale?: string, strict?: boolean) => dayjs.Dayjs;
@@ -0,0 +1,13 @@
1
+ import { Browser } from 'detect-browser';
2
+ export interface BrowserInfo {
3
+ isDeprecated?: boolean;
4
+ name?: string;
5
+ version?: string;
6
+ os?: string;
7
+ type?: string;
8
+ options?: any;
9
+ }
10
+ export type VersionsList = {
11
+ [key in Browser]?: string | boolean;
12
+ };
13
+ export declare function useDetectBrowser(versions: VersionsList, userAgent?: any): BrowserInfo;
@@ -0,0 +1,48 @@
1
+ import { Component, EmitsOptions, VNode } from 'vue';
2
+ interface VNodeCustom extends VNode {
3
+ close: () => void;
4
+ }
5
+ export interface Dialog {
6
+ uuid: string;
7
+ name?: string;
8
+ vnode: VNodeCustom;
9
+ layer: number;
10
+ }
11
+ export interface DialogOptions {
12
+ hashPrefix?: string;
13
+ }
14
+ export interface DialogParseHashResult {
15
+ name: string;
16
+ layer: number;
17
+ [key: string]: any;
18
+ }
19
+ export declare function useDialog(options?: DialogOptions): {
20
+ open: ({ layer, component, props, }: {
21
+ component: Component;
22
+ props?: any;
23
+ layer?: number;
24
+ }) => string;
25
+ getInstance: (uuid: string) => VNodeCustom;
26
+ getLayer: (uuid: string) => number;
27
+ close: (uuid: string) => void;
28
+ closeAll: () => void;
29
+ showConfirm: (text?: string) => boolean;
30
+ isOnTop: (uuid: string) => boolean;
31
+ genHash: ({ layer, componentName, props, }: {
32
+ componentName: string;
33
+ props?: any;
34
+ layer?: number;
35
+ }) => string;
36
+ parseHash: (hash: string, componentName: string) => DialogParseHashResult | undefined;
37
+ clearHash: () => void;
38
+ openByHash: ({ layer, component, props, }: {
39
+ component: Component;
40
+ props?: any;
41
+ layer?: number;
42
+ }) => void;
43
+ watchHash: ({ component, events, }: {
44
+ component: Component;
45
+ events?: EmitsOptions;
46
+ }) => any;
47
+ };
48
+ export {};
@@ -0,0 +1,22 @@
1
+ import { Ref, ComputedRef } from 'vue';
2
+ export declare function useFilters<T extends Record<string, any>, K extends Record<string, any>>({ config, initialFilters, delay, }: {
3
+ config: T;
4
+ initialFilters: K;
5
+ /**
6
+ * 0 — применять сразу, без задержки
7
+ */
8
+ delay?: number;
9
+ }): {
10
+ isOpen: Ref<boolean, boolean>;
11
+ filtersModel: Ref<K, K>;
12
+ filtersFromQuery: ComputedRef<{}>;
13
+ filtersCount: ComputedRef<number>;
14
+ updateOne: (key: keyof K, value: any) => void;
15
+ updateMany: (filters: Record<string, any>) => void;
16
+ open: () => void;
17
+ clear: () => void;
18
+ setQueryFromFilters: (filters: Record<string, any>) => void;
19
+ getValidatedParams: (query: Record<string, any>) => {
20
+ filters: any;
21
+ };
22
+ };
@@ -0,0 +1,6 @@
1
+ import { Ref } from 'vue';
2
+ export declare function useGlobalScroll(): {
3
+ isLocked: Ref<boolean, boolean>;
4
+ lock: () => void;
5
+ unlock: () => void;
6
+ };
@@ -0,0 +1,8 @@
1
+ import { default as logdown } from 'logdown';
2
+ interface Options {
3
+ tag?: string;
4
+ color?: string;
5
+ debug?: boolean;
6
+ }
7
+ export declare function useLogger(scope: string, options?: Options): logdown.Logger;
8
+ export {};
@@ -0,0 +1,27 @@
1
+ import { Component, EmitsOptions, VNode } from 'vue';
2
+ interface VNodeCustom extends VNode {
3
+ close: () => void;
4
+ }
5
+ /**
6
+ * @deprecated use useDialog
7
+ */
8
+ export declare function usePanel(): {
9
+ open: ({ layer, component, props, }: {
10
+ component: Component;
11
+ props?: any;
12
+ layer?: number;
13
+ }) => string;
14
+ getInstance: (uuid: string) => VNodeCustom;
15
+ close: (uuid: string) => void;
16
+ closeAll: () => void;
17
+ openByHash: ({ layer, component, props, }: {
18
+ component: Component;
19
+ props?: any;
20
+ layer?: number;
21
+ }) => void;
22
+ watchHash: ({ component, events, }: {
23
+ component: Component;
24
+ events?: EmitsOptions;
25
+ }) => any;
26
+ };
27
+ export {};