getCountryByCallingCode.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = getCountryByCallingCode;
  6. var _getCountryByNationalNumber = _interopRequireDefault(require("./getCountryByNationalNumber.js"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  8. var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
  9. function getCountryByCallingCode(callingCode, _ref) {
  10. var nationalPhoneNumber = _ref.nationalNumber,
  11. defaultCountry = _ref.defaultCountry,
  12. metadata = _ref.metadata;
  13. /* istanbul ignore if */
  14. if (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {
  15. if (metadata.isNonGeographicCallingCode(callingCode)) {
  16. return '001';
  17. }
  18. }
  19. var possibleCountries = metadata.getCountryCodesForCallingCode(callingCode);
  20. if (!possibleCountries) {
  21. return;
  22. } // If there's just one country corresponding to the country code,
  23. // then just return it, without further phone number digits validation.
  24. if (possibleCountries.length === 1) {
  25. return possibleCountries[0];
  26. }
  27. return (0, _getCountryByNationalNumber["default"])(nationalPhoneNumber, {
  28. countries: possibleCountries,
  29. defaultCountry: defaultCountry,
  30. metadata: metadata.metadata
  31. });
  32. }
  33. //# sourceMappingURL=getCountryByCallingCode.js.map