@appcorp/fusion-storybook 0.1.74 → 0.1.76

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.
@@ -0,0 +1,2 @@
1
+ export declare function normalizePhone(value: unknown): string | null | undefined;
2
+ export declare function formatPhoneDisplay(value: unknown): string | undefined;
@@ -0,0 +1,28 @@
1
+ export function normalizePhone(value) {
2
+ if (value === null)
3
+ return null;
4
+ if (typeof value !== "string")
5
+ return undefined;
6
+ return value.replace(/\D/g, "");
7
+ }
8
+ export function formatPhoneDisplay(value) {
9
+ const digits = normalizePhone(value);
10
+ if (!digits)
11
+ return undefined;
12
+ if (digits.length === 12 && digits.startsWith("92")) {
13
+ return `+92 ${digits.slice(2, 5)} ${digits.slice(5)}`;
14
+ }
15
+ if (digits.length === 11 && digits.startsWith("0")) {
16
+ return `0${digits.slice(1, 4)} ${digits.slice(4, 7)} ${digits.slice(7)}`;
17
+ }
18
+ if (digits.length === 11 && digits.startsWith("1")) {
19
+ return `+1 (${digits.slice(1, 4)}) ${digits.slice(4, 7)}-${digits.slice(7)}`;
20
+ }
21
+ if (digits.length === 10) {
22
+ return `${digits.slice(0, 3)} ${digits.slice(3, 6)} ${digits.slice(6)}`;
23
+ }
24
+ if (digits.length > 12) {
25
+ return `+${digits}`;
26
+ }
27
+ return digits;
28
+ }