Created
December 23, 2017 11:06
-
-
Save LuisSevillano/889ef32626810646b14315981dbdb466 to your computer and use it in GitHub Desktop.
Normalizer
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
function normalize(str) { | |
var from = "1234567890ÃÀÃÄÂÈÉËÊÌÃÃÎÒÓÖÔÙÚÜÛãà áäâèéëêìÃïîòóöôùúüûÑñÇç '/&().!", | |
to = "izeasgtogoAAAAAEEEEIIIIOOOOUUUUaaaaaeeeeiiiioooouuuunncc_____", | |
mapping = {}; | |
for (var i = 0, j = from.length; i < j; i++) { | |
mapping[from.charAt(i)] = to.charAt(i); | |
} | |
var ret = []; | |
for (var i = 0, j = str.length; i < j; i++) { | |
var c = str.charAt(i); | |
if (mapping.hasOwnProperty(str.charAt(i))) { | |
ret.push(mapping[c]); | |
} else { | |
ret.push(c); | |
} | |
} | |
return ret.join('').toLowerCase(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment