ruimarinho / google-libphonenumber

The up-to-date and reliable Google's libphonenumber package for node.js.
https://ruimarinho.github.io/google-libphonenumber
Other
1.4k stars 146 forks source link

Sample number for Italy - first 0 is omitted because of parseInt? #302

Closed vault-developer closed 3 years ago

vault-developer commented 3 years ago

Hello! Thank you for your library, it's great!

I tried to retrieve an example number for Italy. Looks like all is correct in metadata.js: https://github.com/ruimarinho/google-libphonenumber/blob/master/src/metadata.js#L3721 Please pay attention to the end of the line, number is 0212345678.

But then when I try to retrieve this number like this: PhoneNumberUtil.getInstance().getExampleNumber('IT').getNationalNumber(); I receive only 212345678 (first 0 is omitted).

P.S. Probably it is happened because of casting string to number here: https://github.com/ruimarinho/google-libphonenumber/blob/master/src/phonenumberutil.js#L4313

Thank you in advance!

NagendraSIB commented 3 years ago

Hi The digit "0" was the trunk code. For getNationalNumber() it will only give you national number i.e- 212345678. If you want to add 0 you can use getItalianLeadingZero() fxn & if it's give true you can concate 0 at at begining of national number. Thanks

vault-developer commented 3 years ago

Hello, @NagendraSIB Oh, I see now. Thank you for the explanation.