Created
May 10, 2019 14:34
-
-
Save IOIO72/57b58ee89dc80452acc0be5b574a2f0e to your computer and use it in GitHub Desktop.
As an alternative conversion to encodeURIComponent this function removes every character except the alphabet and `-` and replaces spaces by `-`
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 normalizeURIComponentName = str => { | |
const stripChars = /[^a-z-\s]/gi; | |
return ( | |
str.toLowerCase().replace(stripChars, '').replace(/\s/gi, '-') || str | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment