@inzombieland/core 1.18.2 → 1.18.3
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/helpers/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { apiHelper } from "./api-helper";
|
|
2
2
|
export { dateHelper } from "./date-helper";
|
|
3
|
+
export { phoneHelper } from "./phone-helper";
|
|
4
|
+
export { stringHelper } from "./string-helper";
|
|
3
5
|
export { deviceHelper, type Device } from "./device-helper";
|
|
4
6
|
export declare function once<T extends (...args: any[]) => any>(fn: T): T;
|
|
5
7
|
export declare function createSingletonAsync<T, Args extends unknown[]>(fn: (...args: Args) => Promise<T>): (...args: Args) => Promise<T>;
|
package/helpers/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { apiHelper } from "./api-helper.mjs";
|
|
2
2
|
export { dateHelper } from "./date-helper.mjs";
|
|
3
|
+
export { phoneHelper } from "./phone-helper.mjs";
|
|
4
|
+
export { stringHelper } from "./string-helper.mjs";
|
|
3
5
|
export { deviceHelper } from "./device-helper.mjs";
|
|
4
6
|
export function once(fn) {
|
|
5
7
|
let executed = false;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function getPlainPhoneNumber(value: string): string;
|
|
2
|
+
/**
|
|
3
|
+
* Преобразование номера телефона в формат: +7 (987) 777-88-99
|
|
4
|
+
* @param value - номер телефона
|
|
5
|
+
* @param addLastSymbol -
|
|
6
|
+
*/
|
|
7
|
+
export declare function convertToPhone(value: string, addLastSymbol?: boolean): string;
|
|
8
|
+
export declare function maskPhone(phone?: string): string;
|
|
9
|
+
export declare const phoneHelper: {
|
|
10
|
+
getPlainPhoneNumber: typeof getPlainPhoneNumber;
|
|
11
|
+
convertToPhone: typeof convertToPhone;
|
|
12
|
+
maskPhone: typeof maskPhone;
|
|
13
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export function getPlainPhoneNumber(value) {
|
|
2
|
+
const symbol = "+ ";
|
|
3
|
+
const tempNumber = value.replace(symbol, "").replace(symbol.trim(), "");
|
|
4
|
+
return tempNumber.replaceAll(/\D+/g, "");
|
|
5
|
+
}
|
|
6
|
+
export function convertToPhone(value, addLastSymbol = true) {
|
|
7
|
+
const plainNumber = getPlainPhoneNumber(value);
|
|
8
|
+
if (plainNumber.length === 0) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
const mask = getCountryMask(plainNumber);
|
|
12
|
+
return getFormattedByMask(plainNumber, mask, addLastSymbol);
|
|
13
|
+
}
|
|
14
|
+
function getCountryMask(value = "") {
|
|
15
|
+
if (value.length === 0) {
|
|
16
|
+
return "";
|
|
17
|
+
}
|
|
18
|
+
if (value.startsWith("7")) {
|
|
19
|
+
return "+# (###) ###-##-###########";
|
|
20
|
+
}
|
|
21
|
+
if (value.startsWith("8")) {
|
|
22
|
+
return "# (###) ###-##-###########";
|
|
23
|
+
}
|
|
24
|
+
if (value.startsWith("1")) {
|
|
25
|
+
return "+# ### ### ## ###########";
|
|
26
|
+
}
|
|
27
|
+
if (value.startsWith("375")) {
|
|
28
|
+
return "+### ## ### ## ##########";
|
|
29
|
+
}
|
|
30
|
+
if (value.startsWith("380")) {
|
|
31
|
+
return "+### ## ### ## ##########";
|
|
32
|
+
}
|
|
33
|
+
return "+####################";
|
|
34
|
+
}
|
|
35
|
+
function getFormattedByMask(plainNumber, mask, addLastSymbol) {
|
|
36
|
+
let number = "";
|
|
37
|
+
let symbolIterator = 0;
|
|
38
|
+
[...mask].forEach((value) => {
|
|
39
|
+
if (plainNumber.length >= symbolIterator) {
|
|
40
|
+
if (value === "#") {
|
|
41
|
+
if (plainNumber.length > symbolIterator) {
|
|
42
|
+
number += plainNumber[symbolIterator];
|
|
43
|
+
}
|
|
44
|
+
symbolIterator++;
|
|
45
|
+
} else {
|
|
46
|
+
const notPasteSymbol = symbolIterator === plainNumber.length && !addLastSymbol;
|
|
47
|
+
if (!notPasteSymbol) {
|
|
48
|
+
number += value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return number;
|
|
54
|
+
}
|
|
55
|
+
export function maskPhone(phone = "") {
|
|
56
|
+
return `+${phone.slice(0, 1)} *****${phone.slice(-4)}`;
|
|
57
|
+
}
|
|
58
|
+
export const phoneHelper = { getPlainPhoneNumber, convertToPhone, maskPhone };
|