Skip to content

Instantly share code, notes, and snippets.

@vyper
Created October 15, 2012 23:58
Show Gist options
  • Save vyper/3896453 to your computer and use it in GitHub Desktop.
Save vyper/3896453 to your computer and use it in GitHub Desktop.
String.prototype.slugify = function() {
return this.toLowerCase().trim()
.replace(/[áàãâä]/g, "a")
.replace(/[éèẽêë]/g, "e")
.replace(/[íìĩîï]/g, "i")
.replace(/[óòõôö]/g, "o")
.replace(/[úùũûü]/g, "u")
.replace(/ç/g, "c")
.replace(/(\ |_)+/, " ")
.replace(/(^-+|-+$)/, "")
.replace(/[^a-z0-9]+/g, "-");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment