Skip to content

Instantly share code, notes, and snippets.

View benbkk's full-sized avatar
🎯
Focusing

Beta Anggoro (Ben) benbkk

🎯
Focusing
View GitHub Profile
@benbkk
benbkk / slugify.js
Created February 12, 2017 13:08 — forked from mathewbyrne/slugify.js
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(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}