@peacom/core 0.0.62 → 0.0.63
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/README.md +11 -11
- package/package.json +1 -1
- package/src/index.d.ts +4 -4
- package/src/index.js +7 -7
- package/src/lib/api/api.constant.d.ts +58 -58
- package/src/lib/api/api.constant.js +19 -19
- package/src/lib/api/core.api.d.ts +9 -9
- package/src/lib/api/core.api.js +77 -77
- package/src/lib/api/index.d.ts +4 -4
- package/src/lib/api/index.js +7 -7
- package/src/lib/api/micro-service.api.d.ts +2 -2
- package/src/lib/api/micro-service.api.js +37 -37
- package/src/lib/api/queue/queue.api.d.ts +5 -5
- package/src/lib/api/queue/queue.api.js +23 -23
- package/src/lib/core.d.ts +1 -1
- package/src/lib/core.js +7 -7
- package/src/lib/error/FormError.d.ts +53 -53
- package/src/lib/error/FormError.js +57 -57
- package/src/lib/error/HttpError.d.ts +4 -4
- package/src/lib/error/HttpError.js +11 -11
- package/src/lib/model/Application.d.ts +49 -49
- package/src/lib/model/Application.js +56 -56
- package/src/lib/model/Billing.d.ts +10 -10
- package/src/lib/model/Billing.js +15 -15
- package/src/lib/model/Currency.d.ts +4 -4
- package/src/lib/model/Currency.js +8 -8
- package/src/lib/model/FileInfo.d.ts +9 -9
- package/src/lib/model/FileInfo.js +2 -2
- package/src/lib/model/conversation/constant.d.ts +25 -21
- package/src/lib/model/conversation/constant.js +24 -15
- package/src/lib/model/conversation/constant.js.map +1 -1
- package/src/lib/model/conversation/index.d.ts +1 -1
- package/src/lib/model/conversation/index.js +4 -4
- package/src/lib/model/index.d.ts +9 -9
- package/src/lib/model/index.js +12 -12
- package/src/lib/model/message/Message.d.ts +117 -117
- package/src/lib/model/message/Message.js +83 -83
- package/src/lib/model/message/TemplateMessage.d.ts +4 -4
- package/src/lib/model/message/TemplateMessage.js +8 -8
- package/src/lib/model/message/index.d.ts +4 -4
- package/src/lib/model/message/index.js +7 -7
- package/src/lib/model/message/sinch/SinchWhatsappTemplate.d.ts +22 -22
- package/src/lib/model/message/sinch/SinchWhatsappTemplate.js +13 -13
- package/src/lib/model/message/zalo/ZaloZNSTemplate.d.ts +23 -23
- package/src/lib/model/message/zalo/ZaloZNSTemplate.js +2 -2
- package/src/lib/model/queue/QueueMessage.d.ts +28 -28
- package/src/lib/model/queue/QueueMessage.js +8 -8
- package/src/lib/model/queue/index.d.ts +2 -2
- package/src/lib/model/queue/index.js +5 -5
- package/src/lib/model/queue/queue.constant.d.ts +5 -5
- package/src/lib/model/queue/queue.constant.js +9 -9
- package/src/lib/model/template/Template.d.ts +43 -43
- package/src/lib/model/template/Template.js +88 -88
- package/src/lib/model/template/index.d.ts +1 -1
- package/src/lib/model/template/index.js +4 -4
- package/src/lib/model/viber-business/constant.d.ts +4 -4
- package/src/lib/model/viber-business/constant.js +8 -8
- package/src/lib/model/viber-business/index.d.ts +1 -1
- package/src/lib/model/viber-business/index.js +4 -4
- package/src/lib/util/date/constant.d.ts +3 -3
- package/src/lib/util/date/constant.js +6 -6
- package/src/lib/util/date/date.util.d.ts +15 -15
- package/src/lib/util/date/date.util.js +40 -40
- package/src/lib/util/file/file.util.d.ts +5 -5
- package/src/lib/util/file/file.util.js +34 -34
- package/src/lib/util/general.util.d.ts +1 -1
- package/src/lib/util/general.util.js +7 -7
- package/src/lib/util/index.d.ts +5 -5
- package/src/lib/util/index.js +8 -8
- package/src/lib/util/message/message.util.d.ts +89 -89
- package/src/lib/util/message/message.util.js +65 -65
- package/src/lib/util/phone.util.d.ts +24 -24
- package/src/lib/util/phone.util.js +50 -50
- package/src/lib/util/string.util.d.ts +13 -13
- package/src/lib/util/string.util.js +107 -107
@@ -1,51 +1,51 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.isPhoneValid = exports.PHONE_COUNTRY_SUPPORT = exports.DEFAULT_PHONE_COUNTRY = void 0;
|
4
|
-
const google_libphonenumber_1 = require("google-libphonenumber");
|
5
|
-
const _1 = require("./");
|
6
|
-
const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
|
7
|
-
exports.DEFAULT_PHONE_COUNTRY = "VN";
|
8
|
-
exports.PHONE_COUNTRY_SUPPORT = {
|
9
|
-
84: {
|
10
|
-
countries: [{
|
11
|
-
ios2: "VN"
|
12
|
-
}]
|
13
|
-
},
|
14
|
-
1: {
|
15
|
-
countries: [
|
16
|
-
{
|
17
|
-
iso2: "US",
|
18
|
-
regions: [""]
|
19
|
-
}, {
|
20
|
-
iso2: "CA"
|
21
|
-
}
|
22
|
-
]
|
23
|
-
}
|
24
|
-
};
|
25
|
-
function isPhoneValid(phone, country = exports.DEFAULT_PHONE_COUNTRY) {
|
26
|
-
if (!phone || !(0, _1.hasText)(phone)) {
|
27
|
-
throw new Error(`Invalid phone ${phone}`);
|
28
|
-
}
|
29
|
-
let _phone = phone;
|
30
|
-
const phone2Prefix = phone.substring(0, 2);
|
31
|
-
if (phone2Prefix !== "00") {
|
32
|
-
const phone1Prefix = phone[0];
|
33
|
-
if (phone1Prefix !== "0") {
|
34
|
-
_phone = `+${phone}`;
|
35
|
-
}
|
36
|
-
}
|
37
|
-
const number = phoneUtil.parse(_phone, country);
|
38
|
-
const existPhone = phoneUtil.isValidNumber(number);
|
39
|
-
if (!existPhone) {
|
40
|
-
throw new Error(`Invalid phone ${phone}`);
|
41
|
-
}
|
42
|
-
return {
|
43
|
-
countryCode: number.getCountryCode(),
|
44
|
-
nationalNumber: `0${number.getNationalNumber()}`,
|
45
|
-
e164: `${number.getCountryCode()}${number.getNationalNumber()}`,
|
46
|
-
network: number.preferredDomesticCarrierCodeCount(),
|
47
|
-
region: phoneUtil.getRegionCodeForNumber(number)
|
48
|
-
};
|
49
|
-
}
|
50
|
-
exports.isPhoneValid = isPhoneValid;
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isPhoneValid = exports.PHONE_COUNTRY_SUPPORT = exports.DEFAULT_PHONE_COUNTRY = void 0;
|
4
|
+
const google_libphonenumber_1 = require("google-libphonenumber");
|
5
|
+
const _1 = require("./");
|
6
|
+
const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
|
7
|
+
exports.DEFAULT_PHONE_COUNTRY = "VN";
|
8
|
+
exports.PHONE_COUNTRY_SUPPORT = {
|
9
|
+
84: {
|
10
|
+
countries: [{
|
11
|
+
ios2: "VN"
|
12
|
+
}]
|
13
|
+
},
|
14
|
+
1: {
|
15
|
+
countries: [
|
16
|
+
{
|
17
|
+
iso2: "US",
|
18
|
+
regions: [""]
|
19
|
+
}, {
|
20
|
+
iso2: "CA"
|
21
|
+
}
|
22
|
+
]
|
23
|
+
}
|
24
|
+
};
|
25
|
+
function isPhoneValid(phone, country = exports.DEFAULT_PHONE_COUNTRY) {
|
26
|
+
if (!phone || !(0, _1.hasText)(phone)) {
|
27
|
+
throw new Error(`Invalid phone ${phone}`);
|
28
|
+
}
|
29
|
+
let _phone = phone;
|
30
|
+
const phone2Prefix = phone.substring(0, 2);
|
31
|
+
if (phone2Prefix !== "00") {
|
32
|
+
const phone1Prefix = phone[0];
|
33
|
+
if (phone1Prefix !== "0") {
|
34
|
+
_phone = `+${phone}`;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
const number = phoneUtil.parse(_phone, country);
|
38
|
+
const existPhone = phoneUtil.isValidNumber(number);
|
39
|
+
if (!existPhone) {
|
40
|
+
throw new Error(`Invalid phone ${phone}`);
|
41
|
+
}
|
42
|
+
return {
|
43
|
+
countryCode: number.getCountryCode(),
|
44
|
+
nationalNumber: `0${number.getNationalNumber()}`,
|
45
|
+
e164: `${number.getCountryCode()}${number.getNationalNumber()}`,
|
46
|
+
network: number.preferredDomesticCarrierCodeCount(),
|
47
|
+
region: phoneUtil.getRegionCodeForNumber(number)
|
48
|
+
};
|
49
|
+
}
|
50
|
+
exports.isPhoneValid = isPhoneValid;
|
51
51
|
//# sourceMappingURL=phone.util.js.map
|
@@ -1,13 +1,13 @@
|
|
1
|
-
export declare function generateRandomCode(length: number): string;
|
2
|
-
export declare const hasText: (str: string) => boolean;
|
3
|
-
export declare function markKey(keyStr: string): string;
|
4
|
-
export declare function unescapeHTML(str: string): string;
|
5
|
-
export declare const filterForNumberOnly: (str: string) => string;
|
6
|
-
export declare function isNumberOnly(str: string): boolean;
|
7
|
-
export declare function filterForInvalidCharacter(str: string, replaceCharacter?: string): string;
|
8
|
-
export declare function filterNotNumberAndDivideChar(str: string): string;
|
9
|
-
export declare function stringNumberToList(str: string): number[];
|
10
|
-
export declare function htmlEncode(rawStr: string): string;
|
11
|
-
export declare function filterNonAlphaNumeric(str: string): string;
|
12
|
-
export declare const leftString: (string: string, count: number) => string;
|
13
|
-
export declare const rightString: (string: string, count: number) => string;
|
1
|
+
export declare function generateRandomCode(length: number): string;
|
2
|
+
export declare const hasText: (str: string) => boolean;
|
3
|
+
export declare function markKey(keyStr: string): string;
|
4
|
+
export declare function unescapeHTML(str: string): string;
|
5
|
+
export declare const filterForNumberOnly: (str: string) => string;
|
6
|
+
export declare function isNumberOnly(str: string): boolean;
|
7
|
+
export declare function filterForInvalidCharacter(str: string, replaceCharacter?: string): string;
|
8
|
+
export declare function filterNotNumberAndDivideChar(str: string): string;
|
9
|
+
export declare function stringNumberToList(str: string): number[];
|
10
|
+
export declare function htmlEncode(rawStr: string): string;
|
11
|
+
export declare function filterNonAlphaNumeric(str: string): string;
|
12
|
+
export declare const leftString: (string: string, count: number) => string;
|
13
|
+
export declare const rightString: (string: string, count: number) => string;
|
@@ -1,108 +1,108 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.rightString = exports.leftString = exports.filterNonAlphaNumeric = exports.htmlEncode = exports.stringNumberToList = exports.filterNotNumberAndDivideChar = exports.filterForInvalidCharacter = exports.isNumberOnly = exports.filterForNumberOnly = exports.unescapeHTML = exports.markKey = exports.hasText = exports.generateRandomCode = void 0;
|
4
|
-
function generateRandomCode(length) {
|
5
|
-
let text = "";
|
6
|
-
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
7
|
-
for (let i = 0; i < length; i += 1)
|
8
|
-
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
9
|
-
return text;
|
10
|
-
}
|
11
|
-
exports.generateRandomCode = generateRandomCode;
|
12
|
-
const hasText = (str) => {
|
13
|
-
const testStr = `${str || ""}`;
|
14
|
-
return !!str && testStr.length > 0;
|
15
|
-
};
|
16
|
-
exports.hasText = hasText;
|
17
|
-
function markKey(keyStr) {
|
18
|
-
return `**** ${keyStr.substring(keyStr.length - 4, keyStr.length)}`;
|
19
|
-
}
|
20
|
-
exports.markKey = markKey;
|
21
|
-
const htmlEntities = {
|
22
|
-
nbsp: " ",
|
23
|
-
cent: "¢",
|
24
|
-
pound: "£",
|
25
|
-
yen: "¥",
|
26
|
-
euro: "€",
|
27
|
-
copy: "©",
|
28
|
-
reg: "®",
|
29
|
-
lt: "<",
|
30
|
-
gt: ">",
|
31
|
-
quot: '"',
|
32
|
-
amp: "&",
|
33
|
-
apos: "'"
|
34
|
-
};
|
35
|
-
function unescapeHTML(str) {
|
36
|
-
return str.replace(/&([^;]+);/g, (entity, entityCode) => {
|
37
|
-
let match;
|
38
|
-
if (entityCode in htmlEntities) {
|
39
|
-
return htmlEntities[entityCode];
|
40
|
-
}
|
41
|
-
// eslint-disable-next-line no-cond-assign
|
42
|
-
if ((match = entityCode.match(/^#x([\da-fA-F]+)$/))) {
|
43
|
-
return String.fromCharCode(parseInt(match[1], 16));
|
44
|
-
}
|
45
|
-
// eslint-disable-next-line no-cond-assign
|
46
|
-
if ((match = entityCode.match(/^#(\d+)$/))) {
|
47
|
-
// eslint-disable-next-line no-bitwise
|
48
|
-
return String.fromCharCode(~~match[1]);
|
49
|
-
}
|
50
|
-
return entity;
|
51
|
-
});
|
52
|
-
}
|
53
|
-
exports.unescapeHTML = unescapeHTML;
|
54
|
-
const filterForNumberOnly = (str) => str.replace(/\D+/g, "");
|
55
|
-
exports.filterForNumberOnly = filterForNumberOnly;
|
56
|
-
function isNumberOnly(str) {
|
57
|
-
const pattern = /^\d+$/;
|
58
|
-
return pattern.test(str);
|
59
|
-
}
|
60
|
-
exports.isNumberOnly = isNumberOnly;
|
61
|
-
function filterForInvalidCharacter(str, replaceCharacter = "_") {
|
62
|
-
let rs = str.replace(/[^\p{L}\s]/giu, " ");
|
63
|
-
rs = rs.trim();
|
64
|
-
rs = rs.replace(/ +/g, replaceCharacter);
|
65
|
-
return rs;
|
66
|
-
}
|
67
|
-
exports.filterForInvalidCharacter = filterForInvalidCharacter;
|
68
|
-
function filterNotNumberAndDivideChar(str) {
|
69
|
-
let rs = str.replace(/\D+/g, " ");
|
70
|
-
rs = rs.trim();
|
71
|
-
rs = rs.replace(/ +/g, ",");
|
72
|
-
return rs;
|
73
|
-
}
|
74
|
-
exports.filterNotNumberAndDivideChar = filterNotNumberAndDivideChar;
|
75
|
-
function stringNumberToList(str) {
|
76
|
-
return filterNotNumberAndDivideChar(str)
|
77
|
-
.split(/[ _\-,]/)
|
78
|
-
.filter((t) => (0, exports.hasText)(t))
|
79
|
-
.map((t) => Number(t));
|
80
|
-
}
|
81
|
-
exports.stringNumberToList = stringNumberToList;
|
82
|
-
function htmlEncode(rawStr) {
|
83
|
-
return rawStr.replace(/[\u00A0-\u9999<>&]/g, (i) => {
|
84
|
-
return `&#${i.charCodeAt(0)};`;
|
85
|
-
});
|
86
|
-
}
|
87
|
-
exports.htmlEncode = htmlEncode;
|
88
|
-
function filterNonAlphaNumeric(str) {
|
89
|
-
return str.replace(/\W/g, "");
|
90
|
-
}
|
91
|
-
exports.filterNonAlphaNumeric = filterNonAlphaNumeric;
|
92
|
-
const leftString = (string, count) => {
|
93
|
-
const str = `${string || ""}`;
|
94
|
-
if (str.length > count) {
|
95
|
-
return str.substring(0, count);
|
96
|
-
}
|
97
|
-
return str;
|
98
|
-
};
|
99
|
-
exports.leftString = leftString;
|
100
|
-
const rightString = (string, count) => {
|
101
|
-
const str = `${string || ""}`;
|
102
|
-
if (str.length > count) {
|
103
|
-
return str.substring(str.length - count);
|
104
|
-
}
|
105
|
-
return str;
|
106
|
-
};
|
107
|
-
exports.rightString = rightString;
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.rightString = exports.leftString = exports.filterNonAlphaNumeric = exports.htmlEncode = exports.stringNumberToList = exports.filterNotNumberAndDivideChar = exports.filterForInvalidCharacter = exports.isNumberOnly = exports.filterForNumberOnly = exports.unescapeHTML = exports.markKey = exports.hasText = exports.generateRandomCode = void 0;
|
4
|
+
function generateRandomCode(length) {
|
5
|
+
let text = "";
|
6
|
+
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
7
|
+
for (let i = 0; i < length; i += 1)
|
8
|
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
9
|
+
return text;
|
10
|
+
}
|
11
|
+
exports.generateRandomCode = generateRandomCode;
|
12
|
+
const hasText = (str) => {
|
13
|
+
const testStr = `${str || ""}`;
|
14
|
+
return !!str && testStr.length > 0;
|
15
|
+
};
|
16
|
+
exports.hasText = hasText;
|
17
|
+
function markKey(keyStr) {
|
18
|
+
return `**** ${keyStr.substring(keyStr.length - 4, keyStr.length)}`;
|
19
|
+
}
|
20
|
+
exports.markKey = markKey;
|
21
|
+
const htmlEntities = {
|
22
|
+
nbsp: " ",
|
23
|
+
cent: "¢",
|
24
|
+
pound: "£",
|
25
|
+
yen: "¥",
|
26
|
+
euro: "€",
|
27
|
+
copy: "©",
|
28
|
+
reg: "®",
|
29
|
+
lt: "<",
|
30
|
+
gt: ">",
|
31
|
+
quot: '"',
|
32
|
+
amp: "&",
|
33
|
+
apos: "'"
|
34
|
+
};
|
35
|
+
function unescapeHTML(str) {
|
36
|
+
return str.replace(/&([^;]+);/g, (entity, entityCode) => {
|
37
|
+
let match;
|
38
|
+
if (entityCode in htmlEntities) {
|
39
|
+
return htmlEntities[entityCode];
|
40
|
+
}
|
41
|
+
// eslint-disable-next-line no-cond-assign
|
42
|
+
if ((match = entityCode.match(/^#x([\da-fA-F]+)$/))) {
|
43
|
+
return String.fromCharCode(parseInt(match[1], 16));
|
44
|
+
}
|
45
|
+
// eslint-disable-next-line no-cond-assign
|
46
|
+
if ((match = entityCode.match(/^#(\d+)$/))) {
|
47
|
+
// eslint-disable-next-line no-bitwise
|
48
|
+
return String.fromCharCode(~~match[1]);
|
49
|
+
}
|
50
|
+
return entity;
|
51
|
+
});
|
52
|
+
}
|
53
|
+
exports.unescapeHTML = unescapeHTML;
|
54
|
+
const filterForNumberOnly = (str) => str.replace(/\D+/g, "");
|
55
|
+
exports.filterForNumberOnly = filterForNumberOnly;
|
56
|
+
function isNumberOnly(str) {
|
57
|
+
const pattern = /^\d+$/;
|
58
|
+
return pattern.test(str);
|
59
|
+
}
|
60
|
+
exports.isNumberOnly = isNumberOnly;
|
61
|
+
function filterForInvalidCharacter(str, replaceCharacter = "_") {
|
62
|
+
let rs = str.replace(/[^\p{L}\s]/giu, " ");
|
63
|
+
rs = rs.trim();
|
64
|
+
rs = rs.replace(/ +/g, replaceCharacter);
|
65
|
+
return rs;
|
66
|
+
}
|
67
|
+
exports.filterForInvalidCharacter = filterForInvalidCharacter;
|
68
|
+
function filterNotNumberAndDivideChar(str) {
|
69
|
+
let rs = str.replace(/\D+/g, " ");
|
70
|
+
rs = rs.trim();
|
71
|
+
rs = rs.replace(/ +/g, ",");
|
72
|
+
return rs;
|
73
|
+
}
|
74
|
+
exports.filterNotNumberAndDivideChar = filterNotNumberAndDivideChar;
|
75
|
+
function stringNumberToList(str) {
|
76
|
+
return filterNotNumberAndDivideChar(str)
|
77
|
+
.split(/[ _\-,]/)
|
78
|
+
.filter((t) => (0, exports.hasText)(t))
|
79
|
+
.map((t) => Number(t));
|
80
|
+
}
|
81
|
+
exports.stringNumberToList = stringNumberToList;
|
82
|
+
function htmlEncode(rawStr) {
|
83
|
+
return rawStr.replace(/[\u00A0-\u9999<>&]/g, (i) => {
|
84
|
+
return `&#${i.charCodeAt(0)};`;
|
85
|
+
});
|
86
|
+
}
|
87
|
+
exports.htmlEncode = htmlEncode;
|
88
|
+
function filterNonAlphaNumeric(str) {
|
89
|
+
return str.replace(/\W/g, "");
|
90
|
+
}
|
91
|
+
exports.filterNonAlphaNumeric = filterNonAlphaNumeric;
|
92
|
+
const leftString = (string, count) => {
|
93
|
+
const str = `${string || ""}`;
|
94
|
+
if (str.length > count) {
|
95
|
+
return str.substring(0, count);
|
96
|
+
}
|
97
|
+
return str;
|
98
|
+
};
|
99
|
+
exports.leftString = leftString;
|
100
|
+
const rightString = (string, count) => {
|
101
|
+
const str = `${string || ""}`;
|
102
|
+
if (str.length > count) {
|
103
|
+
return str.substring(str.length - count);
|
104
|
+
}
|
105
|
+
return str;
|
106
|
+
};
|
107
|
+
exports.rightString = rightString;
|
108
108
|
//# sourceMappingURL=string.util.js.map
|