Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some countries are missing #73

Closed
ppsimatikas opened this issue May 1, 2017 · 3 comments
Closed

Some countries are missing #73

ppsimatikas opened this issue May 1, 2017 · 3 comments

Comments

@ppsimatikas
Copy link

I was trying to use the getPhoneCode method for Bulgaria (country code 'BU') and the library have failed with an error breaking the page.

 error      TypeError: Cannot read property '0' of undefined
    at get_phone_code (eval at <anonymous> (), <anonymous>:31:25)
    at getPhoneCodeCustom (eval at <anonymous> (), <anonymous>:107:101)
    at Object.getPhoneCode [as a] (eval at <anonymous> (), <anonymous>:102:9)

I have noticed that the https://github.com/halt-hammerzeit/libphonenumber-js/blob/master/metadata.min.json does not include BU as a country.

I could go and regenerate the metadata file to get that country code from the Google library, but I think it would be nicer to have some kind of handling country codes that are not supported in a better way. Some examples are :

  1. Make the function return undefined
  2. Make the function throw an error with a message "BU is not a supported country"
@catamphetamine
Copy link
Owner

catamphetamine commented May 1, 2017

Although your proposal is good and is likely to be implemented, the code you're using is wrong:

    <!-- Bulgaria -->
    <territory id="BG" countryCode="359" internationalPrefix="00"
               nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG"
               mobileNumberPortableRegion="true">

@ppsimatikas
Copy link
Author

ppsimatikas commented May 1, 2017

The code I am using is exactly this :

import { getPhoneCode } from 'libphonenumber-js';

getPhoneCode('BU');

Can you let me know how am I using this wrong?

The version of the library I am using is 0.4.9

@catamphetamine
Copy link
Owner

It is BG for Bulgaria

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants