@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
package/dist/index.d.ts
CHANGED
|
@@ -695,13 +695,19 @@ declare function extractCountryCodeFromPhoneNumber(phoneNumber: string, country?
|
|
|
695
695
|
};
|
|
696
696
|
/**
|
|
697
697
|
* Formats a phone number by prepending the country code if not already present.
|
|
698
|
-
* If the number already starts with a known country code
|
|
699
|
-
*
|
|
698
|
+
* If the number already starts with a known country code (with or without the
|
|
699
|
+
* leading "+") it is returned unchanged except for the "+" being added when
|
|
700
|
+
* missing. Leading zeros, spaces and dashes are stripped from the local part
|
|
701
|
+
* before formatting.
|
|
700
702
|
*
|
|
701
703
|
* @example
|
|
702
|
-
* formatPhoneNumberWithCountryCode("77123456", "+221")
|
|
704
|
+
* formatPhoneNumberWithCountryCode("77123456", "+221") // "+22177123456"
|
|
703
705
|
* formatPhoneNumberWithCountryCode("+22177123456", "+221") // "+22177123456" (unchanged)
|
|
704
|
-
* formatPhoneNumberWithCountryCode("077123456", "+221")
|
|
706
|
+
* formatPhoneNumberWithCountryCode("077123456", "+221") // "+22177123456" (leading 0 stripped)
|
|
707
|
+
* formatPhoneNumberWithCountryCode("22177123456") // "+22177123456" (backend's
|
|
708
|
+
* // canonical digits-only
|
|
709
|
+
* // storage format — just add "+",
|
|
710
|
+
* // don't re-prepend the dial code)
|
|
705
711
|
*/
|
|
706
712
|
declare function formatPhoneNumberWithCountryCode(phoneNumber: string, countryCode?: string): string;
|
|
707
713
|
|
package/dist/index.esm.js
CHANGED
|
@@ -68,17 +68,19 @@ var SupportedCountry;
|
|
|
68
68
|
const REGIONS_BY_COUNTRY = {
|
|
69
69
|
[SupportedCountry.SENEGAL]: [
|
|
70
70
|
"Dakar",
|
|
71
|
-
"
|
|
72
|
-
"Saint-Louis",
|
|
73
|
-
"Louga",
|
|
71
|
+
"Diourbel",
|
|
74
72
|
"Fatick",
|
|
75
|
-
"
|
|
73
|
+
"Kaffrine", // missing in your list
|
|
74
|
+
"Kaolack", // missing in your list (spelling variant of Kaolac)
|
|
75
|
+
"Kédougou",
|
|
76
76
|
"Kolda",
|
|
77
|
-
"
|
|
77
|
+
"Louga",
|
|
78
78
|
"Matam",
|
|
79
|
-
"
|
|
79
|
+
"Saint-Louis",
|
|
80
80
|
"Sédhiou",
|
|
81
|
-
"
|
|
81
|
+
"Tambacounda",
|
|
82
|
+
"Thiès",
|
|
83
|
+
"Ziguinchor",
|
|
82
84
|
],
|
|
83
85
|
[SupportedCountry.CHAD]: [
|
|
84
86
|
"N'Djamena",
|
|
@@ -150,6 +152,17 @@ function extractCountryCodeFromPhoneNumber(phoneNumber, country) {
|
|
|
150
152
|
.trim();
|
|
151
153
|
return { countryCode: matched.code, cleanedPhoneNumber: cleaned };
|
|
152
154
|
}
|
|
155
|
+
// Same dial code, but without the leading "+" — e.g. the backend's canonical
|
|
156
|
+
// digits-only storage format ("221770000010" instead of "+221770000010").
|
|
157
|
+
// Without this check the caller below would treat the whole string (dial
|
|
158
|
+
// code digits included) as the local part.
|
|
159
|
+
const bareMatch = COUNTRY_CODES.find(({ code }) => phoneNumber.startsWith(code.slice(1)));
|
|
160
|
+
if (bareMatch) {
|
|
161
|
+
const cleaned = phoneNumber
|
|
162
|
+
.replace(new RegExp(`^${bareMatch.code.slice(1)}\\s*`), "")
|
|
163
|
+
.trim();
|
|
164
|
+
return { countryCode: bareMatch.code, cleanedPhoneNumber: cleaned };
|
|
165
|
+
}
|
|
153
166
|
return {
|
|
154
167
|
countryCode: getDefaultCountryCode(phoneNumber, country),
|
|
155
168
|
cleanedPhoneNumber: phoneNumber.trim(),
|
|
@@ -157,13 +170,19 @@ function extractCountryCodeFromPhoneNumber(phoneNumber, country) {
|
|
|
157
170
|
}
|
|
158
171
|
/**
|
|
159
172
|
* Formats a phone number by prepending the country code if not already present.
|
|
160
|
-
* If the number already starts with a known country code
|
|
161
|
-
*
|
|
173
|
+
* If the number already starts with a known country code (with or without the
|
|
174
|
+
* leading "+") it is returned unchanged except for the "+" being added when
|
|
175
|
+
* missing. Leading zeros, spaces and dashes are stripped from the local part
|
|
176
|
+
* before formatting.
|
|
162
177
|
*
|
|
163
178
|
* @example
|
|
164
|
-
* formatPhoneNumberWithCountryCode("77123456", "+221")
|
|
179
|
+
* formatPhoneNumberWithCountryCode("77123456", "+221") // "+22177123456"
|
|
165
180
|
* formatPhoneNumberWithCountryCode("+22177123456", "+221") // "+22177123456" (unchanged)
|
|
166
|
-
* formatPhoneNumberWithCountryCode("077123456", "+221")
|
|
181
|
+
* formatPhoneNumberWithCountryCode("077123456", "+221") // "+22177123456" (leading 0 stripped)
|
|
182
|
+
* formatPhoneNumberWithCountryCode("22177123456") // "+22177123456" (backend's
|
|
183
|
+
* // canonical digits-only
|
|
184
|
+
* // storage format — just add "+",
|
|
185
|
+
* // don't re-prepend the dial code)
|
|
167
186
|
*/
|
|
168
187
|
function formatPhoneNumberWithCountryCode(phoneNumber, countryCode = "+221") {
|
|
169
188
|
const trimmed = phoneNumber?.trim() || "";
|
|
@@ -173,6 +192,14 @@ function formatPhoneNumberWithCountryCode(phoneNumber, countryCode = "+221") {
|
|
|
173
192
|
if (COUNTRY_CODES.some(({ code }) => trimmed.startsWith(code))) {
|
|
174
193
|
return trimmed;
|
|
175
194
|
}
|
|
195
|
+
// Same dial code, but without the leading "+" (e.g. "221770000010", the
|
|
196
|
+
// backend's canonical digits-only storage format). Just add the "+" —
|
|
197
|
+
// re-prepending countryCode here would double the dial-code digits
|
|
198
|
+
// ("+221221770000010").
|
|
199
|
+
const bareMatch = COUNTRY_CODES.find(({ code }) => trimmed.startsWith(code.slice(1)));
|
|
200
|
+
if (bareMatch) {
|
|
201
|
+
return `+${trimmed}`;
|
|
202
|
+
}
|
|
176
203
|
// Strip leading zeros, spaces, dashes and + signs from the local part
|
|
177
204
|
const cleaned = trimmed.replace(/^[\s+0-]*/, "").trim();
|
|
178
205
|
if (!cleaned)
|