Skip to content

Instantly share code, notes, and snippets.

@senthilmpro
Created January 12, 2020 04:25
Show Gist options
  • Save senthilmpro/32645ce8c117116022d42b3ed5141b9f to your computer and use it in GitHub Desktop.
Save senthilmpro/32645ce8c117116022d42b3ed5141b9f to your computer and use it in GitHub Desktop.
JS kebab case
const toKebabCase = str =>
str &&
str
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
.map(x => x.toLowerCase())
.join('-');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment