getCountryByCallingCode.js 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. import getCountryByNationalNumber from './getCountryByNationalNumber.js';
  2. var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
  3. export default function getCountryByCallingCode(callingCode, _ref) {
  4. var nationalPhoneNumber = _ref.nationalNumber,
  5. defaultCountry = _ref.defaultCountry,
  6. metadata = _ref.metadata;
  7. /* istanbul ignore if */
  8. if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
  9. if (metadata.isNonGeographicCallingCode(callingCode)) {
  10. return '001';
  11. }
  12. }
  13. var possibleCountries = metadata.getCountryCodesForCallingCode(callingCode);
  14. if (!possibleCountries) {
  15. return;
  16. } // If there's just one country corresponding to the country code,
  17. // then just return it, without further phone number digits validation.
  18. if (possibleCountries.length === 1) {
  19. return possibleCountries[0];
  20. }
  21. return getCountryByNationalNumber(nationalPhoneNumber, {
  22. countries: possibleCountries,
  23. defaultCountry: defaultCountry,
  24. metadata: metadata.metadata
  25. });
  26. }
  27. //# sourceMappingURL=getCountryByCallingCode.js.map