catamphetamine / libphonenumber-js

A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript
https://catamphetamine.gitlab.io/libphonenumber-js/
MIT License
2.77k stars 218 forks source link

Include `leading digits` in result #387

Closed dr3 closed 4 years ago

dr3 commented 4 years ago

Steps to reproduce

Calling getCountryCallingCode on countries/territories like American Samoa and Anguila

Observed result

It returns +1

Expected result

What's the expected result?

It returns +1 684 and +1 264 respectively

Google's demo link

https://libphonenumber.appspot.com/phonenumberparser?number=%2B1-2641234567

catamphetamine commented 4 years ago

Hi. First, the country calling code is +1, not +1684, even when leadingDigits are 684. Second, not all countries have leadingDigits: for example, CAnada. https://github.com/google/libphonenumber/blob/master/resources/PhoneNumberMetadata.xml So leadingDigits are just an internal performance optimization in the library code, not an exposed feature.