Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created October 30, 2013 12:09
Show Gist options
  • Save Kcko/7231576 to your computer and use it in GitHub Desktop.
Save Kcko/7231576 to your computer and use it in GitHub Desktop.
JS: text makes safe
function makeSafe(thisText, allowSpace){
var w = "!@#$%^&*()+=[]\\\';,./{}|\":<>?";
var s = 'abcdefghijklmnopqrstuvwxyz0123456789-';
var x = new Array('àáâãäå', 'çč', 'èéêëě','š','ř','ž','á', 'ìíîï', 'ñ', 'ðóòôõöø', 'ùúûüů', 'ýÿ',' ','.');
var r = new Array('a', 'c', 'e','s','r','z','a', 'i', 'n', 'o', 'u', 'y','-','-');
if(allowSpace){
s = s + ' ';
}
thisText = thisText.toLowerCase();
var newText = new Array();
for (i = 0; i < thisText.length; i++){
thisChar = thisText.charAt(i);
if(w.indexOf(thisChar) == -1){
if(s.match(''+thisChar+'')){
newText[i] = thisChar;
}else{
for (j = 0; j < x.length; j++){
if(x[j].match(thisChar)){
newText[i] = r[j];
}
}
}
}
}
return newText.join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment