country-code-lookup icon indicating copy to clipboard operation
country-code-lookup copied to clipboard

feat(Search): More flexible name search byCountry()

Open IvanDLar opened this issue 2 years ago • 4 comments

I find this library to be extremely useful, and grateful that I found it but I have a single suggestion.

Make the byCountry() function a bit more flexible by parsing both the input and the output by homologating both strings. Ej.-

  • Transform into all miniscule letters
  • Trim extra spaces
  • Maybe, add name variants for some countries EJ
    • The United States of America
    • United States of America

I would love to help implementing this new functionalities, if I may so :smile:

IvanDLar avatar Jun 09 '23 02:06 IvanDLar

I have made a local branch where I added a function that uses regex and a couple of other methods to help out in making the byCountry() function a bit more flexible.

For example, all of the countries within this list now can be matched to their country: let sampleCountries = ["The United States of America", " Qatar ", "Canada", "United Kingdom", "United States", "United States of America", "United Kingdom of Great Britain", " mexico", "jamaica ", "Republic of the Congo"];

IvanDLar avatar Jun 09 '23 04:06 IvanDLar

If you agree, I could send a PR so you can review the proposed changes that were made in your code :smile:

IvanDLar avatar Jun 09 '23 04:06 IvanDLar

Hi @IvanDLar great to hear you're finding the library useful!

Fuzzy matching on country name is not something I oppose, but it wasn't a usecase I had anticipated. I added more for completeness than for anything useful.

A challenge I see is that some countries (my own included!) have an official name, and another name that is more commonly used. For example "United Kingdom of Great Britain" could also be "Britain", "Great Britain", "UK" and some people would expect "England" as well. I don't have a data source for all of these variations, and it's not the intention of this library to fix that.

Curious to know your thoughts?

richorama avatar Jun 09 '23 11:06 richorama

The python iso3166 module maintains an apolitical_name field that is quite useful in these contexts if you're looking for source/inspiration @IvanDLar

maxmorlocke avatar Jul 26 '23 19:07 maxmorlocke