brianreavis / sifter.js

A library for textually searching arrays and hashes of objects by property (or multiple properties). Designed specifically for autocomplete.
1.09k stars 125 forks source link

Please allow redefinition of DIACRITICS through options #49

Open varyen opened 7 years ago

varyen commented 7 years ago

Hi. I'm using selectize with sifter support.

Diacritics matching can be also used when you have two languages (two keyboard layouts) to switch between and you're typing on wrong one.

In my case, english letters "qwertyuiop" are "йцукенгшщз" in russian keyboard layout. If I add these pairs of letters to DIACRITICSit works just perfect and shows expected search results even if I'm on wrong keyboard layout! Very handy.

Something like this:

    var DIACRITICS = {
        'a': '[фaḀḁĂăÂâǍǎȺⱥȦȧẠạÄäÀàÁáĀāÃãÅåąĄÃąĄ]',
        'b': '[иb␢βΒB฿𐌁ᛒ]',
        'c': '[сcĆćĈĉČčĊċC̄c̄ÇçḈḉȻȼƇƈɕᴄCc]',
        'd': '[вdĎďḊḋḐḑḌḍḒḓḎḏĐđD̦d̦ƉɖƊɗƋƌᵭᶁᶑȡᴅDdð]',
        'e': '[уeÉéÈèÊêḘḙĚěĔĕẼẽḚḛẺẻĖėËëĒēȨȩĘęᶒɆɇȄȅẾếỀềỄễỂểḜḝḖḗḔḕȆȇẸẹỆệⱸᴇEeɘǝƏƐε]',
        'f': '[аfƑƒḞḟ]',
        'g': '[пgɢ₲ǤǥĜĝĞğĢģƓɠĠġ]',
        'h': '[рhĤĥĦħḨḩẖẖḤḥḢḣɦʰǶƕ]',
        'i': '[шiÍíÌìĬĭÎîǏǐÏïḮḯĨĩĮįĪīỈỉȈȉȊȋỊịḬḭƗɨɨ̆ᵻᶖİiIıɪIi]',
        'j': '[оjȷĴĵɈɉʝɟʲ]',
        'k': '[лkƘƙꝀꝁḰḱǨǩḲḳḴḵκϰ₭]',
        'l': '[дlŁłĽľĻļĹĺḶḷḸḹḼḽḺḻĿŀȽƚⱠⱡⱢɫɬᶅɭȴʟLl]',
        'n': '[тnŃńǸǹŇňÑñṄṅŅņṆṇṊṋṈṉN̈n̈ƝɲȠƞᵰᶇɳȵɴNnŊŋ]',
        'o': '[щoØøÖöÓóÒòÔôǑǒŐőŎŏȮȯỌọƟɵƠơỎỏŌōÕõǪǫȌȍՕօ]',
        'p': '[зpṔṕṖṗⱣᵽƤƥᵱ]',
        'q': '[йqꝖꝗʠɊɋꝘꝙq̃]',
        'r': '[кrŔŕɌɍŘřŖŗṘṙȐȑȒȓṚṛⱤɽ]',
        's': '[ыsŚśṠṡṢṣꞨꞩŜŝŠšŞşȘșS̈s̈]',
        't': '[еtŤťṪṫŢţṬṭƮʈȚțṰṱṮṯƬƭ]',
        'u': '[гuŬŭɄʉỤụÜüÚúÙùÛûǓǔŰűŬŭƯưỦủŪūŨũŲųȔȕ∪]',
        'v': '[мvṼṽṾṿƲʋꝞꝟⱱʋ]',
        'w': '[цwẂẃẀẁŴŵẄẅẆẇẈẉ]',
        'x': '[чxẌẍẊẋχ]',
        'y': '[нyÝýỲỳŶŷŸÿỸỹẎẏỴỵɎɏƳƴ]',
        'z': '[яzŹźẐẑŽžŻżẒẓẔẕƵƶ]'
    };

Unfortunately there's no way to redefine DIACRITICSvariable, it's hardcoded. Is it possible to make it configurable?

P.S. I don't think russian-english or other language pairs should be implemented in source along another diacritics, end users should configure it themselves. But it may be a new feature, in that case of course it will be another variable which can be used in asciifold().

I can prepare and send you pull request for it.