getIddPrefix.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = getIddPrefix;
  6. var _metadata = _interopRequireDefault(require("../metadata.js"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  8. /**
  9. * Pattern that makes it easy to distinguish whether a region has a single
  10. * international dialing prefix or not. If a region has a single international
  11. * prefix (e.g. 011 in USA), it will be represented as a string that contains
  12. * a sequence of ASCII digits, and possibly a tilde, which signals waiting for
  13. * the tone. If there are multiple available international prefixes in a
  14. * region, they will be represented as a regex string that always contains one
  15. * or more characters that are not ASCII digits or a tilde.
  16. */
  17. var SINGLE_IDD_PREFIX_REG_EXP = /^[\d]+(?:[~\u2053\u223C\uFF5E][\d]+)?$/; // For regions that have multiple IDD prefixes
  18. // a preferred IDD prefix is returned.
  19. function getIddPrefix(country, callingCode, metadata) {
  20. var countryMetadata = new _metadata["default"](metadata);
  21. countryMetadata.selectNumberingPlan(country, callingCode);
  22. if (countryMetadata.defaultIDDPrefix()) {
  23. return countryMetadata.defaultIDDPrefix();
  24. }
  25. if (SINGLE_IDD_PREFIX_REG_EXP.test(countryMetadata.IDDPrefix())) {
  26. return countryMetadata.IDDPrefix();
  27. }
  28. }
  29. //# sourceMappingURL=getIddPrefix.js.map