Skip to content

Instantly share code, notes, and snippets.

@thinhbuzz
Created November 28, 2018 04:36
Show Gist options
  • Save thinhbuzz/a41e5d0934ea697f52607a56273d6924 to your computer and use it in GitHub Desktop.
Save thinhbuzz/a41e5d0934ea697f52607a56273d6924 to your computer and use it in GitHub Desktop.
javascript kebab case convert
function kebabCase(str) {
return str.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, match => '-' + match.toLowerCase()) // lower case and add -
.replace(/[^\w]/g, '-') // replace non-word characters by -
.replace(/-+/g, '-') // remove multiple - characters
.replace(/^-|-$/g, ''); // trim first and last - character
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment