Convert a string to URL slug
JavaScript
const slugify = (str) => str
.toLowerCase()
.replace(/\s+/g, '-')
.replace(/[^\w-]+/g, '')
Examples
slugify('Chapter One: Once upon a time...') // 'chapter-one-once-upon-a-time'
const slugify = (str) => str
.toLowerCase()
.replace(/\s+/g, '-')
.replace(/[^\w-]+/g, '')
slugify('Chapter One: Once upon a time...') // 'chapter-one-once-upon-a-time'