searchPhoneNumbersInText.js 580 B

123456789101112131415161718192021222324
  1. import PhoneNumberMatcher from './PhoneNumberMatcher.js'
  2. import normalizeArguments from './normalizeArguments.js'
  3. export default function searchPhoneNumbersInText() {
  4. const { text, options, metadata } = normalizeArguments(arguments)
  5. const matcher = new PhoneNumberMatcher(text, { ...options, v2: true }, metadata)
  6. return {
  7. [Symbol.iterator]() {
  8. return {
  9. next: () => {
  10. if (matcher.hasNext()) {
  11. return {
  12. done: false,
  13. value: matcher.next()
  14. }
  15. }
  16. return {
  17. done: true
  18. }
  19. }
  20. }
  21. }
  22. }
  23. }