Last active
November 4, 2021 23:05
-
-
Save andersonbosa/d3693a3760c14e0564230d1535dd0adc to your computer and use it in GitHub Desktop.
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
/** | |
* Removes the accent from a String | |
* @see {@link https://gist.github.com/andersonbosa/d3693a3760c14e0564230d1535dd0adc} | |
* @param {String} rawString | |
* @returns {String} | |
*/ | |
function normalizeString (rawString) { | |
const replaceMap = { | |
'[ãâàáä]': 'a', | |
'[êèéë]': 'e', | |
'[îìíï]': 'i', | |
'[õôòóö]': 'o', | |
'[ûúùü]': 'u', | |
ç: 'c', | |
ñ: 'n' | |
} | |
return Object.keys(replaceMap) | |
.reduce( | |
(string, currentRegex) => | |
string.replace( | |
RegExp(currentRegex, 'ig'), | |
replaceMap[currentRegex] | |
), | |
String(rawString) | |
) | |
.toLowerCase() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment