Skip to content

Instantly share code, notes, and snippets.

@Sharifur
Created April 8, 2022 05:41
Show Gist options
  • Save Sharifur/73bb17fcd74a5727bbdd68ab01863339 to your computer and use it in GitHub Desktop.
Save Sharifur/73bb17fcd74a5727bbdd68ab01863339 to your computer and use it in GitHub Desktop.
make any text ,description, title to slug
function converToSlug(slug){
let finalSlug = slug.replace(/[^a-zA-Z0-9]/g, ' ');
//remove multiple space to single
finalSlug = slug.replace(/ +/g, ' ');
// remove all white spaces single or multiple spaces
finalSlug = slug.replace(/\s/g, '-').toLowerCase().replace(/[^\w-]+/g, '-');
return finalSlug;
}
console.log(makeSlug("Car Cleaning Service From Best Cleaner [] () !@#$%^&*()_+))
//car-cleaning-service-from-best-cleaner---------_-
Car Cleaning Service From Best Cleaner [] () !@#$%^&*()_+
@Sharifur
Copy link
Author

Sharifur commented Apr 8, 2022

make any text ,description, title to slug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment