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