therebelrobot / countryjs

[unmaintained] A module for returning data about countries, ISO info and states/provinces within them. Browserify-compatible
http://country.js.org
120 stars 88 forks source link

Add support for approximate string matching of country name #32

Closed loris closed 8 years ago

loris commented 8 years ago

Hi again, This is a fix I do need for my own use cases. So feel free to reject it if you think it might bloat the library. But I think it could be quite useful to others. It makes the matching insensitive to the case, diacritics, the presence of small words (of, the, end, ...) or some characters like "-" and ".". It does not have any performance impact since I do build an index at start (It might even be a bit faster). Have a look at the new test case to see some examples of matching that was not possible before.

(Sorry for the multiple commits, at first I was using an external fuzzy matching library but results were too inaccurate)

therebelrobot commented 8 years ago

Will take a look at this later today :) Thanks for your work on this!

therebelrobot commented 8 years ago

One thing I would say this needs is an addition to the README for its usage details. Could you add that into this PR?

loris commented 8 years ago

I gave it a try at detailing the method usage, feel free to improve it :)

therebelrobot commented 8 years ago

LGTM. I'll do a couple more tests today, and if all looks well, I'll get another release out today.

loris commented 8 years ago

Please do, especially regarding the following lines:

.replace(/\-/g, ' ')
.replace(/(\.|\b(the|and|of|de|des|du|di|del|y|da|und|die) \b)/g, '')

We might need to add some more small words or characters to improve the matching.

therebelrobot commented 8 years ago

ooo, yeah, we'll need at least la and el, los, and las for spanish... (this could get suuuper long...)

loris commented 8 years ago

Hi @therebelrobot, have you had the chance to check this out?

therebelrobot commented 8 years ago

I remember taking a look at it back when you submitted it, but haven't had a chance to take a deep dive because of the holiday. I'll have some time today to play catch up, set up new releases, etc. Defs by PT EOD for sure.

therebelrobot commented 8 years ago

kk. lgtm. setting up a release.

therebelrobot commented 8 years ago

v1.5.0 published.