Last active
February 9, 2018 14:17
-
-
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
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
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