Lodash Ciąg do ślimaka
Method 1:
var slug = (req.body.package_name).toString().toLowerCase().replace(/\s+/g, '-').replace(/[^\u0100-\uFFFF\w\-]/g,'-').replace(/\-\-+/g, '-').replace(/^-+/, '').replace(/-+$/, '');
console.log(slug);
Text Tested : "What Is a CSS Framework? (And When to Use 6 Popular Options) "
Output : what-is-a-css-framework-and-when-to-use-6-popular-options
Method 2 with function:
function slugify(text){
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\u0100-\uFFFF\w\-]/g,'-') // Remove all non-word chars ( fix for UTF-8 chars )
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
var slug = slugify(Text);
console.log(slug);
Beautiful Buzzard