Created
April 8, 2022 05:41
-
-
Save Sharifur/73bb17fcd74a5727bbdd68ab01863339 to your computer and use it in GitHub Desktop.
make any text ,description, title to slug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [] () !@#$%^&*()_+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
make any text ,description, title to slug