@ews-admin/global-design-system 1.22.1 → 1.24.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.
- package/dist/index.d.ts +10 -4
- package/dist/index.esm.js +38 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +38 -11
- package/dist/index.js.map +1 -1
- package/dist/utils/locations.d.ts.map +1 -1
- package/dist/utils/phone.d.ts +10 -4
- package/dist/utils/phone.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/utils/locations.ts +16 -14
- package/src/utils/phone.ts +36 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locations.d.ts","sourceRoot":"","sources":["../../src/utils/locations.ts"],"names":[],"mappings":"AAAA,oBAAY,gBAAgB;IAC1B,OAAO,YAAY;IACnB,IAAI,SAAS;CACd;
|
|
1
|
+
{"version":3,"file":"locations.d.ts","sourceRoot":"","sources":["../../src/utils/locations.ts"],"names":[],"mappings":"AAAA,oBAAY,gBAAgB;IAC1B,OAAO,YAAY;IACnB,IAAI,SAAS;CACd;AAgCD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAG7D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,CAKpF"}
|
package/dist/utils/phone.d.ts
CHANGED
|
@@ -36,13 +36,19 @@ export declare function extractCountryCodeFromPhoneNumber(phoneNumber: string, c
|
|
|
36
36
|
};
|
|
37
37
|
/**
|
|
38
38
|
* Formats a phone number by prepending the country code if not already present.
|
|
39
|
-
* If the number already starts with a known country code
|
|
40
|
-
*
|
|
39
|
+
* If the number already starts with a known country code (with or without the
|
|
40
|
+
* leading "+") it is returned unchanged except for the "+" being added when
|
|
41
|
+
* missing. Leading zeros, spaces and dashes are stripped from the local part
|
|
42
|
+
* before formatting.
|
|
41
43
|
*
|
|
42
44
|
* @example
|
|
43
|
-
* formatPhoneNumberWithCountryCode("77123456", "+221")
|
|
45
|
+
* formatPhoneNumberWithCountryCode("77123456", "+221") // "+22177123456"
|
|
44
46
|
* formatPhoneNumberWithCountryCode("+22177123456", "+221") // "+22177123456" (unchanged)
|
|
45
|
-
* formatPhoneNumberWithCountryCode("077123456", "+221")
|
|
47
|
+
* formatPhoneNumberWithCountryCode("077123456", "+221") // "+22177123456" (leading 0 stripped)
|
|
48
|
+
* formatPhoneNumberWithCountryCode("22177123456") // "+22177123456" (backend's
|
|
49
|
+
* // canonical digits-only
|
|
50
|
+
* // storage format — just add "+",
|
|
51
|
+
* // don't re-prepend the dial code)
|
|
46
52
|
*/
|
|
47
53
|
export declare function formatPhoneNumberWithCountryCode(phoneNumber: string, countryCode?: string): string;
|
|
48
54
|
//# sourceMappingURL=phone.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phone.d.ts","sourceRoot":"","sources":["../../src/utils/phone.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,iBAAiB,EAG5C,CAAC;AAEF;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,CAgBR;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,MAAM,GACf;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"phone.d.ts","sourceRoot":"","sources":["../../src/utils/phone.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,iBAAiB,EAG5C,CAAC;AAEF;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,CAgBR;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,MAAM,GACf;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAA;CAAE,CA+BrD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gCAAgC,CAC9C,WAAW,EAAE,MAAM,EACnB,WAAW,GAAE,MAAe,GAC3B,MAAM,CA2BR"}
|
package/package.json
CHANGED
package/src/utils/locations.ts
CHANGED
|
@@ -4,20 +4,22 @@ export enum SupportedCountry {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
const REGIONS_BY_COUNTRY: Record<string, string[]> = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
[SupportedCountry.SENEGAL]: [
|
|
8
|
+
"Dakar",
|
|
9
|
+
"Diourbel",
|
|
10
|
+
"Fatick",
|
|
11
|
+
"Kaffrine", // missing in your list
|
|
12
|
+
"Kaolack", // missing in your list (spelling variant of Kaolac)
|
|
13
|
+
"Kédougou",
|
|
14
|
+
"Kolda",
|
|
15
|
+
"Louga",
|
|
16
|
+
"Matam",
|
|
17
|
+
"Saint-Louis",
|
|
18
|
+
"Sédhiou",
|
|
19
|
+
"Tambacounda",
|
|
20
|
+
"Thiès",
|
|
21
|
+
"Ziguinchor",
|
|
22
|
+
],
|
|
21
23
|
[SupportedCountry.CHAD]: [
|
|
22
24
|
"N'Djamena",
|
|
23
25
|
"Moundou",
|
package/src/utils/phone.ts
CHANGED
|
@@ -71,6 +71,21 @@ export function extractCountryCodeFromPhoneNumber(
|
|
|
71
71
|
return { countryCode: matched.code, cleanedPhoneNumber: cleaned };
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
// Same dial code, but without the leading "+" — e.g. the backend's canonical
|
|
75
|
+
// digits-only storage format ("221770000010" instead of "+221770000010").
|
|
76
|
+
// Without this check the caller below would treat the whole string (dial
|
|
77
|
+
// code digits included) as the local part.
|
|
78
|
+
const bareMatch = COUNTRY_CODES.find(({ code }) =>
|
|
79
|
+
phoneNumber.startsWith(code.slice(1))
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
if (bareMatch) {
|
|
83
|
+
const cleaned = phoneNumber
|
|
84
|
+
.replace(new RegExp(`^${bareMatch.code.slice(1)}\\s*`), "")
|
|
85
|
+
.trim();
|
|
86
|
+
return { countryCode: bareMatch.code, cleanedPhoneNumber: cleaned };
|
|
87
|
+
}
|
|
88
|
+
|
|
74
89
|
return {
|
|
75
90
|
countryCode: getDefaultCountryCode(phoneNumber, country),
|
|
76
91
|
cleanedPhoneNumber: phoneNumber.trim(),
|
|
@@ -79,13 +94,19 @@ export function extractCountryCodeFromPhoneNumber(
|
|
|
79
94
|
|
|
80
95
|
/**
|
|
81
96
|
* Formats a phone number by prepending the country code if not already present.
|
|
82
|
-
* If the number already starts with a known country code
|
|
83
|
-
*
|
|
97
|
+
* If the number already starts with a known country code (with or without the
|
|
98
|
+
* leading "+") it is returned unchanged except for the "+" being added when
|
|
99
|
+
* missing. Leading zeros, spaces and dashes are stripped from the local part
|
|
100
|
+
* before formatting.
|
|
84
101
|
*
|
|
85
102
|
* @example
|
|
86
|
-
* formatPhoneNumberWithCountryCode("77123456", "+221")
|
|
103
|
+
* formatPhoneNumberWithCountryCode("77123456", "+221") // "+22177123456"
|
|
87
104
|
* formatPhoneNumberWithCountryCode("+22177123456", "+221") // "+22177123456" (unchanged)
|
|
88
|
-
* formatPhoneNumberWithCountryCode("077123456", "+221")
|
|
105
|
+
* formatPhoneNumberWithCountryCode("077123456", "+221") // "+22177123456" (leading 0 stripped)
|
|
106
|
+
* formatPhoneNumberWithCountryCode("22177123456") // "+22177123456" (backend's
|
|
107
|
+
* // canonical digits-only
|
|
108
|
+
* // storage format — just add "+",
|
|
109
|
+
* // don't re-prepend the dial code)
|
|
89
110
|
*/
|
|
90
111
|
export function formatPhoneNumberWithCountryCode(
|
|
91
112
|
phoneNumber: string,
|
|
@@ -100,6 +121,17 @@ export function formatPhoneNumberWithCountryCode(
|
|
|
100
121
|
return trimmed;
|
|
101
122
|
}
|
|
102
123
|
|
|
124
|
+
// Same dial code, but without the leading "+" (e.g. "221770000010", the
|
|
125
|
+
// backend's canonical digits-only storage format). Just add the "+" —
|
|
126
|
+
// re-prepending countryCode here would double the dial-code digits
|
|
127
|
+
// ("+221221770000010").
|
|
128
|
+
const bareMatch = COUNTRY_CODES.find(({ code }) =>
|
|
129
|
+
trimmed.startsWith(code.slice(1))
|
|
130
|
+
);
|
|
131
|
+
if (bareMatch) {
|
|
132
|
+
return `+${trimmed}`;
|
|
133
|
+
}
|
|
134
|
+
|
|
103
135
|
// Strip leading zeros, spaces, dashes and + signs from the local part
|
|
104
136
|
const cleaned = trimmed.replace(/^[\s+0-]*/, "").trim();
|
|
105
137
|
|