Last active
December 8, 2023 17:34
-
-
Save craigerskine/3a984c8fdc3a40dfed3051394195c2f3 to your computer and use it in GitHub Desktop.
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
slugify(text) { | |
return text?.toString() | |
.toLowerCase() | |
.trim() | |
.replace(/\.+/g, '-') // . to - (this can be removed - my specific usecase) | |
.replace(/&/g, '-and-') // & to -and- (this can be removed - my specific usecase) | |
.normalize('NFKD') // unicode normalization | |
.replace(/[^\w\-]+/g, '') // remove other crazy chars | |
.replace(/\s+/g, '-') // space to - | |
.replace(/\-\-+/g, '-') // multiple - to single - | |
.replace(/^-+/, "") // remove - from start | |
.replace(/-+$/, "") // remove - from end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment