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.79k stars 216 forks source link

Unable to do customise mobile library like min.meta.json functionality #329

Closed priyankapyt closed 5 years ago

priyankapyt commented 5 years ago

Unable to do customise mobile library like min functionality.

I want to remove mobile.meta.json from my code for that I tried custom format as mentioned in the documentation but after that parsePhoneNumberFromString of mobile lib is not working.

catamphetamine commented 5 years ago

It's not clear what you mean at all

priyankapyt commented 5 years ago

@catamphetamine Sorry if I was not clear enough. Actually in my current app I'm using libphonenumber-js/mobile. But for optimisation i want to remove the meta.mobile.json out of my bundle.

So i was trying script to create custom meta file and use it.

But it is not working as expected for parsePhoneNumberFromString function from mobile flavour of it.

Do let me know if you need more details.

catamphetamine commented 5 years ago

But for optimisation i want to remove the meta.mobile.json out of my bundle.

The library requires some metadata to work with. Otherwise it won't work.

priyankapyt commented 5 years ago

Yes, that meta data file i'm passing as a parameter exactly as it is mentioned in custom meta-data part of documentation.

It is working as expected for functions from min flavor of library, but not for functions from mobile flavor of it.

@catamphetamine do you know why customisation doesn't work for mobile flavor of library and only works for min flavor of library? Even in example it shows use case of min flavor of library.

catamphetamine commented 5 years ago

It is working as expected for functions from min flavor of library not for functions from mobile flavor of it.

Don't use min or mobile in that case, use custom.

priyankapyt commented 5 years ago

Yes, I'm using custom flavor only. But in that if you use below function it gives true and in mobile flavor it gives false. (expectes result is false as 1234567890 is invalid no)

parsePhoneNumberFromString('+911234567890').isValid()

Here 1234567890 is wrong mobile number entered by user.

catamphetamine commented 5 years ago

If the results aren't valid then perhaps the metadata isn't valid.

Post how you generate your metadata.

priyankapyt commented 5 years ago
"libphonenumber-metadata": "libphonenumber-generate-metadata metadata.min.json"

I'm generating my json using above script and later I'm saving it in my app and accessing it from there.

catamphetamine commented 5 years ago

There's no need to do that — it won't differ from the min metadata.

priyankapyt commented 5 years ago

correct, so in a nutshell -> I have just kept the meta files out of the bundle and using custom flavour by passing metaData as parameter.

But in that case below function gives true and when I use mobile flavour it gives false. (expected result is false as 1234567890 is invalid no)

parsePhoneNumberFromString('+911234567890').isValid()

**here 1234567890 is wrong mobile number entered by user.

priyankapyt commented 5 years ago

Closing the issue, got it. I was not passing the correct meta data files. Thanks @catamphetamine for directing towards correct issue.