Forked from marcelo-ribeiro/javascript-remove-accents.js
Created
May 13, 2021 21:36
-
-
Save N0NameF0und/703a3a6d6e2ca921924fb7316a8f772d to your computer and use it in GitHub Desktop.
An Javascript function to remove accents, spaces and set lower case from an input string.
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
const slugify = str => { | |
const map = { | |
'-' : ' ', | |
'-' : '_', | |
'a' : 'á|à|ã|â|ä|À|Á|Ã|Â|Ä', | |
'e' : 'é|è|ê|ë|É|È|Ê|Ë', | |
'i' : 'í|ì|î|ï|Í|Ì|Î|Ï', | |
'o' : 'ó|ò|ô|õ|ö|Ó|Ò|Ô|Õ|Ö', | |
'u' : 'ú|ù|û|ü|Ú|Ù|Û|Ü', | |
'c' : 'ç|Ç', | |
'n' : 'ñ|Ñ' | |
}; | |
for (var pattern in map) { | |
str = str.replace(new RegExp(map[pattern], 'g'), pattern); | |
} | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment