Skip to content

Instantly share code, notes, and snippets.

@yarkovaleksei
Forked from mad-gooze/node-translit.js
Created August 27, 2017 16:30
Show Gist options
  • Save yarkovaleksei/9f8859dec0f89b72fb5c7af95337f719 to your computer and use it in GitHub Desktop.
Save yarkovaleksei/9f8859dec0f89b72fb5c7af95337f719 to your computer and use it in GitHub Desktop.
Simple translit module for node.js - Простой модуль транслитерации кирилицы для node.js
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