@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.js
CHANGED
|
@@ -88,17 +88,19 @@ exports.SupportedCountry = void 0;
|
|
|
88
88
|
const REGIONS_BY_COUNTRY = {
|
|
89
89
|
[exports.SupportedCountry.SENEGAL]: [
|
|
90
90
|
"Dakar",
|
|
91
|
-
"
|
|
92
|
-
"Saint-Louis",
|
|
93
|
-
"Louga",
|
|
91
|
+
"Diourbel",
|
|
94
92
|
"Fatick",
|
|
95
|
-
"
|
|
93
|
+
"Kaffrine", // missing in your list
|
|
94
|
+
"Kaolack", // missing in your list (spelling variant of Kaolac)
|
|
95
|
+
"Kédougou",
|
|
96
96
|
"Kolda",
|
|
97
|
-
"
|
|
97
|
+
"Louga",
|
|
98
98
|
"Matam",
|
|
99
|
-
"
|
|
99
|
+
"Saint-Louis",
|
|
100
100
|
"Sédhiou",
|
|
101
|
-
"
|
|
101
|
+
"Tambacounda",
|
|
102
|
+
"Thiès",
|
|
103
|
+
"Ziguinchor",
|
|
102
104
|
],
|
|
103
105
|
[exports.SupportedCountry.CHAD]: [
|
|
104
106
|
"N'Djamena",
|
|
@@ -170,6 +172,17 @@ function extractCountryCodeFromPhoneNumber(phoneNumber, country) {
|
|
|
170
172
|
.trim();
|
|
171
173
|
return { countryCode: matched.code, cleanedPhoneNumber: cleaned };
|
|
172
174
|
}
|
|
175
|
+
// Same dial code, but without the leading "+" — e.g. the backend's canonical
|
|
176
|
+
// digits-only storage format ("221770000010" instead of "+221770000010").
|
|
177
|
+
// Without this check the caller below would treat the whole string (dial
|
|
178
|
+
// code digits included) as the local part.
|
|
179
|
+
const bareMatch = COUNTRY_CODES.find(({ code }) => phoneNumber.startsWith(code.slice(1)));
|
|
180
|
+
if (bareMatch) {
|
|
181
|
+
const cleaned = phoneNumber
|
|
182
|
+
.replace(new RegExp(`^${bareMatch.code.slice(1)}\\s*`), "")
|
|
183
|
+
.trim();
|
|
184
|
+
return { countryCode: bareMatch.code, cleanedPhoneNumber: cleaned };
|
|
185
|
+
}
|
|
173
186
|
return {
|
|
174
187
|
countryCode: getDefaultCountryCode(phoneNumber, country),
|
|
175
188
|
cleanedPhoneNumber: phoneNumber.trim(),
|
|
@@ -177,13 +190,19 @@ function extractCountryCodeFromPhoneNumber(phoneNumber, country) {
|
|
|
177
190
|
}
|
|
178
191
|
/**
|
|
179
192
|
* Formats a phone number by prepending the country code if not already present.
|
|
180
|
-
* If the number already starts with a known country code
|
|
181
|
-
*
|
|
193
|
+
* If the number already starts with a known country code (with or without the
|
|
194
|
+
* leading "+") it is returned unchanged except for the "+" being added when
|
|
195
|
+
* missing. Leading zeros, spaces and dashes are stripped from the local part
|
|
196
|
+
* before formatting.
|
|
182
197
|
*
|
|
183
198
|
* @example
|
|
184
|
-
* formatPhoneNumberWithCountryCode("77123456", "+221")
|
|
199
|
+
* formatPhoneNumberWithCountryCode("77123456", "+221") // "+22177123456"
|
|
185
200
|
* formatPhoneNumberWithCountryCode("+22177123456", "+221") // "+22177123456" (unchanged)
|
|
186
|
-
* formatPhoneNumberWithCountryCode("077123456", "+221")
|
|
201
|
+
* formatPhoneNumberWithCountryCode("077123456", "+221") // "+22177123456" (leading 0 stripped)
|
|
202
|
+
* formatPhoneNumberWithCountryCode("22177123456") // "+22177123456" (backend's
|
|
203
|
+
* // canonical digits-only
|
|
204
|
+
* // storage format — just add "+",
|
|
205
|
+
* // don't re-prepend the dial code)
|
|
187
206
|
*/
|
|
188
207
|
function formatPhoneNumberWithCountryCode(phoneNumber, countryCode = "+221") {
|
|
189
208
|
const trimmed = phoneNumber?.trim() || "";
|
|
@@ -193,6 +212,14 @@ function formatPhoneNumberWithCountryCode(phoneNumber, countryCode = "+221") {
|
|
|
193
212
|
if (COUNTRY_CODES.some(({ code }) => trimmed.startsWith(code))) {
|
|
194
213
|
return trimmed;
|
|
195
214
|
}
|
|
215
|
+
// Same dial code, but without the leading "+" (e.g. "221770000010", the
|
|
216
|
+
// backend's canonical digits-only storage format). Just add the "+" —
|
|
217
|
+
// re-prepending countryCode here would double the dial-code digits
|
|
218
|
+
// ("+221221770000010").
|
|
219
|
+
const bareMatch = COUNTRY_CODES.find(({ code }) => trimmed.startsWith(code.slice(1)));
|
|
220
|
+
if (bareMatch) {
|
|
221
|
+
return `+${trimmed}`;
|
|
222
|
+
}
|
|
196
223
|
// Strip leading zeros, spaces, dashes and + signs from the local part
|
|
197
224
|
const cleaned = trimmed.replace(/^[\s+0-]*/, "").trim();
|
|
198
225
|
if (!cleaned)
|