Created
August 16, 2020 09:03
-
-
Save hallojoe/41b38b7db11319d2f0922009677b0740 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
const slug = s => s | |
.toString() // ensure string | |
.normalize("NFD") // convert to unicode normalization form using (N)normalization (F)form canonical (D)decomposition | |
// aka. remove accent and leave base | |
.replace(/[\u0300-\u036f]/g, "") // remove range combining grave accent to combining lating small letter x | |
.toLowerCase() // lower chars | |
.trim() // trim whitespace | |
.replace(/\s+/g, '-') // replace space(s) with dash | |
.replace(/[^\w-]+/g, "") // remove things not a-z A-Z 0-9 or - | |
.replace(/--+/g, '-') // replace double dash with single dash | |
// 90% SO copy/paste | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment