Skip to content

Instantly share code, notes, and snippets.

@DrAzraelTod
Last active February 9, 2018 14:17
Show Gist options
  • Save DrAzraelTod/645b6fbc05f94ceee7987cbc8c06a7fb to your computer and use it in GitHub Desktop.
Save DrAzraelTod/645b6fbc05f94ceee7987cbc8c06a7fb 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.toLocaleLowerCase().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