@peacom/core 0.0.6 → 0.0.8
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/package.json +8 -2
- package/src/lib/model/Message.d.ts +3 -2
- package/src/lib/util/file/file.util.d.ts +2 -0
- package/src/lib/util/file/file.util.js +19 -0
- package/src/lib/util/file/file.util.js.map +1 -0
- package/src/lib/util/index.d.ts +1 -0
- package/src/lib/util/index.js +1 -0
- package/src/lib/util/index.js.map +1 -1
- package/src/lib/util/phone.util.d.ts +12 -0
- package/src/lib/util/phone.util.js +38 -0
- package/src/lib/util/phone.util.js.map +1 -0
package/package.json
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
{
|
2
2
|
"name": "@peacom/core",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.8",
|
4
4
|
"type": "commonjs",
|
5
5
|
"dependencies": {
|
6
6
|
"moment": "^2.29.4",
|
7
|
-
"moment-timezone": "^0.5.40"
|
7
|
+
"moment-timezone": "^0.5.40",
|
8
|
+
"mime-types": "^2.1.35",
|
9
|
+
"google-libphonenumber": "^3.2.31"
|
10
|
+
},
|
11
|
+
"devDependencies": {
|
12
|
+
"@types/mime-types": "^2.1.1",
|
13
|
+
"@types/google-libphonenumber": "^7.4.23"
|
8
14
|
},
|
9
15
|
"main": "./src/index.js",
|
10
16
|
"types": "./src/index.d.ts",
|
@@ -40,9 +40,10 @@ export declare enum SuggestionActionType {
|
|
40
40
|
export interface FileInfo {
|
41
41
|
type: string;
|
42
42
|
name: string;
|
43
|
-
size: number;
|
44
43
|
url: string;
|
45
|
-
|
44
|
+
extension?: string;
|
45
|
+
size?: number;
|
46
|
+
uuid?: string;
|
46
47
|
preview?: string;
|
47
48
|
}
|
48
49
|
export interface RawMessageSuggestion {
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getFileInfoFromUrl = void 0;
|
4
|
+
const mime = require("mime-types");
|
5
|
+
const getFileInfoFromUrl = (url, defaultMimeType = "application/binary") => {
|
6
|
+
const rs = {
|
7
|
+
name: "",
|
8
|
+
type: defaultMimeType,
|
9
|
+
extension: ""
|
10
|
+
};
|
11
|
+
rs.name = new URL(url).pathname.split("/").pop() || url;
|
12
|
+
rs.extension = rs.name.split(".").pop();
|
13
|
+
if (rs.extension) {
|
14
|
+
rs.type = mime.lookup(rs.extension) || defaultMimeType;
|
15
|
+
}
|
16
|
+
return rs;
|
17
|
+
};
|
18
|
+
exports.getFileInfoFromUrl = getFileInfoFromUrl;
|
19
|
+
//# sourceMappingURL=file.util.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"file.util.js","sourceRoot":"","sources":["../../../../../../../packages/core/src/lib/util/file/file.util.ts"],"names":[],"mappings":";;;AAEA,mCAAoC;AAE7B,MAAM,kBAAkB,GAAG,CAChC,GAAW,EACX,eAAe,GAAG,oBAAoB,EAC5B,EAAE;IACZ,MAAM,EAAE,GAAG;QACT,IAAI,EAAE,EAAE;QACR,IAAI,EAAE,eAAe;QACrB,SAAS,EAAE,EAAE;KACF,CAAC;IAEd,EAAE,CAAC,IAAI,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,GAAG,CAAC;IACxD,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IACxC,IAAI,EAAE,CAAC,SAAS,EAAE;QAChB,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,eAAe,CAAC;KACxD;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAjBW,QAAA,kBAAkB,sBAiB7B"}
|
package/src/lib/util/index.d.ts
CHANGED
package/src/lib/util/index.js
CHANGED
@@ -4,4 +4,5 @@ const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./message/message.util"), exports);
|
5
5
|
tslib_1.__exportStar(require("./string.util"), exports);
|
6
6
|
tslib_1.__exportStar(require("./general.util"), exports);
|
7
|
+
tslib_1.__exportStar(require("./file/file.util"), exports);
|
7
8
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/util/index.ts"],"names":[],"mappings":";;;AAAA,iEAAsC;AACtC,wDAA6B;AAC7B,yDAA8B"}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/util/index.ts"],"names":[],"mappings":";;;AAAA,iEAAsC;AACtC,wDAA6B;AAC7B,yDAA8B;AAC9B,2DAAgC"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
export declare const DEFAULT_PHONE_COUNTRY = "VN";
|
2
|
+
export declare const PHONE_COUNTRY_SUPPORT: {
|
3
|
+
84: {
|
4
|
+
code: string;
|
5
|
+
};
|
6
|
+
};
|
7
|
+
export declare function isPhoneValid(phone: string, country?: string): {
|
8
|
+
countryCode: number | undefined;
|
9
|
+
nationalNumber: string;
|
10
|
+
e164: string;
|
11
|
+
network: number;
|
12
|
+
};
|
@@ -0,0 +1,38 @@
|
|
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 core_1 = require("@peacom/core");
|
6
|
+
const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
|
7
|
+
exports.DEFAULT_PHONE_COUNTRY = "VN";
|
8
|
+
exports.PHONE_COUNTRY_SUPPORT = {
|
9
|
+
84: {
|
10
|
+
code: "VN"
|
11
|
+
}
|
12
|
+
};
|
13
|
+
function isPhoneValid(phone, country = exports.DEFAULT_PHONE_COUNTRY) {
|
14
|
+
if (!phone || !(0, core_1.hasText)(phone)) {
|
15
|
+
throw new Error(`Invalid phone ${phone}`);
|
16
|
+
}
|
17
|
+
let _phone = phone;
|
18
|
+
const phone2Prefix = phone.substring(0, 2);
|
19
|
+
if (phone2Prefix !== "00") {
|
20
|
+
const phone1Prefix = phone[0];
|
21
|
+
if (phone1Prefix !== "0") {
|
22
|
+
_phone = `+${phone}`;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
const number = phoneUtil.parse(_phone, country);
|
26
|
+
const existPhone = phoneUtil.isValidNumber(number);
|
27
|
+
if (!existPhone) {
|
28
|
+
throw new Error(`Invalid phone ${phone}`);
|
29
|
+
}
|
30
|
+
return {
|
31
|
+
countryCode: number.getCountryCode(),
|
32
|
+
nationalNumber: `0${number.getNationalNumber()}`,
|
33
|
+
e164: `${number.getCountryCode()}${number.getNationalNumber()}`,
|
34
|
+
network: number.preferredDomesticCarrierCodeCount()
|
35
|
+
};
|
36
|
+
}
|
37
|
+
exports.isPhoneValid = isPhoneValid;
|
38
|
+
//# sourceMappingURL=phone.util.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"phone.util.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/util/phone.util.ts"],"names":[],"mappings":";;;AAAA,iEAAsD;AACtD,uCAAqC;AAErC,MAAM,SAAS,GAAG,uCAAe,CAAC,WAAW,EAAE,CAAC;AAEnC,QAAA,qBAAqB,GAAG,IAAI,CAAC;AAE7B,QAAA,qBAAqB,GAAG;IACnC,EAAE,EAAE;QACF,IAAI,EAAE,IAAI;KACX;CACF,CAAC;AAEF,SAAgB,YAAY,CAAC,KAAa,EAAE,OAAO,GAAG,6BAAqB;IACzE,IAAI,CAAC,KAAK,IAAI,CAAC,IAAA,cAAO,EAAC,KAAK,CAAC,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,iBAAiB,KAAK,EAAE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