Skip to content

Instantly share code, notes, and snippets.

@viatsko
Created August 31, 2014 08:54
Show Gist options
  • Save viatsko/866c8a32d4bdd43d1f46 to your computer and use it in GitHub Desktop.
Save viatsko/866c8a32d4bdd43d1f46 to your computer and use it in GitHub Desktop.
Транслит, не помню откуда
'use strict';
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