function slugify(text, separator)
Converts a string to a URL-friendly slug
Name↑ | Type | Required | Description |
|---|---|---|---|
| separator | string | Optional | The separator character to use |
| text | string | Required | The text to convert to a slug |
function slugify(text, separator = '-') {
return text
.toString()
.toLowerCase()
.trim()
.replace(/[^\w\s-]/g, '')
.replace(/[\s_-]+/g, separator)
.replace(/^-+|-+$/g, '');
}