Forked from marcelo-ribeiro/javascript-remove-accents.js
Created
October 28, 2020 13:00
-
-
Save iqbmo04/15e7a588158e589b066078a0f8b9e7bf 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