Last active
May 28, 2022 11:48
-
-
Save FrankFonts/a854906873db4a6c727fd38b0c749028 to your computer and use it in GitHub Desktop.
camelise(str) JS function
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
// The function camelise(str) changes dash-separated words | |
// like “my-short-string” into camel-cased “myShortString”. | |
// Removes all dashes, each word after dash becomes uppercased. | |
function camelize(str) { | |
return str.split('-').reduce((a, b) => { | |
return a + b[0].toUpperCase()+b.slice(1); | |
}); | |
} | |
// test | |
console.log(camelize('')); // returns ''; | |
console.log(camelize('background-color')); // returns 'backgroundColor'; | |
console.log(camelize('list-style-image')); // returns 'listStyleImage'; | |
console.log(camelize('-webkit-transition')); // returns 'WebkitTransition'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment