Skip to content

Instantly share code, notes, and snippets.

@arnissolle
Forked from mathewbyrne/slugify.js
Last active May 20, 2017 09:19
Show Gist options
  • Select an option

  • Save arnissolle/e623b714467c61d42ea7e7f22db2a048 to your computer and use it in GitHub Desktop.

Select an option

Save arnissolle/e623b714467c61d42ea7e7f22db2a048 to your computer and use it in GitHub Desktop.
JavaScript Slugify
function slugify(text) {
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+|-+$/g, ''); // Trim -
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment