mattyork / fuzzy

Filters a list based on a fuzzy string search

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Option to tolerate diacritics

googol7 opened this issue · comments

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

I got diacritics to be included in searches by changing 2 places in fuzzy.js where comparisons are done...

Line 50:

-    , 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, "");