Skip to content

Instantly share code, notes, and snippets.

@wallace7souza
Forked from mathewbyrne/slugify.js
Last active September 8, 2017 12:01
Show Gist options
  • Save wallace7souza/9f679bbf93c91d1e36f8ad4adc1395b2 to your computer and use it in GitHub Desktop.
Save wallace7souza/9f679bbf93c91d1e36f8ad4adc1395b2 to your computer and use it in GitHub Desktop.
Javascript Slugify pt-BR - Adicionado caracteres do português
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/[àáâãäå]/g,"a")
.replace(/[éèëê]/g,"e")
.replace(/[ìíîï]/g,"i")
.replace(/[òóôõ]/g,"o")
.replace(/[úùüû]/g,"u")
.replace(/ç/g,"c")
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment