@heavybit/pendoadmin-shared-lib 1.1.9 → 1.2.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.
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
export declare function normalizePhoneNumber(phone: string, defaultCountry?: string): string;
|
|
2
2
|
export declare function isValidPhoneNumber(phone: string, defaultCountry?: string): boolean;
|
|
3
3
|
export declare function formatPhoneNumber(phone: string, format?: 'e164' | 'international' | 'national', defaultCountry?: string): string;
|
|
4
|
+
/**
|
|
5
|
+
* WhatsApp Cloud API format: E.164 without leading '+'.
|
|
6
|
+
* E.g. '+254712345678' -> '254712345678'.
|
|
7
|
+
*/
|
|
8
|
+
export declare function toWhatsAppFormat(phone: string, defaultCountry?: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Normalise a phone number to a plain MSISDN (no '+'), suitable for DB storage.
|
|
11
|
+
* E.g. '+254712345678' | '0712345678' | '254712345678' → '254712345678'.
|
|
12
|
+
*
|
|
13
|
+
* Uses libphonenumber to extract the numeric country code and national number,
|
|
14
|
+
* then concatenates them — no manual string slicing.
|
|
15
|
+
* Falls back to stripping non-digits if parsing fails.
|
|
16
|
+
*/
|
|
17
|
+
export declare function toMsisdn(phone: string, defaultCountry?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Return the ISO 3166-1 alpha-2 region code for a phone number.
|
|
20
|
+
* E.g. '0712345678' → 'KE', '+447911123456' → 'GB'.
|
|
21
|
+
*
|
|
22
|
+
* Falls back to `defaultCountry` if parsing fails.
|
|
23
|
+
*/
|
|
24
|
+
export declare function extractPhoneRegion(phone: string, defaultCountry?: string): string;
|
|
4
25
|
//# sourceMappingURL=phone.utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phone.utils.d.ts","sourceRoot":"","sources":["../../src/common/phone.utils.ts"],"names":[],"mappings":"AAKA,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,GAAE,MAAa,GAAG,MAAM,CAOzF;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,GAAE,MAAa,GAAG,OAAO,CAOxF;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,GAAG,eAAe,GAAG,UAAmB,EAAE,cAAc,GAAE,MAAa,GAAG,MAAM,CAY9I"}
|
|
1
|
+
{"version":3,"file":"phone.utils.d.ts","sourceRoot":"","sources":["../../src/common/phone.utils.ts"],"names":[],"mappings":"AAKA,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,GAAE,MAAa,GAAG,MAAM,CAOzF;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,GAAE,MAAa,GAAG,OAAO,CAOxF;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,GAAG,eAAe,GAAG,UAAmB,EAAE,cAAc,GAAE,MAAa,GAAG,MAAM,CAY9I;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,GAAE,MAAa,GAAG,MAAM,CAGrF;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,GAAE,MAAa,GAAG,MAAM,CAO7E;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,GAAE,MAAa,GAAG,MAAM,CAOvF"}
|
|
@@ -33,4 +33,44 @@ export function formatPhoneNumber(phone, format = 'e164', defaultCountry = 'KE')
|
|
|
33
33
|
return phone;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* WhatsApp Cloud API format: E.164 without leading '+'.
|
|
38
|
+
* E.g. '+254712345678' -> '254712345678'.
|
|
39
|
+
*/
|
|
40
|
+
export function toWhatsAppFormat(phone, defaultCountry = 'KE') {
|
|
41
|
+
const e164 = normalizePhoneNumber(phone, defaultCountry);
|
|
42
|
+
return e164.startsWith('+') ? e164.slice(1) : e164;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Normalise a phone number to a plain MSISDN (no '+'), suitable for DB storage.
|
|
46
|
+
* E.g. '+254712345678' | '0712345678' | '254712345678' → '254712345678'.
|
|
47
|
+
*
|
|
48
|
+
* Uses libphonenumber to extract the numeric country code and national number,
|
|
49
|
+
* then concatenates them — no manual string slicing.
|
|
50
|
+
* Falls back to stripping non-digits if parsing fails.
|
|
51
|
+
*/
|
|
52
|
+
export function toMsisdn(phone, defaultCountry = 'KE') {
|
|
53
|
+
try {
|
|
54
|
+
const parsed = phoneUtil.parse(phone, defaultCountry);
|
|
55
|
+
return `${parsed.getCountryCode()}${parsed.getNationalNumber()}`;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return String(phone).replace(/\D/g, '');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Return the ISO 3166-1 alpha-2 region code for a phone number.
|
|
63
|
+
* E.g. '0712345678' → 'KE', '+447911123456' → 'GB'.
|
|
64
|
+
*
|
|
65
|
+
* Falls back to `defaultCountry` if parsing fails.
|
|
66
|
+
*/
|
|
67
|
+
export function extractPhoneRegion(phone, defaultCountry = 'KE') {
|
|
68
|
+
try {
|
|
69
|
+
const parsed = phoneUtil.parse(phone, defaultCountry);
|
|
70
|
+
return phoneUtil.getRegionCodeForNumber(parsed) ?? defaultCountry;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return defaultCountry;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
36
76
|
//# sourceMappingURL=phone.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phone.utils.js","sourceRoot":"","sources":["../../src/common/phone.utils.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,u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D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa,EAAE,iBAAyB,IAAI;IAC3E,MAAM,IAAI,GAAG,oBAAoB,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IACzD,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACrD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa,EAAE,iBAAyB,IAAI;IACnE,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;QACtD,OAAO,GAAG,MAAM,CAAC,cAAc,EAAE,GAAG,MAAM,CAAC,iBAAiB,EAAE,EAAE,CAAC;IACnE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa,EAAE,iBAAyB,IAAI;IAC7E,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;QACtD,OAAO,SAAS,CAAC,sBAAsB,CAAC,MAAM,CAAC,IAAI,cAAc,CAAC;IACpE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,cAAc,CAAC;IACxB,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -34,3 +34,44 @@ export function formatPhoneNumber(phone: string, format: 'e164' | 'international
|
|
|
34
34
|
return phone;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* WhatsApp Cloud API format: E.164 without leading '+'.
|
|
40
|
+
* E.g. '+254712345678' -> '254712345678'.
|
|
41
|
+
*/
|
|
42
|
+
export function toWhatsAppFormat(phone: string, defaultCountry: string = 'KE'): string {
|
|
43
|
+
const e164 = normalizePhoneNumber(phone, defaultCountry);
|
|
44
|
+
return e164.startsWith('+') ? e164.slice(1) : e164;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Normalise a phone number to a plain MSISDN (no '+'), suitable for DB storage.
|
|
49
|
+
* E.g. '+254712345678' | '0712345678' | '254712345678' → '254712345678'.
|
|
50
|
+
*
|
|
51
|
+
* Uses libphonenumber to extract the numeric country code and national number,
|
|
52
|
+
* then concatenates them — no manual string slicing.
|
|
53
|
+
* Falls back to stripping non-digits if parsing fails.
|
|
54
|
+
*/
|
|
55
|
+
export function toMsisdn(phone: string, defaultCountry: string = 'KE'): string {
|
|
56
|
+
try {
|
|
57
|
+
const parsed = phoneUtil.parse(phone, defaultCountry);
|
|
58
|
+
return `${parsed.getCountryCode()}${parsed.getNationalNumber()}`;
|
|
59
|
+
} catch {
|
|
60
|
+
return String(phone).replace(/\D/g, '');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Return the ISO 3166-1 alpha-2 region code for a phone number.
|
|
66
|
+
* E.g. '0712345678' → 'KE', '+447911123456' → 'GB'.
|
|
67
|
+
*
|
|
68
|
+
* Falls back to `defaultCountry` if parsing fails.
|
|
69
|
+
*/
|
|
70
|
+
export function extractPhoneRegion(phone: string, defaultCountry: string = 'KE'): string {
|
|
71
|
+
try {
|
|
72
|
+
const parsed = phoneUtil.parse(phone, defaultCountry);
|
|
73
|
+
return phoneUtil.getRegionCodeForNumber(parsed) ?? defaultCountry;
|
|
74
|
+
} catch {
|
|
75
|
+
return defaultCountry;
|
|
76
|
+
}
|
|
77
|
+
}
|