Created
April 9, 2020 17:09
-
-
Save wall-e-08/eb5cd9e72dd0d5e199c55adf6405c7d6 to your computer and use it in GitHub Desktop.
This file contains 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
const _slugify = str => { | |
str = str.toLowerCase(); | |
str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars | |
.trim() // remove starting or ending whitespace before replacing whitespace | |
.replace(/\s+/g, '-') // collapse whitespace and replace by - | |
.replace(/-+/g, '-'); // collapse dashes | |
return str; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment