Closed dortamur closed 5 years ago
Works for me:
const phoneNumber2 = parsePhoneNumberFromString('+6584655555')
phoneNumber2.getType().should.equal('MOBILE')
You can create a pull request with a test which you think illustrates your issue.
See tests/parsePhoneNumberFromString.test.js
.
@Dortamur
Oh, I get it now: you're importing from the wrong package.
See readme on min
vs max
vs mobile
.
Oh right! I get it now! I misinterpreted the metadata docs - since I was used to the older API, I thought metadata still needed to be imported separately - but instead, each metadata variant replaces the core library.
So my code should instead be:
const PhoneUtil = require('libphonenumber-js/mobile')
let number = PhoneUtil.parsePhoneNumberFromString('+6584685555', 'AU')
let type = number.getType(number)
console.log({number, type})
...which does return type == 'MOBILE'
Might I suggest adding a simple example code to the min/max/mobile section to illustrate the different metadata in action.
Thanks!
@Dortamur
Yeah, I guess that would make sense..
Added two examples to .getType()
and .isValid()
sections of the README.
Great! Thanks.
I have a case where a given number is returning no Type, whereas the same number in Google's library (and other online checkers) correctly returns type "MOBILE". This case works in libphonenumber-js versions prior to 1.6.0 (using older API - tested with 1.5.2), but anything later than 1.6.0 inclusive fails.
The number is +6584655555 (last 5 digits changed for privacy). I use Default Country "AU" (as that's where I am, and most of our user). The library correctly identifies it as a Valid number from country "SG" - but the type is undefined.
Google Test: https://libphonenumber.appspot.com/phonenumberparser?number=%2B6584655555&country=AU
I have tried using "metadata.full.json" - although normally I use "metadata.mobile.json".
Minimal script: