blob: bef37d4beab849840b083dcfd121427c49631b87 (
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
26
27
28
29
|
/** 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
*/
ORiGiNal = 'ςερτυθιοπασδφγηξκλζχψωβνμΕΡΤΥΘΙΟΠΑΣΔΦΓΗΞΚΛΖΧΨΩΒΝΜάέήίόύώϊΐϋΆΈΉΊΌΎΏΪΫQWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm0123456789- '.split('');
kbKeyZed = 'sertyuiopasdfghjklzxcvbnmertyuiopasdfghjklzxcvbnmaehioyviiyaehioyviyqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm0123456789- '.split('');
map = new Map();
for (var i=0; i<ORiGiNal.length; i++) map.set(ORiGiNal[i], kbKeyZed[i]);
exports.keybutil = {
map: map,
keyboardize: function(str) {
str = str.replace('\'','');
var out = '';
// [map]'s implementation is 40x faster than [for]'s
for (var i=0 ; i< str.length; i++) out += map.get(str[i]);
return out;
}
};
|