Skip to content

Instantly share code, notes, and snippets.

@rap0so
Last active February 15, 2019 13:08
Show Gist options
  • Save rap0so/526b7310427855e44bd2f433251d302e to your computer and use it in GitHub Desktop.
Save rap0so/526b7310427855e44bd2f433251d302e to your computer and use it in GitHub Desktop.
Remove accent
/**
* Normalizes the string to lowercase letters and no accents
* @param {string} str string to normalize
* @return {string} return string normalized
*/
const removeAccent = (str) => {
const replaceMap = {
'[ãâàáä]': 'a',
'[êèéë]': 'e',
'[îìíï]': 'i',
'[õôòóö]': 'o',
'[ûúùü]': 'u',
ç: 'c',
ñ: 'n'
};
return Object.keys(replaceMap).reduce((string, currentRegex) => {
return string
.replace(RegExp(currentRegex, 'ig'), replaceMap[currentRegex])
.replace(/[\s]/g, '-')
.replace(/[\d]/g, '');
}, str);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment