Created
February 18, 2020 07:39
-
-
Save cs09g/cf011c5d9d7c8a0382fbce398acaaf55 to your computer and use it in GitHub Desktop.
Convert Camel case to Kebab case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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