Last active
March 7, 2024 10:20
-
-
Save mad-gooze/f576259db969bed2d10e to your computer and use it in GitHub Desktop.
Simple translit module for node.js - Простой модуль транслитерации кирилицы для node.js
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
module.exports = function(text) { | |
return text.replace(/([а-яё])|([\s_-])|([^a-z\d])/gi, | |
function (all, ch, space, words, i) { | |
if (space || words) { | |
return space ? '-' : ''; | |
} | |
var code = ch.charCodeAt(0), | |
index = code == 1025 || code == 1105 ? 0 : | |
code > 1071 ? code - 1071 : code - 1039, | |
t = ['yo', 'a', 'b', 'v', 'g', 'd', 'e', 'zh', | |
'z', 'i', 'y', 'k', 'l', 'm', 'n', 'o', 'p', | |
'r', 's', 't', 'u', 'f', 'h', 'c', 'ch', 'sh', | |
'shch', '', 'y', '', 'e', 'yu', 'ya' | |
]; | |
return t[index]; | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment