Skip to content

Instantly share code, notes, and snippets.

@IOIO72
Created May 10, 2019 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IOIO72/57b58ee89dc80452acc0be5b574a2f0e to your computer and use it in GitHub Desktop.
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 `-`
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