Skip to content

Instantly share code, notes, and snippets.

@yalovek
Last active October 23, 2016 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yalovek/ccc8c0931398e3d79d8edb2d3e937f0e to your computer and use it in GitHub Desktop.
Save yalovek/ccc8c0931398e3d79d8edb2d3e937f0e to your computer and use it in GitHub Desktop.
Translit cyrillic to latin
/**
* Function for translitirating cyrillic to latin
* @param {String} word Word on cyrillic
* @return {String} Word translitirated to latin
*/
const translitCyrillicToLatin = word => {
const translitMap = {
'а': 'a',
'б': 'b',
'в': 'v',
'г': 'g',
'д': 'd',
'е': 'e',
'ё': 'e',
'ж': 'zh',
'з': 'z',
'и': 'i',
'ий': 'iy',
'й': 'j',
'к': 'k',
'л': 'l',
'м': 'm',
'н': 'n',
'о': 'o',
'п': 'p',
'р': 'r',
'с': 's',
'т': 't',
'у': 'u',
'ф': 'f',
'х': 'h',
'ц': 'ts',
'ч': 'ch',
'ш': 'sh',
'щ': 'sch',
'ъ': "'",
'ы': 'y',
'ь': "'",
'э': 'e',
'ю': 'ju',
'я': 'ja'
};
return word.toLowerCase()
.split('')
.map((l, k, a) => {
if (l === 'и' && a[k + 1] === 'й') {
return translitMap[l + a[k + 1]];
}
else if (l === 'й' && k - 1 >= 0 && a[k - 1] === 'и') {
return '';
}
return translitMap[l];
})
.join('');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment