diff options
| author | Geo Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2024-04-12 18:31:00 +0300 |
|---|---|---|
| committer | Geo Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2024-04-12 18:31:00 +0300 |
| commit | b122279ece06a9381e805c6087f130b41616fe3d (patch) | |
| tree | 2ec0a8fc3c570417d972b18a7a7b878758ce3a6f /pieces/kb-util.js | |
| parent | 762d85c95690f510bec4dd8c37c05454ae1be4fc (diff) | |
| download | oseine-b122279ece06a9381e805c6087f130b41616fe3d.tar.gz oseine-b122279ece06a9381e805c6087f130b41616fe3d.tar.bz2 oseine-b122279ece06a9381e805c6087f130b41616fe3d.zip | |
added utils folder; added several suplamentary modules
Diffstat (limited to 'pieces/kb-util.js')
| -rw-r--r-- | pieces/kb-util.js | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/pieces/kb-util.js b/pieces/kb-util.js deleted file mode 100644 index 5441861..0000000 --- a/pieces/kb-util.js +++ /dev/null @@ -1,84 +0,0 @@ -// suplamentary arrays (mostly for cache) -// --- -- -- - - - - -var ORiGiNal = 'ςερτυθιοπασδφγηξκλζχψωβνμΕΡΤΥΘΙΟΠΑΣΔΦΓΗΞΚΛΖΧΨΩΒΝΜάέήίόύώϊΐϋΆΈΉΊΌΎΏΪΫQWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm0123456789- '.split(''); - -var kbKeyZed = 'sertyuiopasdfghjklzxcvbnmertyuiopasdfghjklzxcvbnmaehioyviiyaehioyviyqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm0123456789- '.split(''); - -var map = new Map(); -for (var i=0; i<ORiGiNal.length; i++) map.set(ORiGiNal[i], kbKeyZed[i]); - - -// cache (=create a global array) -// of accended to non-accended vowels mapping -// --- -- -- - - - -accented_vowels = []; -[ - 'ά α', 'έ ε', 'ή η', 'ί ι', 'ϊ ι', 'ΐ ι', 'ό ο', 'ύ υ', 'ϋ υ', 'ώ ω', - 'Ά Α', 'Έ Ε', 'Ή Η', 'Ί Ι', 'Ϊ Ι', 'Ό Ο', 'Ύ Υ', 'Ϋ Υ', 'Ώ Ω' -].forEach( pair => { - ap = pair.split(' '); - accented_vowels.push({ - a: ap[0], // accented - p: ap[1] // pure = non accended - }); -}); - - -// translates string to keyboard-latin keys -// (the ones that used whan typing each letter of the word) -const 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 += map.get(str[i]); - return out; -} - -// keyboardize an array of strings -const keyb_array = (arr) => { - kb_arr = []; - arr.forEach( w => { - kb_arr.push(keyboardize(w)); - }); - return kb_arr; -} - - -// transforms to lowercase; handles sigma-teliko -const sanitizeGR = (str) => { - str = str.toLowerCase(); - - // replace accended vowels with pure ones - accented_vowels.forEach( v => { - str = str.replaceAll(v.a, v.p); - }); - - // replace sigma on the end of words - str = str + ' '; - str = str.replaceAll('σ-', 'ς-'); - str = str.replaceAll('σ ', 'ς '); - - return str; -} - -// removes non keyword characters [+ . , !] and internal multiple-spaces -// @param txt (string): product description -const clean = (txt) => { - return txt.replace('+',' ').replace('.',' ').replace(',',' ') // change to space - .replace('!','').replace('\"', '') // remove character - .replace(' ',' ').replace(' ',' '); // remove multiple spaces -} - - -// exports -// --- -- -- - - - - -module.exports = { - map, - accented_vowels, - keyboardize, - keyb_array, - sanitizeGR, - clean -};
\ No newline at end of file |
