Skip to content

Instantly share code, notes, and snippets.

View blinkylights23's full-sized avatar

Paul Smith blinkylights23

  • Paris, France
  • 14:07 (UTC +02:00)
View GitHub Profile
function slugify(text) {
return text.toString().toLowerCase().trim()
.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
}