Skip to content

Instantly share code, notes, and snippets.

@albertoperezf
Created October 17, 2017 08:14
Show Gist options
  • Save albertoperezf/275fe566ed231d49f30af42b19844cc7 to your computer and use it in GitHub Desktop.
Save albertoperezf/275fe566ed231d49f30af42b19844cc7 to your computer and use it in GitHub Desktop.
Function to remove special characters (Accents, etc) from strings (es6)
// 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