Skip to content

Instantly share code, notes, and snippets.

@fabiofdsantos
Last active February 2, 2018 17:26
Show Gist options
  • Save fabiofdsantos/12ef1b66061ab363a1fa to your computer and use it in GitHub Desktop.
Save fabiofdsantos/12ef1b66061ab363a1fa to your computer and use it in GitHub Desktop.
An angularJS function to remove accents from an input string.
function removeAccents (str) {
map = {
'a' : 'á|à|ã|â|À|Á|Ã|Â',
'e' : 'é|è|ê|É|È|Ê',
'i' : 'í|ì|î',
'o' : 'ó|ò|ô|õ|Ó|Ò|Ô|Õ',
'u' : 'ú|ù|û|ü|Ú|Ù|Û|Ü',
'c' : 'ç|Ç',
'n' : 'ñ|Ñ'
};
angular.forEach(map, function (pattern, newValue) {
str = str.replace(new RegExp(pattern, 'g'), newValue);
});
return str;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment