Skip to content

Instantly share code, notes, and snippets.

@cs09g
Created February 18, 2020 07:39
Show Gist options
  • Save cs09g/cf011c5d9d7c8a0382fbce398acaaf55 to your computer and use it in GitHub Desktop.
Save cs09g/cf011c5d9d7c8a0382fbce398acaaf55 to your computer and use it in GitHub Desktop.
Convert Camel case to Kebab case
/*
* convert camel case string to kebab case string
* e.g. camelCaseString => camel-case-string
*
* note:
* It doesn't support for weird camel case such as "HTMLElement"
* The first letter of camel case string should be with lower case.
*/
function convertStringCamelToKebab(camel) {
return camel.split("").reduce((acc, char) => [...acc, char < "a" ? `-${char.toLowerCase()}` : char], []).join("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment