Skip to content

Instantly share code, notes, and snippets.

@himalay
Created October 19, 2022 08:23
Show Gist options
  • Save himalay/5a3f5b315ca87537ca223c7188c27966 to your computer and use it in GitHub Desktop.
Save himalay/5a3f5b315ca87537ca223c7188c27966 to your computer and use it in GitHub Desktop.
Create a valid CSS class name from a string
function createCssClassName(str: string) {
return str
.toLowerCase()
.replace(/^(-?[0-9]|--)|[!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g, "")
.trim()
.replace(/\s+/g, "-");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment