Skip to content

Instantly share code, notes, and snippets.

@daformat
Created June 28, 2023 09:46
Show Gist options
  • Save daformat/3f3699f09307518b9d2e3f934481b029 to your computer and use it in GitHub Desktop.
Save daformat/3f3699f09307518b9d2e3f934481b029 to your computer and use it in GitHub Desktop.
Convert camel case to kebab case
// convert camelCase to kebab-case
const kebabize = (str) =>
str.replace(
/[A-Z]+(?![a-z])|[A-Z]/g,
(match, offset) => (offset ? '-' : '') + match.toLowerCase()
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment