Skip to content

Commit

Permalink
Stop using "as"
Browse files Browse the repository at this point in the history
  • Loading branch information
mleduc-pass committed Nov 27, 2024
1 parent 50eeb3c commit c46261a
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import parsePhoneNumberFromString, { CountryCode } from 'libphonenumber-js'
import parsePhoneNumberFromString, { CountryCode, getCountries } from 'libphonenumber-js'

function isCountryCode(code: string): code is CountryCode {
const countries: string[] = getCountries()
return countries.includes(code)
}

export function isPhoneNumberValid(number: string, country: string) {
const phoneNumber = parsePhoneNumberFromString(number, country as CountryCode)
if (!isCountryCode(country)) return false

const phoneNumber = parsePhoneNumberFromString(number, country)
return phoneNumber?.isValid() ?? false
}

0 comments on commit c46261a

Please sign in to comment.