function slug(str) {
return str
.toLowerCase() // Convert to lowercase
.trim() // Remove leading and trailing spaces
.replace(/[^\w\s-]/g, '') // Remove all non-word characters
.replace(/\s+/g, '-') // Replace spaces with hyphens
.replace(/--+/g, '-'); // Replace multiple hyphens with a single hyphen
}
let a = " This is an example of slug / // ///"
console.log(slug(a));