parsePhoneNumber_.js 669 B

123456789101112131415161718192021222324
  1. import parsePhoneNumberWithError from './parsePhoneNumberWithError_.js'
  2. import ParseError from './ParseError.js'
  3. import { isSupportedCountry } from './metadata.js'
  4. export default function parsePhoneNumber(text, options, metadata) {
  5. // Validate `defaultCountry`.
  6. if (options && options.defaultCountry && !isSupportedCountry(options.defaultCountry, metadata)) {
  7. options = {
  8. ...options,
  9. defaultCountry: undefined
  10. }
  11. }
  12. // Parse phone number.
  13. try {
  14. return parsePhoneNumberWithError(text, options, metadata)
  15. } catch (error) {
  16. /* istanbul ignore else */
  17. if (error instanceof ParseError) {
  18. //
  19. } else {
  20. throw error
  21. }
  22. }
  23. }