summaryrefslogtreecommitdiff
path: root/pieces/kbutils.js
blob: b8ae0ad0c8ec4d2502a7cff7372711b3b98e8b3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/** keyboardize
 * -------------------------------------------------------------------------
 * translates string to keyboard-latin keys
 * (the ones that used whan typing each letter of the word)
 * 
 * @param str (string): original string (utf8 of latin or greek subgroups)
 * @return (string): latin/ascii equivalent string
 */

_kbu = {
    ORiGiNal:'ςερτυθιοπασδφγηξκλζχψωβνμΕΡΤΥΘΙΟΠΑΣΔΦΓΗΞΚΛΖΧΨΩΒΝΜάέήίόύώϊΐϋΆΈΉΊΌΎΏΪΫQWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm0123456789- '.split(''),
    kbKeyZed: 'sertyuiopasdfghjklzxcvbnmertyuiopasdfghjklzxcvbnmaehioyviiyaehioyviyqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm0123456789- '.split(''),
    map: new Map()
}
for (var i=0; i<_kbu.ORiGiNal.length; i++) _kbu.map.set(_kbu.ORiGiNal[i], _kbu.kbKeyZed[i]);

_kbu.keyboardize = (str) => {
    str = str.replace('\'','');
    var out = '';
    // [map]'s implementation is 40x faster than [for]'s
    for (var i=0 ; i< str.length; i++)  out += _kbu.map.get(str[i]);
    return out;
}

exports.keybutil = _kbu;