@karta.io/utils 0.20.3 → 0.21.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 +27 -15
- package/dist/index.d.ts +71 -71
- package/dist/index.mjs +27 -13
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
const libphonenumberJs = require('libphonenumber-js');
|
|
6
4
|
const lodashEs = require('lodash-es');
|
|
7
5
|
const detectBrowser = require('detect-browser');
|
|
@@ -43,7 +41,10 @@ function getCardNumber(number, options) {
|
|
|
43
41
|
if (isHidden) {
|
|
44
42
|
result = "\u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022";
|
|
45
43
|
} else {
|
|
46
|
-
result = number.replace(
|
|
44
|
+
result = number.replace(
|
|
45
|
+
/(\d{4})?(\d{4})?(\d{4})?(\d{4})?/,
|
|
46
|
+
hasOnlyLast4 ? "\u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 $4" : "$1 $2 $3 $4"
|
|
47
|
+
);
|
|
47
48
|
}
|
|
48
49
|
return dot === "\u2022" ? result : result.replaceAll("\u2022", dot);
|
|
49
50
|
}
|
|
@@ -57,7 +58,10 @@ function getCountryFromPhone(phone) {
|
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
function genLoadingTableRows(columns, limit) {
|
|
60
|
-
const row = columns.reduce(
|
|
61
|
+
const row = columns.reduce(
|
|
62
|
+
(acc, curr) => ({ ...acc, [curr.key]: void 0 }),
|
|
63
|
+
{}
|
|
64
|
+
);
|
|
61
65
|
return Array.from(Array(limit).keys()).map((item) => ({ id: item, ...row }));
|
|
62
66
|
}
|
|
63
67
|
|
|
@@ -81,10 +85,13 @@ function camelizeKeys(object) {
|
|
|
81
85
|
return object.map((v) => camelizeKeys(v));
|
|
82
86
|
}
|
|
83
87
|
if (object !== null && object.constructor === Object) {
|
|
84
|
-
return Object.keys(object).reduce(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
return Object.keys(object).reduce(
|
|
89
|
+
(result, key) => ({
|
|
90
|
+
...result,
|
|
91
|
+
[lodashEs.camelCase(key)]: camelizeKeys(object[key])
|
|
92
|
+
}),
|
|
93
|
+
{}
|
|
94
|
+
);
|
|
88
95
|
}
|
|
89
96
|
return object;
|
|
90
97
|
}
|
|
@@ -238,7 +245,9 @@ const useClassName = (block) => {
|
|
|
238
245
|
|
|
239
246
|
function parseVersion(version) {
|
|
240
247
|
if (typeof version !== "string" && typeof version !== "number") {
|
|
241
|
-
throw new TypeError(
|
|
248
|
+
throw new TypeError(
|
|
249
|
+
"Browser version must be type of string, number or negative boolean"
|
|
250
|
+
);
|
|
242
251
|
}
|
|
243
252
|
const [major, minor = 0, patch = 0, build = 0] = typeof version === "string" ? version.split(".").map(Number) : [version];
|
|
244
253
|
return { major, minor, patch, build };
|
|
@@ -253,12 +262,15 @@ function isVersionLower(minimum, target) {
|
|
|
253
262
|
function useDetectBrowser(versions, userAgent) {
|
|
254
263
|
const browserInfo = {};
|
|
255
264
|
if (userAgent) {
|
|
256
|
-
Object.assign(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
265
|
+
Object.assign(
|
|
266
|
+
browserInfo,
|
|
267
|
+
userAgent ? detectBrowser.detect(userAgent) : {
|
|
268
|
+
name: null,
|
|
269
|
+
version: null,
|
|
270
|
+
type: null,
|
|
271
|
+
os: null
|
|
272
|
+
}
|
|
273
|
+
);
|
|
262
274
|
} else {
|
|
263
275
|
Object.assign(browserInfo, detectBrowser.detect());
|
|
264
276
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,32 +2,32 @@ import { Browser } from 'detect-browser';
|
|
|
2
2
|
|
|
3
3
|
declare function viewExample(value: string): string;
|
|
4
4
|
|
|
5
|
-
declare function formatMoney(value: string | number | null | undefined, currency?: string, options?: {
|
|
6
|
-
locale: string;
|
|
7
|
-
minimumFractionDigits: number;
|
|
8
|
-
maximumFractionDigits: number;
|
|
5
|
+
declare function formatMoney(value: string | number | null | undefined, currency?: string, options?: {
|
|
6
|
+
locale: string;
|
|
7
|
+
minimumFractionDigits: number;
|
|
8
|
+
maximumFractionDigits: number;
|
|
9
9
|
}): string;
|
|
10
10
|
|
|
11
11
|
declare function createClassName(className: string): (...classNames: string[]) => string;
|
|
12
12
|
|
|
13
13
|
declare function genRandomNumber(min: number, max: number): number;
|
|
14
14
|
|
|
15
|
-
interface Options {
|
|
16
|
-
hasOnlyLast4: boolean;
|
|
17
|
-
isHidden: boolean;
|
|
18
|
-
dot: string;
|
|
19
|
-
}
|
|
15
|
+
interface Options {
|
|
16
|
+
hasOnlyLast4: boolean;
|
|
17
|
+
isHidden: boolean;
|
|
18
|
+
dot: string;
|
|
19
|
+
}
|
|
20
20
|
declare function getCardNumber(number: string, options?: Partial<Options>): string;
|
|
21
21
|
|
|
22
22
|
declare function getCountryFromPhone(phone: string): string;
|
|
23
23
|
|
|
24
|
-
interface Dictionary {
|
|
25
|
-
[keys: string | number]: any;
|
|
24
|
+
interface Dictionary {
|
|
25
|
+
[keys: string | number]: any;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
declare function genLoadingTableRows(columns: Dictionary[], limit: number): {
|
|
29
|
-
id: number | undefined;
|
|
30
|
-
key?: undefined;
|
|
28
|
+
declare function genLoadingTableRows(columns: Dictionary[], limit: number): {
|
|
29
|
+
id: number | undefined;
|
|
30
|
+
key?: undefined;
|
|
31
31
|
}[];
|
|
32
32
|
|
|
33
33
|
declare function genUUID(): string;
|
|
@@ -36,75 +36,75 @@ declare function camelizeKeys(object: Dictionary): Dictionary;
|
|
|
36
36
|
|
|
37
37
|
declare function validateNumber(value: string | number, defaultValue: number): number;
|
|
38
38
|
|
|
39
|
-
/**
|
|
40
|
-
* Принимает на вход число в виде строки или числа,
|
|
41
|
-
* возвращает корректное значение типа Number (убирает лишние пробелы и запятые)
|
|
42
|
-
* @example
|
|
43
|
-
* // returns 1000
|
|
44
|
-
* unformatNumber('1 000');
|
|
45
|
-
* @example
|
|
46
|
-
* // returns 1000
|
|
47
|
-
* unformatNumber('1,000')
|
|
48
|
-
* @example
|
|
49
|
-
* // returns 1000.123
|
|
50
|
-
* unformatNummber('1 000,123')
|
|
51
|
-
* @example
|
|
52
|
-
* // returns 1000.123
|
|
53
|
-
* unformatNummber('1,000.123')
|
|
54
|
-
* @param value
|
|
55
|
-
* @return number
|
|
56
|
-
*/
|
|
39
|
+
/**
|
|
40
|
+
* Принимает на вход число в виде строки или числа,
|
|
41
|
+
* возвращает корректное значение типа Number (убирает лишние пробелы и запятые)
|
|
42
|
+
* @example
|
|
43
|
+
* // returns 1000
|
|
44
|
+
* unformatNumber('1 000');
|
|
45
|
+
* @example
|
|
46
|
+
* // returns 1000
|
|
47
|
+
* unformatNumber('1,000')
|
|
48
|
+
* @example
|
|
49
|
+
* // returns 1000.123
|
|
50
|
+
* unformatNummber('1 000,123')
|
|
51
|
+
* @example
|
|
52
|
+
* // returns 1000.123
|
|
53
|
+
* unformatNummber('1,000.123')
|
|
54
|
+
* @param value
|
|
55
|
+
* @return number
|
|
56
|
+
*/
|
|
57
57
|
declare function unformatNumber(value: string | number): string | number;
|
|
58
58
|
|
|
59
|
-
declare function getPaginationParams({ page, limit, }: {
|
|
60
|
-
page: string | number;
|
|
61
|
-
limit: string | number;
|
|
62
|
-
}): {
|
|
63
|
-
limit: number;
|
|
64
|
-
offset: number;
|
|
65
|
-
};
|
|
66
|
-
declare function getPaginationLimit({ limit, }: {
|
|
67
|
-
limit: string | number;
|
|
68
|
-
}): number;
|
|
69
|
-
declare function getPaginationOffset({ page, limit, }: {
|
|
70
|
-
page: string | number;
|
|
71
|
-
limit: string | number;
|
|
72
|
-
}): number;
|
|
73
|
-
declare function getPaginationPages({ count, limit, }: {
|
|
74
|
-
count: number;
|
|
75
|
-
limit: string | number;
|
|
59
|
+
declare function getPaginationParams({ page, limit, }: {
|
|
60
|
+
page: string | number;
|
|
61
|
+
limit: string | number;
|
|
62
|
+
}): {
|
|
63
|
+
limit: number;
|
|
64
|
+
offset: number;
|
|
65
|
+
};
|
|
66
|
+
declare function getPaginationLimit({ limit, }: {
|
|
67
|
+
limit: string | number;
|
|
68
|
+
}): number;
|
|
69
|
+
declare function getPaginationOffset({ page, limit, }: {
|
|
70
|
+
page: string | number;
|
|
71
|
+
limit: string | number;
|
|
72
|
+
}): number;
|
|
73
|
+
declare function getPaginationPages({ count, limit, }: {
|
|
74
|
+
count: number;
|
|
75
|
+
limit: string | number;
|
|
76
76
|
}): number;
|
|
77
77
|
|
|
78
78
|
declare function parsePhone(phone: string): string;
|
|
79
79
|
|
|
80
|
-
declare function isElementIgnored({ ignoredClasses, event, }?: {
|
|
81
|
-
ignoredClasses?: string[];
|
|
82
|
-
event?: Event;
|
|
80
|
+
declare function isElementIgnored({ ignoredClasses, event, }?: {
|
|
81
|
+
ignoredClasses?: string[];
|
|
82
|
+
event?: Event;
|
|
83
83
|
}): boolean;
|
|
84
84
|
|
|
85
85
|
declare function isEmptyObject(object: {}): boolean;
|
|
86
86
|
|
|
87
|
-
declare const useClassName: (block: string) => {
|
|
88
|
-
b: (blockSuffix?: string) => string;
|
|
89
|
-
e: (element?: string) => string;
|
|
90
|
-
m: (modifier?: string, condition?: boolean) => string;
|
|
91
|
-
em: (element?: string, modifier?: string, condition?: boolean) => string;
|
|
92
|
-
mv: (modifier: string, modifierValue: string, condition?: boolean) => string;
|
|
93
|
-
cssVar: (object: Record<string, string>) => Record<string, string>;
|
|
94
|
-
cssVarName: (name: string) => string;
|
|
87
|
+
declare const useClassName: (block: string) => {
|
|
88
|
+
b: (blockSuffix?: string) => string;
|
|
89
|
+
e: (element?: string) => string;
|
|
90
|
+
m: (modifier?: string, condition?: boolean) => string;
|
|
91
|
+
em: (element?: string, modifier?: string, condition?: boolean) => string;
|
|
92
|
+
mv: (modifier: string, modifierValue: string, condition?: boolean) => string;
|
|
93
|
+
cssVar: (object: Record<string, string>) => Record<string, string>;
|
|
94
|
+
cssVarName: (name: string) => string;
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
-
interface BrowserInfo {
|
|
98
|
-
isDeprecated?: boolean;
|
|
99
|
-
name?: string;
|
|
100
|
-
version?: string;
|
|
101
|
-
os?: string;
|
|
102
|
-
type?: string;
|
|
103
|
-
options?: any;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
[key in Browser]?: string | boolean;
|
|
107
|
-
};
|
|
97
|
+
interface BrowserInfo {
|
|
98
|
+
isDeprecated?: boolean;
|
|
99
|
+
name?: string;
|
|
100
|
+
version?: string;
|
|
101
|
+
os?: string;
|
|
102
|
+
type?: string;
|
|
103
|
+
options?: any;
|
|
104
|
+
}
|
|
105
|
+
type VersionsList = {
|
|
106
|
+
[key in Browser]?: string | boolean;
|
|
107
|
+
};
|
|
108
108
|
declare function useDetectBrowser(versions: VersionsList, userAgent?: any): BrowserInfo;
|
|
109
109
|
|
|
110
110
|
declare function validatePhone(rule: string, value: string): boolean;
|
package/dist/index.mjs
CHANGED
|
@@ -39,7 +39,10 @@ function getCardNumber(number, options) {
|
|
|
39
39
|
if (isHidden) {
|
|
40
40
|
result = "\u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022";
|
|
41
41
|
} else {
|
|
42
|
-
result = number.replace(
|
|
42
|
+
result = number.replace(
|
|
43
|
+
/(\d{4})?(\d{4})?(\d{4})?(\d{4})?/,
|
|
44
|
+
hasOnlyLast4 ? "\u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 $4" : "$1 $2 $3 $4"
|
|
45
|
+
);
|
|
43
46
|
}
|
|
44
47
|
return dot === "\u2022" ? result : result.replaceAll("\u2022", dot);
|
|
45
48
|
}
|
|
@@ -53,7 +56,10 @@ function getCountryFromPhone(phone) {
|
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
function genLoadingTableRows(columns, limit) {
|
|
56
|
-
const row = columns.reduce(
|
|
59
|
+
const row = columns.reduce(
|
|
60
|
+
(acc, curr) => ({ ...acc, [curr.key]: void 0 }),
|
|
61
|
+
{}
|
|
62
|
+
);
|
|
57
63
|
return Array.from(Array(limit).keys()).map((item) => ({ id: item, ...row }));
|
|
58
64
|
}
|
|
59
65
|
|
|
@@ -77,10 +83,13 @@ function camelizeKeys(object) {
|
|
|
77
83
|
return object.map((v) => camelizeKeys(v));
|
|
78
84
|
}
|
|
79
85
|
if (object !== null && object.constructor === Object) {
|
|
80
|
-
return Object.keys(object).reduce(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
return Object.keys(object).reduce(
|
|
87
|
+
(result, key) => ({
|
|
88
|
+
...result,
|
|
89
|
+
[camelCase(key)]: camelizeKeys(object[key])
|
|
90
|
+
}),
|
|
91
|
+
{}
|
|
92
|
+
);
|
|
84
93
|
}
|
|
85
94
|
return object;
|
|
86
95
|
}
|
|
@@ -234,7 +243,9 @@ const useClassName = (block) => {
|
|
|
234
243
|
|
|
235
244
|
function parseVersion(version) {
|
|
236
245
|
if (typeof version !== "string" && typeof version !== "number") {
|
|
237
|
-
throw new TypeError(
|
|
246
|
+
throw new TypeError(
|
|
247
|
+
"Browser version must be type of string, number or negative boolean"
|
|
248
|
+
);
|
|
238
249
|
}
|
|
239
250
|
const [major, minor = 0, patch = 0, build = 0] = typeof version === "string" ? version.split(".").map(Number) : [version];
|
|
240
251
|
return { major, minor, patch, build };
|
|
@@ -249,12 +260,15 @@ function isVersionLower(minimum, target) {
|
|
|
249
260
|
function useDetectBrowser(versions, userAgent) {
|
|
250
261
|
const browserInfo = {};
|
|
251
262
|
if (userAgent) {
|
|
252
|
-
Object.assign(
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
263
|
+
Object.assign(
|
|
264
|
+
browserInfo,
|
|
265
|
+
userAgent ? detect(userAgent) : {
|
|
266
|
+
name: null,
|
|
267
|
+
version: null,
|
|
268
|
+
type: null,
|
|
269
|
+
os: null
|
|
270
|
+
}
|
|
271
|
+
);
|
|
258
272
|
} else {
|
|
259
273
|
Object.assign(browserInfo, detect());
|
|
260
274
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karta.io/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "karta.io utils for admin and application",
|
|
5
5
|
"author": "Vitaly Blokhin <karambafe@gmail.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -20,20 +20,20 @@
|
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@karta.io/common-data": "^0.
|
|
23
|
+
"@karta.io/common-data": "^0.21.0",
|
|
24
24
|
"detect-browser": "5.3.0",
|
|
25
25
|
"libphonenumber-js": "1.9.44",
|
|
26
26
|
"lodash-es": "4.17.21"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@qvant/prettier-config": "0.1.0",
|
|
30
|
-
"eslint": "8.
|
|
30
|
+
"eslint": "8.28.0",
|
|
31
31
|
"eslint-config-airbnb-base": "15.0.0",
|
|
32
|
-
"eslint-plugin-import": "2.
|
|
33
|
-
"prettier": "2.
|
|
34
|
-
"typescript": "4.
|
|
35
|
-
"unbuild": "0.
|
|
36
|
-
"vitest": "0.
|
|
32
|
+
"eslint-plugin-import": "2.26.0",
|
|
33
|
+
"prettier": "2.8.0",
|
|
34
|
+
"typescript": "4.9.3",
|
|
35
|
+
"unbuild": "1.0.1",
|
|
36
|
+
"vitest": "0.25.3"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"dev": "vitest",
|