Skip to content

Instantly share code, notes, and snippets.

@IgorHalfeld
Created November 28, 2019 01:16
Show Gist options
  • Save IgorHalfeld/6e19b6544313cf734304f03b702ccd62 to your computer and use it in GitHub Desktop.
Save IgorHalfeld/6e19b6544313cf734304f03b702ccd62 to your computer and use it in GitHub Desktop.
const slugify = input => input
.toString()
.toLowerCase()
.replace(/[áãâà]/gi, 'a')
.replace(/[éê]/gi, 'e')
.replace(/í/gi, 'i')
.replace(/[óõô]/gi, 'o')
.replace(/ú/gi, 'u')
.replace(/ñ/gi, 'n')
.replace(/ç/g, 'c')
.replace(/[\s_]+/g, '-')
.replace(/[^\w-]+/g, '')
.replace(/-+/g, '-')
.replace(/^-+/, '')
.replace(/-+$/, '');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment