As many of you will know, almost every programming language has a standard casing system; unfortunately, we have not been able to agree on a singular system to use and now must frequently switch between camelCase, snake_case, PascalCase and kebab-case.
Now I know what you're thinking... wouldn't it be nice if we had a program that could convert from one casing to another?
Well - soon we're going to have plenty!!! (This is where you come in)
Challenge
You're job is to write a program/function that will take an input string, and a casing system. It will then print/return the converted string.
Inputs:
You're program will receive two inputs, an alphabetic string that is to be converted and a string that will always be one of kebab
camel
pascal
or snake
.
Outputs:
You're program should output a string that conforms to the new casing. You can assume the input string is valid and will only conform to one of the casings (i.e. it won't be mixed_Casing
).
As most programming languages prefer lowercase variable names, you should convert all letters to lowercase unless it is needed to be upper case for the casing requirements.
- Snake Case: All letters are lower case, with underscores separating words.
- Kebab Case: All letters are lower case, with hyphens separating words.
- Camel Case: The first letter of every word after the first is capitalized, with no spaces.
- Pascal Case: The first letter of every word is capitalized, with no spaces.
Test Cases:
"aJavaVariable", "snake" = "a_java_variable"
"a_python_variable", "kebab" = "a-python-variable"
"golf", "camel" = "golf"
"camelToPascal", "pascal" = "CamelToPascal"
"PascalToCamel", "camel" = "pascalToCamel"
"", "snake" = ""
"doHTMLRequest", "kebab" = "do-h-t-m-l-request"
<!-- Run the snippet to see the leaderboard. Report any bugs to @ozewski on Github. --> <iframe src="https://ozewski.github.io/ppcg-leaderboard/?id=216396" width="100%" height="100%" style="border:none;">Oops, your browser is too old to view this content! Please upgrade to a newer version of your browser that supports HTML5.</iframe><style>html,body{margin:0;padding:0;height:100%;overflow:hidden}</style>