Skip to content

Instantly share code, notes, and snippets.

@lelotnk
Forked from marioluan/remover-acentos.js
Created October 23, 2014 23:40
Show Gist options
  • Save lelotnk/dc92ea5ca2c708b5150f to your computer and use it in GitHub Desktop.
Save lelotnk/dc92ea5ca2c708b5150f to your computer and use it in GitHub Desktop.
/**
* Remove acentos de caracteres
* @param {String} stringComAcento [string que contem os acentos]
* @return {String} [string sem acentos]
*/
function removerAcentos( newStringComAcento ) {
var string = newStringComAcento;
var mapaAcentosHex = {
a : /[\xE0-\xE6]/g,
A : /[\xC0-\xC6]/g,
e : /[\xE8-\xEB]/g,
E : /[\xC8-\xCB]/g,
i : /[\xEC-\xEF]/g,
I : /[\xCC-\xCF]/g,
o : /[\xF2-\xF6]/g,
O : /[\xD2-\xD6]/g,
u : /[\xF9-\xFC]/g,
U : /[\xD9-\xDC]/g,
c : /\xE7/g,
C : /\xC7/g,
n : /\xF1/g,
N : /\xD1/g,
};
for ( var letra in mapaAcentosHex ) {
var expressaoRegular = mapaAcentosHex[letra];
string = string.replace( expressaoRegular, letra );
}
return string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment