Created
May 29, 2018 04:34
transliterate eng-rus or rus-eng and space replace -
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function transliterate(text, engToRus) { | |
const rus = "щ ш ч ц ю я ё ж ъ ы э а б в г д е з и й к л м н о п р с т у ф х ь".split(/ +/g) | |
const eng = "shh sh ch cz yu ya yo zh '' y' e' a b v g d e z i j k l m n o p r s t u f x '".split(/ +/g) | |
for(let x = 0; x < rus.length; x++) { | |
text = text.split(engToRus ? eng[x] : rus[x]).join(engToRus ? rus[x] : eng[x]); | |
text = text.split(engToRus ? eng[x].toUpperCase() : rus[x].toUpperCase()).join(engToRus ? rus[x].toUpperCase() : eng[x].toUpperCase()); | |
} | |
if (text.includes('-')) { | |
return text.split('-').join(' '); | |
} | |
return text.split(' ').join('-'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment