Created
May 14, 2017 00:39
-
-
Save DfKimera/7cd53b4dc869cc6efe4f93921c3fbd97 to your computer and use it in GitHub Desktop.
Converts Latin special characters (á, ã, â, ç, etc) (found in languages like Portuguese and Spanish) into corresponding ASCII characters. Useful for handling substring searching. [pt-br: Converte caracteres latinos (á, ã, â, ç, etc) (encontrados em idiomas como Português e Espanhol) em caracteres ASCII correspondentes. Útil para lidar com busca …
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 latinToASCII(input) { | |
let mapFrom = 'ãàáâäéêèëíìîïóòõôöúùûüçÃÀÁÂÄÉÊÈËÍÌÎÏÓÒÕÔÖÚÙÛÜÇ'.split(''); | |
let mapTo = 'aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC'.split(''); | |
return input | |
.split('') | |
.map((char) => { | |
let index = mapFrom.indexOf(char); | |
if(index === -1) return char; | |
return mapTo[index]; | |
}) | |
.join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment