Last active
February 15, 2019 13:08
-
-
Save rap0so/526b7310427855e44bd2f433251d302e to your computer and use it in GitHub Desktop.
Remove accent
This file contains 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
/** | |
* 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