@karta.io/utils 0.26.5 → 0.27.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/dist/index.cjs +2 -0
- package/dist/index.d.ts +125 -125
- package/dist/index.mjs +2 -0
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -9,6 +9,7 @@ const utc = require('dayjs/plugin/utc.js');
|
|
|
9
9
|
const tz = require('dayjs/plugin/timezone.js');
|
|
10
10
|
const updateLocale = require('dayjs/plugin/updateLocale.js');
|
|
11
11
|
const isToday = require('dayjs/plugin/isToday.js');
|
|
12
|
+
const customParseFormat = require('dayjs/plugin/customParseFormat');
|
|
12
13
|
const detectBrowser = require('detect-browser');
|
|
13
14
|
const logdown = require('logdown');
|
|
14
15
|
|
|
@@ -437,6 +438,7 @@ dayjs.extend(utc);
|
|
|
437
438
|
dayjs.extend(tz);
|
|
438
439
|
dayjs.extend(updateLocale);
|
|
439
440
|
dayjs.extend(isToday);
|
|
441
|
+
dayjs.extend(customParseFormat);
|
|
440
442
|
function useDayjs(timezone) {
|
|
441
443
|
dayjs.updateLocale("en", {
|
|
442
444
|
weekStart: 1
|
package/dist/index.d.ts
CHANGED
|
@@ -4,175 +4,175 @@ import dayjs from 'dayjs';
|
|
|
4
4
|
import { Browser } from 'detect-browser';
|
|
5
5
|
import logdown from 'logdown';
|
|
6
6
|
|
|
7
|
-
interface Dictionary {
|
|
8
|
-
[keys: string | number]: any;
|
|
9
|
-
}
|
|
10
|
-
interface ResponseError {
|
|
11
|
-
status: number;
|
|
12
|
-
statusMessage: string;
|
|
13
|
-
message: string;
|
|
14
|
-
data: Record<string, string | string[]> | null;
|
|
7
|
+
interface Dictionary {
|
|
8
|
+
[keys: string | number]: any;
|
|
9
|
+
}
|
|
10
|
+
interface ResponseError {
|
|
11
|
+
status: number;
|
|
12
|
+
statusMessage: string;
|
|
13
|
+
message: string;
|
|
14
|
+
data: Record<string, string | string[]> | null;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
declare function camelizeKeys(object: Dictionary): Dictionary;
|
|
18
18
|
|
|
19
19
|
declare function createClassName(className: string): (...classNames: string[]) => string;
|
|
20
20
|
|
|
21
|
-
declare function formatMoney(value: string | number | null | undefined, currency?: string, options?: {
|
|
22
|
-
locale: string;
|
|
23
|
-
minimumFractionDigits: number;
|
|
24
|
-
maximumFractionDigits: number;
|
|
21
|
+
declare function formatMoney(value: string | number | null | undefined, currency?: string, options?: {
|
|
22
|
+
locale: string;
|
|
23
|
+
minimumFractionDigits: number;
|
|
24
|
+
maximumFractionDigits: number;
|
|
25
25
|
}): 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
50
|
declare function isEmptyObject(object: {}): boolean;
|
|
51
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;
|
|
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): 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
|
-
declare function useAbortController<T extends (...args: any[]) => any>(callback: T): {
|
|
99
|
-
call(...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
100
|
-
abort(): void;
|
|
101
|
-
isAborted(error: ResponseError): boolean;
|
|
98
|
+
declare function useAbortController<T extends (...args: any[]) => any>(callback: T): {
|
|
99
|
+
call(...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
100
|
+
abort(): void;
|
|
101
|
+
isAborted(error: ResponseError): boolean;
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
-
declare function useAsyncMultiselect<T extends (...args: any[]) => any, K extends (params: Awaited<ReturnType<T>>['results'][0]) => any>({ apiMethod, mapResultCallback, selectedValues, params, }: {
|
|
105
|
-
apiMethod: T;
|
|
106
|
-
mapResultCallback: K;
|
|
107
|
-
selectedValues: ComputedRef<Parameters<T>[0]['includedIds']> | WritableComputedRef<Parameters<T>[0]['includedIds']>;
|
|
108
|
-
params?: Parameters<T>[0];
|
|
109
|
-
}): {
|
|
110
|
-
search: vue.Ref<string>;
|
|
111
|
-
options: ComputedRef<ReturnType<K>[1][]>;
|
|
112
|
-
loading: vue.Ref<boolean>;
|
|
113
|
-
hasNextPage: ComputedRef<boolean>;
|
|
114
|
-
items: vue.Ref<Map<ReturnType<K>[0], ReturnType<K>[1]>>;
|
|
115
|
-
loadItems: (isSearch?: boolean) => Promise<void>;
|
|
116
|
-
handleSearch: (value: string) => Promise<void>;
|
|
104
|
+
declare function useAsyncMultiselect<T extends (...args: any[]) => any, K extends (params: Awaited<ReturnType<T>>['results'][0]) => any>({ apiMethod, mapResultCallback, selectedValues, params, }: {
|
|
105
|
+
apiMethod: T;
|
|
106
|
+
mapResultCallback: K;
|
|
107
|
+
selectedValues: ComputedRef<Parameters<T>[0]['includedIds']> | WritableComputedRef<Parameters<T>[0]['includedIds']>;
|
|
108
|
+
params?: Parameters<T>[0];
|
|
109
|
+
}): {
|
|
110
|
+
search: vue.Ref<string>;
|
|
111
|
+
options: ComputedRef<ReturnType<K>[1][]>;
|
|
112
|
+
loading: vue.Ref<boolean>;
|
|
113
|
+
hasNextPage: ComputedRef<boolean>;
|
|
114
|
+
items: vue.Ref<Map<ReturnType<K>[0], ReturnType<K>[1]>>;
|
|
115
|
+
loadItems: (isSearch?: boolean) => Promise<void>;
|
|
116
|
+
handleSearch: (value: string) => Promise<void>;
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
-
declare function useAsyncSelect<T extends (...args: any[]) => any, K extends (params: Awaited<ReturnType<T>>['results'][0]) => any>({ apiMethod, mapResultCallback, includedIds, params, }: {
|
|
120
|
-
apiMethod: T;
|
|
121
|
-
mapResultCallback: K;
|
|
122
|
-
includedIds?: Parameters<T>[0]['includedIds'];
|
|
123
|
-
params?: Parameters<T>[0];
|
|
124
|
-
}): {
|
|
125
|
-
search: vue.Ref<string>;
|
|
126
|
-
options: vue.ComputedRef<ReturnType<K>[1][]>;
|
|
127
|
-
loading: vue.Ref<boolean>;
|
|
128
|
-
hasNextPage: vue.ComputedRef<boolean>;
|
|
129
|
-
items: vue.Ref<Map<ReturnType<K>[0], ReturnType<K>[1]>>;
|
|
130
|
-
loadItems: (isSearch?: boolean) => Promise<void>;
|
|
131
|
-
handleSearch: (value: string) => Promise<void>;
|
|
119
|
+
declare function useAsyncSelect<T extends (...args: any[]) => any, K extends (params: Awaited<ReturnType<T>>['results'][0]) => any>({ apiMethod, mapResultCallback, includedIds, params, }: {
|
|
120
|
+
apiMethod: T;
|
|
121
|
+
mapResultCallback: K;
|
|
122
|
+
includedIds?: Parameters<T>[0]['includedIds'];
|
|
123
|
+
params?: Parameters<T>[0];
|
|
124
|
+
}): {
|
|
125
|
+
search: vue.Ref<string>;
|
|
126
|
+
options: vue.ComputedRef<ReturnType<K>[1][]>;
|
|
127
|
+
loading: vue.Ref<boolean>;
|
|
128
|
+
hasNextPage: vue.ComputedRef<boolean>;
|
|
129
|
+
items: vue.Ref<Map<ReturnType<K>[0], ReturnType<K>[1]>>;
|
|
130
|
+
loadItems: (isSearch?: boolean) => Promise<void>;
|
|
131
|
+
handleSearch: (value: string) => Promise<void>;
|
|
132
132
|
};
|
|
133
133
|
|
|
134
|
-
declare const useClassName: (block: string) => {
|
|
135
|
-
b: (blockSuffix?: string) => string;
|
|
136
|
-
e: (element?: string) => string;
|
|
137
|
-
m: (modifier?: string, condition?: boolean) => string;
|
|
138
|
-
em: (element?: string, modifier?: string, condition?: boolean) => string;
|
|
139
|
-
mv: (modifier: string, modifierValue: string, condition?: boolean) => string;
|
|
140
|
-
cssVar: (object: Record<string, string>) => Record<string, string>;
|
|
141
|
-
cssVarName: (name: string) => string;
|
|
134
|
+
declare const useClassName: (block: string) => {
|
|
135
|
+
b: (blockSuffix?: string) => string;
|
|
136
|
+
e: (element?: string) => string;
|
|
137
|
+
m: (modifier?: string, condition?: boolean) => string;
|
|
138
|
+
em: (element?: string, modifier?: string, condition?: boolean) => string;
|
|
139
|
+
mv: (modifier: string, modifierValue: string, condition?: boolean) => string;
|
|
140
|
+
cssVar: (object: Record<string, string>) => Record<string, string>;
|
|
141
|
+
cssVarName: (name: string) => string;
|
|
142
142
|
};
|
|
143
143
|
|
|
144
|
-
/**
|
|
145
|
-
* Обертка над dayjs, позволяющая задавать timezone
|
|
146
|
-
* @see https://day.js.org/en/
|
|
147
|
-
*
|
|
148
|
-
* Использовать параметр timezone нужно крайне аккуратно,
|
|
149
|
-
* может привести к утечкам памяти
|
|
150
|
-
* @todo Подумать как сделать оптимальнее
|
|
151
|
-
*/
|
|
144
|
+
/**
|
|
145
|
+
* Обертка над dayjs, позволяющая задавать timezone
|
|
146
|
+
* @see https://day.js.org/en/
|
|
147
|
+
*
|
|
148
|
+
* Использовать параметр timezone нужно крайне аккуратно,
|
|
149
|
+
* может привести к утечкам памяти
|
|
150
|
+
* @todo Подумать как сделать оптимальнее
|
|
151
|
+
*/
|
|
152
152
|
declare function useDayjs(timezone?: string): (date?: dayjs.ConfigType, format?: dayjs.OptionType, locale?: string, strict?: boolean) => dayjs.Dayjs;
|
|
153
153
|
|
|
154
|
-
interface BrowserInfo {
|
|
155
|
-
isDeprecated?: boolean;
|
|
156
|
-
name?: string;
|
|
157
|
-
version?: string;
|
|
158
|
-
os?: string;
|
|
159
|
-
type?: string;
|
|
160
|
-
options?: any;
|
|
161
|
-
}
|
|
162
|
-
type VersionsList = {
|
|
163
|
-
[key in Browser]?: string | boolean;
|
|
164
|
-
};
|
|
154
|
+
interface BrowserInfo {
|
|
155
|
+
isDeprecated?: boolean;
|
|
156
|
+
name?: string;
|
|
157
|
+
version?: string;
|
|
158
|
+
os?: string;
|
|
159
|
+
type?: string;
|
|
160
|
+
options?: any;
|
|
161
|
+
}
|
|
162
|
+
type VersionsList = {
|
|
163
|
+
[key in Browser]?: string | boolean;
|
|
164
|
+
};
|
|
165
165
|
declare function useDetectBrowser(versions: VersionsList, userAgent?: any): BrowserInfo;
|
|
166
166
|
|
|
167
|
-
/**
|
|
168
|
-
* @see https://github.com/caiogondim/logdown.js#readme
|
|
169
|
-
*/
|
|
170
|
-
|
|
171
|
-
interface Options {
|
|
172
|
-
tag?: string;
|
|
173
|
-
color?: string;
|
|
174
|
-
debug?: boolean;
|
|
175
|
-
}
|
|
167
|
+
/**
|
|
168
|
+
* @see https://github.com/caiogondim/logdown.js#readme
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
interface Options {
|
|
172
|
+
tag?: string;
|
|
173
|
+
color?: string;
|
|
174
|
+
debug?: boolean;
|
|
175
|
+
}
|
|
176
176
|
declare function useLogger(scope: string, options?: Options): logdown.Logger;
|
|
177
177
|
|
|
178
178
|
declare function validatePhone(rule: string, value: string): boolean;
|
package/dist/index.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import utc from 'dayjs/plugin/utc.js';
|
|
|
7
7
|
import tz from 'dayjs/plugin/timezone.js';
|
|
8
8
|
import updateLocale from 'dayjs/plugin/updateLocale.js';
|
|
9
9
|
import isToday from 'dayjs/plugin/isToday.js';
|
|
10
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
10
11
|
import { detect } from 'detect-browser';
|
|
11
12
|
import logdown from 'logdown';
|
|
12
13
|
|
|
@@ -435,6 +436,7 @@ dayjs.extend(utc);
|
|
|
435
436
|
dayjs.extend(tz);
|
|
436
437
|
dayjs.extend(updateLocale);
|
|
437
438
|
dayjs.extend(isToday);
|
|
439
|
+
dayjs.extend(customParseFormat);
|
|
438
440
|
function useDayjs(timezone) {
|
|
439
441
|
dayjs.updateLocale("en", {
|
|
440
442
|
weekStart: 1
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karta.io/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "karta.io utils for admin and application",
|
|
5
5
|
"author": "Vitaly Blokhin <karambafe@gmail.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"vue": "3.2.45"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@karta.io/common-data": "^0.
|
|
26
|
+
"@karta.io/common-data": "^0.27.0",
|
|
27
27
|
"@vueuse/core": "9.10.0",
|
|
28
28
|
"dayjs": "1.11.6",
|
|
29
29
|
"detect-browser": "5.3.0",
|