Forked from marcelo-ribeiro/javascript-remove-accents.js
Created
November 22, 2019 08:56
-
-
Save adriancmiranda/d21a4b84c6c88a3b4e38c11ad73e7403 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' : 'ñ|Ñ' | |
}; | |
str = str.toLowerCase(); | |
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