formatIncompletePhoneNumber.js 847 B

1234567891011121314151617
  1. import AsYouType from './AsYouType.js'
  2. /**
  3. * Formats a (possibly incomplete) phone number.
  4. * The phone number can be either in E.164 format
  5. * or in a form of national number digits.
  6. * @param {string} value - A possibly incomplete phone number. Either in E.164 format or in a form of national number digits.
  7. * @param {string|object} [optionsOrDefaultCountry] - A two-letter ("ISO 3166-1 alpha-2") country code, or an object of shape `{ defaultCountry?: string, defaultCallingCode?: string }`.
  8. * @return {string} Formatted (possibly incomplete) phone number.
  9. */
  10. export default function formatIncompletePhoneNumber(value, optionsOrDefaultCountry, metadata) {
  11. if (!metadata) {
  12. metadata = optionsOrDefaultCountry
  13. optionsOrDefaultCountry = undefined
  14. }
  15. return new AsYouType(optionsOrDefaultCountry, metadata).input(value)
  16. }