Created
October 17, 2017 08:14
-
-
Save albertoperezf/275fe566ed231d49f30af42b19844cc7 to your computer and use it in GitHub Desktop.
Function to remove special characters (Accents, etc) from strings (es6)
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
// This function delete the especial characters in the strings (es6) | |
handleAccents = (str) => { | |
const accents = 'ÀÁÂÃÄÅàáâãäåßÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž' | |
const accentsOut = 'AAAAAAaaaaaaBOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz' | |
str = str.split('') | |
str.forEach((letter, index) => { | |
const i = accents.indexOf(letter) | |
if (i !== -1) { str[index] = accentsOut[i] } | |
}) | |
return str.join('') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment