How to use the google-libphonenumber.PhoneNumberType.MOBILE function in google-libphonenumber

To help you get started, we’ve selected a few google-libphonenumber examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github celo-org / celo-monorepo / packages / utils / src / phoneNumbers.ts View on Github external
function prependToFormMobilePhoneNumber(
  parsedNumber: PhoneNumber,
  regionCode: string,
  prefix: string
) {
  if (phoneUtil.getNumberType(parsedNumber) === PhoneNumberType.MOBILE) {
    return parsedNumber
  }

  let nationalNumber = phoneUtil.format(parsedNumber, PhoneNumberFormat.NATIONAL)
  // Nationally formatted numbers sometimes contain leading 0
  if (nationalNumber.charAt(0) === '0') {
    nationalNumber = nationalNumber.slice(1)
  }
  // If the number already starts with prefix, don't prepend it again
  if (nationalNumber.startsWith(prefix)) {
    return null
  }

  const adjustedNumber = phoneUtil.parse(prefix + nationalNumber, regionCode)
  return phoneUtil.getNumberType(adjustedNumber) === PhoneNumberType.MOBILE ? adjustedNumber : null
}
github celo-org / celo-monorepo / packages / utils / src / phoneNumbers.ts View on Github external
if (phoneUtil.getNumberType(parsedNumber) === PhoneNumberType.MOBILE) {
    return parsedNumber
  }

  let nationalNumber = phoneUtil.format(parsedNumber, PhoneNumberFormat.NATIONAL)
  // Nationally formatted numbers sometimes contain leading 0
  if (nationalNumber.charAt(0) === '0') {
    nationalNumber = nationalNumber.slice(1)
  }
  // If the number already starts with prefix, don't prepend it again
  if (nationalNumber.startsWith(prefix)) {
    return null
  }

  const adjustedNumber = phoneUtil.parse(prefix + nationalNumber, regionCode)
  return phoneUtil.getNumberType(adjustedNumber) === PhoneNumberType.MOBILE ? adjustedNumber : null
}