2023-08-29 10:01:28 +02:00
|
|
|
import {
|
|
|
|
|
CountryCode,
|
|
|
|
|
findPhoneNumbersInText,
|
|
|
|
|
isSupportedCountry,
|
|
|
|
|
} from 'libphonenumber-js'
|
2022-12-22 17:02:34 +01:00
|
|
|
|
2023-08-29 10:01:28 +02:00
|
|
|
export const formatPhoneNumber = (
|
|
|
|
|
phoneNumber: string,
|
|
|
|
|
defaultCountryCode?: string
|
|
|
|
|
) =>
|
|
|
|
|
findPhoneNumbersInText(
|
|
|
|
|
phoneNumber,
|
|
|
|
|
defaultCountryCode && isSupportedCountry(defaultCountryCode)
|
|
|
|
|
? (defaultCountryCode as CountryCode)
|
|
|
|
|
: undefined
|
|
|
|
|
).at(0)?.number.number
|