summaryrefslogtreecommitdiff
path: root/pieces/kbutils.js
diff options
context:
space:
mode:
authorGeo Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2024-04-09 19:12:30 +0300
committerGeo Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2024-04-09 19:12:30 +0300
commit575ca536c237eff331998714cdbebaf88fe3b5c6 (patch)
tree0230c26ea8aa00f7d49f96ad9dc9cacf2955d053 /pieces/kbutils.js
parent92ced95eaea6af1ef05b3b02498bea8df1f40552 (diff)
downloadoseine-575ca536c237eff331998714cdbebaf88fe3b5c6.tar.gz
oseine-575ca536c237eff331998714cdbebaf88fe3b5c6.tar.bz2
oseine-575ca536c237eff331998714cdbebaf88fe3b5c6.zip
step-1: import main search implementations into node
Diffstat (limited to 'pieces/kbutils.js')
-rw-r--r--pieces/kbutils.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/pieces/kbutils.js b/pieces/kbutils.js
new file mode 100644
index 0000000..b8ae0ad
--- /dev/null
+++ b/pieces/kbutils.js
@@ -0,0 +1,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; \ No newline at end of file