Forked from marcelo-ribeiro/javascript-remove-accents.js
Created
August 21, 2020 11:38
-
-
Save sh4hids/155f24edefeb8ec9077150b38770e474 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; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment