-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.mjs
16 lines (16 loc) · 884 Bytes
/
main.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
export default function odredi(word) {
let counterLat = word.match(/[\u{0041}-\u{007a}\u{0100}-\u{017f}]/gui) || false; //takes the latin characters from the first 512 characters in a string
if (counterLat) {
counterLat = counterLat.length; //counts them, if there are any
}
let counterCyrl = word.match(/[\u{0400}-\u{04FF}]/gui) || false; //takes the cyrillic characters from the first 512 characters in a string
if (counterCyrl) {
counterCyrl = counterCyrl.length; //counts them, if there are any
}
if (counterLat > counterCyrl) { //if there's more latin than cyrillic, it returns ISO code for latin as a string
return 'Latn';
}
else {
return 'Cyrl'; //otherwise there's more cyrillic, so it returns ISO code for cyrillic as a string
}
}