21 lines
651 B
TypeScript
21 lines
651 B
TypeScript
import { CountryCode } from "libphonenumber-js";
|
|
import { Country } from "@/components/PhoneInput/types";
|
|
import countryOptionsDataMap from "@/components/PhoneInput/utils/countryOptionsDataMap";
|
|
import getPhoneMask from "@/components/PhoneInput/utils/getPhoneMask";
|
|
|
|
type InitialDataFromValue = {
|
|
country: Country;
|
|
format: ReturnType<typeof getPhoneMask>;
|
|
};
|
|
|
|
const getInitialDataFromValue = (
|
|
initialCountryCode: string
|
|
): InitialDataFromValue => {
|
|
return {
|
|
country: countryOptionsDataMap[initialCountryCode],
|
|
format: getPhoneMask(initialCountryCode as CountryCode),
|
|
};
|
|
};
|
|
|
|
export default getInitialDataFromValue;
|