Skip to content

Instantly share code, notes, and snippets.

@belchior
Last active October 27, 2017 21:35
Show Gist options
  • Select an option

  • Save belchior/2c6468045e53bd6dd39c8ae33c0c9875 to your computer and use it in GitHub Desktop.

Select an option

Save belchior/2c6468045e53bd6dd39c8ae33c0c9875 to your computer and use it in GitHub Desktop.
function removeAccent(text) {
/*
Octal representation of letters
Execute the above code at browser console to show octal number of the chars
for(var i = 300; i < 380; i += 1, console.log(i + ' - ', String.fromCharCode(parseInt(i, 8)))) {}
*/
var accent = [
/[\300-\306]/g, /[\340-\346]/g, // A, a
/[\310-\313]/g, /[\350-\353]/g, // E, e
/[\314-\317]/g, /[\354-\357]/g, // I, i
/[\322-\330]/g, /[\362-\370]/g, // O, o
/[\331-\334]/g, /[\371-\374]/g, // U, u
/[\321]/g, /[\361]/g, // N, n
/[\307]/g, /[\347]/g, // C, c
];
var chars = ['A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u', 'N', 'n', 'C', 'c'];
for (var i = 0; i < accent.length; i++) {
text = text.replace(accent[i], chars[i]);
}
return text;
}
@belchior
Copy link
Author

Usage:

removeAccent('ÁÉÍÓÚ âêìõú Ññ Çç');
> "AEIOU aeiou Nn Cc"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment