Created
October 10, 2013 18:27
-
-
Save marioplumbarius/6923123 to your computer and use it in GitHub Desktop.
Funcao marota para remover acentos de strings. Foi utilizado expressao regular em cima de caracteres representados na base hexadecimal.
This file contains hidden or 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
/** | |
* 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, | |
e : /[\xE8-\xEB]/g, | |
i : /[\xEC-\xEF]/g, | |
o : /[\xF2-\xF6]/g, | |
u : /[\xF9-\xFC]/g, | |
c : /\xE7/g, | |
n : /\xF1/g | |
}; | |
for ( var letra in mapaAcentosHex ) { | |
var expressaoRegular = mapaAcentosHex[letra]; | |
string = string.replace( expressaoRegular, letra ); | |
} | |
return string; | |
} |
Usando esse script com a alteração do @lelotnk, fiz uma função para criar slugs em JS: https://gist.github.com/jesobreira/d769aab503847e014b3c
Me ajudou demais essa função! só tive que passá-la para Typescript... segue o link, caso alguém precise:
https://gist.github.com/GiovannyLucas/8af0365b9978c667f875e34741d49818
E se eu quiser remover o conteúdo de uma table html inteira? Como que faço?
Muito bom, ajudou bastante!
Muito Obrigado!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pessoal, cuidado com a função abaixo, não é compatível com android webview nem internet explorer
s.normalize('NFD')
Se o seu site for aberto através de um webview (pode ser aberto em apps onde seus anúncios aparecem)
Valide a existência da função em strings:
if("".normalize){ seuTexto.normalize('NFD')... }