UNPKG

react-native-phone-country-picker-input

Version:
57 lines (56 loc) 2.31 kB
// phonePickerUtils.ts import { Countries } from './data/CountryList'; /** * Get ISO code by dial code * @param dialCode Country dial code (e.g., '+1') * @returns {string | undefined } - ISO2 code (e.g., 'US') or undefined if not found */ export const getIsoCode = (dialCode) => { var _a; return (_a = Countries.find((country) => country.dialCode === dialCode)) === null || _a === void 0 ? void 0 : _a.iso2; }; /** * Get dial code by ISO code * @param isoCode Country ISO2 code (e.g., 'US') * @returns {string | undefined} - Dial code (e.g., '+1') or undefined if not found */ export const getDialCode = (isoCode) => { var _a; return (_a = Countries.find((country) => country.iso2 === isoCode)) === null || _a === void 0 ? void 0 : _a.dialCode; }; /** * Get country flag by dial code or ISO code * @param identifier Country dial code (e.g., '+1') or ISO2 code (e.g., 'US') * @returns {string | undefined} - Flag emoji (e.g., '🇺🇸') or undefined if not found */ export const getCountryFlag = (identifier) => { var _a; return (_a = Countries.find((country) => country.dialCode === identifier || country.iso2.toLowerCase() === identifier.toLowerCase())) === null || _a === void 0 ? void 0 : _a.flag; }; /** * Get country name by dial code or ISO code * @param identifier Country dial code (e.g., '+1') or ISO code (e.g., 'US') * @returns {string | undefined} - Country name (e.g., 'United States') or undefined if not found */ export const getCountryName = (identifier) => { var _a; return (_a = Countries.find((country) => country.dialCode === identifier || country.iso2.toLowerCase() === identifier.toLowerCase())) === null || _a === void 0 ? void 0 : _a.name; }; /** * Get country object by dial code or ISO code * @param identifier Country dial code (e.g., '+1') or ISO code (e.g., 'US') * @returns {Country | undefined} - Country object or undefined if not found */ export const getCountryObject = (identifier) => { return Countries.find((country) => country.dialCode === identifier || country.iso2.toLowerCase() === identifier.toLowerCase()); }; /** * Returns an array of all countries in the world * @returns {Country[]} - Array of country objects */ export const getAllCountries = () => { return Countries; };