Skip to content

Instantly share code, notes, and snippets.

@tosipaulo
Created October 12, 2017 00:23
Show Gist options
  • Select an option

  • Save tosipaulo/f8f0b14063cb293bcb711558a9feb25b to your computer and use it in GitHub Desktop.

Select an option

Save tosipaulo/f8f0b14063cb293bcb711558a9feb25b to your computer and use it in GitHub Desktop.
URL amigável
const urlFriendlyHandler = (string) =>
string.toLowerCase().trim()
.replace(/[áàãâä]/g, "a")
.replace(/[éè?êë]/g, "e")
.replace(/[íìiîï]/g, "i")
.replace(/[óòõôö]/g, "o")
.replace(/[úùuûü]/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