Forked from marcelo-ribeiro/javascript-remove-accents.js
Last active
March 26, 2021 19:17
-
-
Save leandrodasilvaalves/408840338523f10ba6ef22d38e4bedc4 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 hidden or 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
function slugify(str) { | |
var map = { | |
'-': ' ', | |
'-': '_', | |
'a': 'á|à|ã|â|ä|À|Á|Ã|Â|Ä', | |
'e': 'é|è|ê|ë|É|È|Ê|Ë', | |
'i': 'í|ì|î|ï|Í|Ì|Î|Ï', | |
'o': 'ó|ò|ô|õ|ö|Ó|Ò|Ô|Õ|Ö', | |
'u': 'ú|ù|û|ü|Ú|Ù|Û|Ü', | |
'c': 'ç|Ç', | |
'n': 'ñ|Ñ', | |
'': '´|`|"|!|@|!|#|\\$|%|¨|&|\\(|\\)|\\=|\\+|\\{|\\}|\\[|\\]|ª|º|~|\\^|<|>|,|\\.|;|:|\\?|/|°|\\*|\\||\\-|_', | |
}; | |
for (var pattern in map) { | |
str = str.replace(new RegExp(map[pattern], 'g'), pattern); | |
}; | |
return str.replaceAll(" ", "-").toLowerCase(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment