getIddPrefix.js 1.1 KB

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