stripIddPrefix.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = stripIddPrefix;
  6. var _metadata = _interopRequireDefault(require("../metadata.js"));
  7. var _constants = require("../constants.js");
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  9. var CAPTURING_DIGIT_PATTERN = new RegExp('([' + _constants.VALID_DIGITS + '])');
  10. function stripIddPrefix(number, country, callingCode, metadata) {
  11. if (!country) {
  12. return;
  13. } // Check if the number is IDD-prefixed.
  14. var countryMetadata = new _metadata["default"](metadata);
  15. countryMetadata.selectNumberingPlan(country, callingCode);
  16. var IDDPrefixPattern = new RegExp(countryMetadata.IDDPrefix());
  17. if (number.search(IDDPrefixPattern) !== 0) {
  18. return;
  19. } // Strip IDD prefix.
  20. number = number.slice(number.match(IDDPrefixPattern)[0].length); // If there're any digits after an IDD prefix,
  21. // then those digits are a country calling code.
  22. // Since no country code starts with a `0`,
  23. // the code below validates that the next digit (if present) is not `0`.
  24. var matchedGroups = number.match(CAPTURING_DIGIT_PATTERN);
  25. if (matchedGroups && matchedGroups[1] != null && matchedGroups[1].length > 0) {
  26. if (matchedGroups[1] === '0') {
  27. return;
  28. }
  29. }
  30. return number;
  31. }
  32. //# sourceMappingURL=stripIddPrefix.js.map