Closed hbouhadji closed 4 years ago
Hey @catamphetamine, I know you have been busy, but any chance you could still review + merge this? Your library has been great for us but it would be absolutely perfect if this was fixed!
@mario-d-s Hi. I'm actually currently rewriting AsYouType formatter to fix the duplicate area code bug. As for this change, it looks clever. But should we include it in the library? I mean, it could very well be incorporated in developer's code as:
import { parsePhoneNumberFromString, getCountryCallingCode } from 'libphonenumber-js'
export default function autoFixParseNumber(number, country) {
const phoneNumber = parsePhoneNumberFromString(number, country)
if (phoneNumber) {
return phoneNumber
}
if (country && number[0] !== '+') {
if (number.indexOf(getCountryCallingCode(country)) === 0) {
number = number.slice(getCountryCallingCode(country).length)
return parsePhoneNumberFromString(number, country)
}
}
}
This should fix the issue #316
With this example:
what I get:
what I should get:
https://libphonenumber.appspot.com/phonenumberparser?number=33169454850&country=FR
available for any questions