Coding since 11yo, that makes it over 30 years now ~~~
Have a PhD in Comp Sci ~~~
Love to go on bike tours ~~~
I try to stay as generalist as I can in this crazy wide place coding is at now.
I agree with SavagePixie. replace is the way to go if you're in JS!
Here's an extended version that covers all the cases I can think of...
consttoUpperCamelCase=str=>str.replace(/[^a-zA-Z]*([a-zA-Z]?)([a-z]+|[A-Z]*)/g,(_,firstLetter,rest)=>firstLetter.toUpperCase()+rest.toLowerCase());>['Fudge And Sprite',// Words'fudge and sprite',// words'fudge-and-sprite',// kebab-case'fudge_and_sprite',// underscore_case'fudgeAndSprite',// lowerCamelCase'FudgeAndSprite',// UpperCamelCase stays as it is'FUDGE_AND_SPRITE',// CONSTANT_CASE'fUDGEaNDsPRITE',// um, uPSIDEDOWNcASE I guess'>>> Fudge, (and SPRITE!)'// or whatevs].map(toUpperCamelCase);<["FudgeAndSprite","FudgeAndSprite","FudgeAndSprite","FudgeAndSprite","FudgeAndSprite","FudgeAndSprite","FudgeAndSprite","FudgeAndSprite","FudgeAndSprite"]
I agree with SavagePixie.
replace
is the way to go if you're in JS!Here's an extended version that covers all the cases I can think of...
Regex:
test in Debuggex