mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-20 06:55:06 -04:00
fix(phone-parser): use default country code
This commit is contained in:
parent
83a7b3bae9
commit
a43c546e34
2 changed files with 4 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
|||
import type { NumberType } from 'libphonenumber-js/types';
|
||||
import type { CountryCode, NumberType } from 'libphonenumber-js/types';
|
||||
import lookup from 'country-code-lookup';
|
||||
|
||||
export { formatTypeToHumanReadable, getFullCountryName, getDefaultCountryCode };
|
||||
|
@ -32,10 +32,10 @@ function getFullCountryName(countryCode: string | undefined) {
|
|||
function getDefaultCountryCode({
|
||||
locale = window.navigator.language,
|
||||
defaultCode = 'FR',
|
||||
}: { locale?: string; defaultCode?: string } = {}): string {
|
||||
}: { locale?: string; defaultCode?: CountryCode } = {}): CountryCode {
|
||||
const countryCode = locale.split('-')[1]?.toUpperCase();
|
||||
|
||||
if (!countryCode) return defaultCode;
|
||||
|
||||
return lookup.byIso(countryCode)?.iso2 ?? defaultCode;
|
||||
return (lookup.byIso(countryCode)?.iso2 ?? defaultCode) as CountryCode;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ const validation = useValidation({
|
|||
const parsedDetails = computed(() => {
|
||||
if (!validation.isValid) return undefined;
|
||||
|
||||
const parsed = withDefaultOnError(() => parsePhoneNumber(rawPhone.value, 'FR'), undefined);
|
||||
const parsed = withDefaultOnError(() => parsePhoneNumber(rawPhone.value, defaultCountryCode.value), undefined);
|
||||
|
||||
if (!parsed) return undefined;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue