Last active
February 6, 2016 22:31
-
-
Save Sigmus/7162848 to your computer and use it in GitHub Desktop.
Slugify
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
| var slugify = function(text){ | |
| /** Cria um nome web-safe sem acentos e espaços a partir de um nome. */ | |
| var lettersFrom = 'áàãâäéèêëíìîïóòõôöúùûüçñ', lettersTo = 'aaaaaeeeeiiiiooooouuuucn', newText = '', text = text.toLowerCase().replace(' ', '-'); | |
| for (var i = 0; i < text.length; i++) { | |
| if (lettersFrom.search(text.substr(i,1)) >= 0) newText += lettersTo.substr(lettersFrom.search(text.substr(i, 1)), 1); | |
| else newText += text.substr(i, 1); | |
| } | |
| return newText; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Sigmus troca o .replace(' ', '-'), por .split(' ').join('-')