Skip to content

Instantly share code, notes, and snippets.

@Sigmus
Last active February 6, 2016 22:31
Show Gist options
  • Save Sigmus/7162848 to your computer and use it in GitHub Desktop.
Save Sigmus/7162848 to your computer and use it in GitHub Desktop.
Slugify
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;
};
@nicholasess
Copy link

@Sigmus troca o .replace(' ', '-'), por .split(' ').join('-')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment