extractExtension.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. import createExtensionPattern from './createExtensionPattern.js'; // Regexp of all known extension prefixes used by different regions followed by
  2. // 1 or more valid digits, for use when parsing.
  3. var EXTN_PATTERN = new RegExp('(?:' + createExtensionPattern() + ')$', 'i'); // Strips any extension (as in, the part of the number dialled after the call is
  4. // connected, usually indicated with extn, ext, x or similar) from the end of
  5. // the number, and returns it.
  6. export default function extractExtension(number) {
  7. var start = number.search(EXTN_PATTERN);
  8. if (start < 0) {
  9. return {};
  10. } // If we find a potential extension, and the number preceding this is a viable
  11. // number, we assume it is an extension.
  12. var numberWithoutExtension = number.slice(0, start);
  13. var matches = number.match(EXTN_PATTERN);
  14. var i = 1;
  15. while (i < matches.length) {
  16. if (matches[i]) {
  17. return {
  18. number: numberWithoutExtension,
  19. ext: matches[i]
  20. };
  21. }
  22. i++;
  23. }
  24. }
  25. //# sourceMappingURL=extractExtension.js.map