Skip to content

Instantly share code, notes, and snippets.

@DrAzraelTod
Created February 9, 2018 14:13
Show Gist options
  • Save DrAzraelTod/7173f02f6e2a911492951c07cc21fe93 to your computer and use it in GitHub Desktop.
Save DrAzraelTod/7173f02f6e2a911492951c07cc21fe93 to your computer and use it in GitHub Desktop.
quick and dirty way to clean a string from any non-word-characters, while keeping something that looks similar
var reduceSpecialChars = function(input) {
let normalized = input.normalize("NFKD");
normalized = normalized.replace("ß","ss");
bytes = [];
for (var i = 0; i < normalized.length; ++i)
{
charCode = normalized.charCodeAt(i);
bytes.push(charCode & 0xFF);
}
temp = "";
for (var i = 0; i < bytes.length; ++i)
{
temp = temp + String.fromCharCode(bytes[i])
}
return temp.replace(/\W/g, "");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment