Option to tolerate diacritics
googol7 opened this issue · 1 comments
googol7 commented
It would be very helpful if an option could be set so that fuzzy would return strings with and without diacritics.
e.g.: The user searches for "Lumiere"
The result should also include "Lumière":
Lumière
Lümière
Lumiere
Lůmière
Lúmière
You won't find "Lumiere" in this official example:
http://htmlpreview.github.io/?https://github.com/mattyork/fuzzy/blob/master/examples/disney.html
schindld commented
I got diacritics to be included in searches by changing 2 places in fuzzy.js where comparisons are done...
- , compareString = opts.caseSensitive && str || str.toLowerCase()
+ , compareString = opts.caseSensitive && str || str.toLowerCase().normalize("NFKD").replace(/\p{Diacritic}/gu, "")
, ch;
- pattern = opts.caseSensitive && pattern || pattern.toLowerCase();
+ pattern = opts.caseSensitive && pattern || pattern.toLowerCase().normalize("NFKD").replace(/\p{Diacritic}/gu, "");