mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-31 19:42:15 +00:00
* fix: country flag and phone now in sync * change default country --------- Co-authored-by: Elio Bischof <[email protected]> Co-authored-by: Elio Bischof <[email protected]>
20 lines
514 B
TypeScript
20 lines
514 B
TypeScript
import { CountryCode, parsePhoneNumber } from 'libphonenumber-js';
|
|
|
|
export function formatPhone(phone: string): { phone: string; country: CountryCode } | null {
|
|
const defaultCountry = 'US';
|
|
|
|
if (phone) {
|
|
try {
|
|
const phoneNumber = parsePhoneNumber(phone, defaultCountry);
|
|
const country = phoneNumber.country ?? defaultCountry;
|
|
if (phoneNumber) {
|
|
return { phone: phoneNumber.formatInternational(), country };
|
|
}
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|