Skip to content

Instantly share code, notes, and snippets.

@asakasinsky
Created September 26, 2013 19:17
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 asakasinsky/6719178 to your computer and use it in GitHub Desktop.
Save asakasinsky/6719178 to your computer and use it in GitHub Desktop.
if (typeof String.prototype.trim === 'undefined') {
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');};
String.prototype.ltrim=function(){return this.replace(/^\s+/,'');};
String.prototype.rtrim=function(){return this.replace(/\s+$/,'');};
String.prototype.fulltrim=function(){return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'').replace(/\s+/g,' ');};
}
if (typeof String.prototype.capitaliseFirstLetter === 'undefined') {
String.prototype.capitaliseFirstLetter=function(){return this.charAt(0).toUpperCase() + this.slice(1);};
}
if (typeof String.prototype.transliterate === 'undefined') {
String.prototype.transliterate =function () {
var cyrilic = {
'а':'a', 'б':'b', 'в':'v', 'г':'g',
'д':'d', 'е':'e', 'ё':'yo', 'ж':'zh', 'з':'z',
'и':'i', 'й':'y', 'к':'k', 'л':'l',
'м':'m', 'н':'n', 'о':'o', 'п':'p', 'р':'r',
'с':'s', 'т':'t', 'у':'u', 'ф':'f',
'х':'h', 'ц':'c', 'ч':'ch','ш':'sh', 'щ':'shch',
'ъ':'', 'ы':'y', 'ь':'', 'э':'e', 'ю':'yu', 'я':'ya',
'А':'A', 'Б':'B', 'В':'V', 'Г':'G',
'Д':'D', 'Е':'E', 'Ё':'YO', 'Ж':'ZH', 'З':'Z',
'И':'I', 'Й':'Y', 'К':'K', 'Л':'L',
'М':'M', 'Н':'N', 'О':'O', 'П':'P', 'Р':'R',
'С':'S', 'Т':'T', 'У':'U', 'Ф':'F',
'Х':'H', 'Ц':'C', 'Ч':'CH', 'Ш':'SH', 'Щ':'SHCH',
'Ъ':'', 'Ы':'Y', 'Ь':'', 'Э':'E', 'Ю':'YU', 'Я':'YA',
'a':'a', 'b':'b', 'c':'c', 'd':'d', 'e':'e',
'f':'f', 'g':'g', 'h':'h', 'i':'i', 'j':'j',
'k':'k', 'l':'l', 'm':'m', 'n':'n', 'o':'o',
'p':'p', 'q':'q', 'r':'r', 's':'s', 't':'t',
'u':'u', 'v':'v', 'w':'w', 'x':'x', 'y':'y',
'z':'z',
'A':'A', 'B':'B', 'C':'C', 'D':'D', 'E':'E',
'F':'F', 'G':'G', 'H':'H', 'I':'I', 'J':'J', 'K':'K',
'L':'L', 'M':'M', 'N':'N', 'O':'O', 'P':'P',
'Q':'Q', 'R':'R', 'S':'S', 'T':'T', 'U':'U', 'V':'V',
'W':'W', 'X':'X', 'Y':'Y', 'Z':'Z',
' ':'_', '0':'0', '1':'1', '2':'2', '3':'3',
'4':'4', '5':'5', '6':'6', '7':'7', '8':'8', '9':'9',
'-':'_'
};
return this.replace(/[0-9А-Яа-яЁё\W]/g,
function(a, b) {
return cyrilic[a] || "";
}
);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment