Skip to content

Instantly share code, notes, and snippets.

@digitalconceptvisuals
Created July 30, 2020 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitalconceptvisuals/6a89dd08afed8c22b37268d80182a53a to your computer and use it in GitHub Desktop.
Save digitalconceptvisuals/6a89dd08afed8c22b37268d80182a53a to your computer and use it in GitHub Desktop.
**
* Adding new functionality does not require modify "code"
* We can simply update our map with new case converter
*/
function changeCase(word, caseType) {
const caseMap = {
"lower": convertToLower,
"camel": convertToCamel,
"proper": convertToProper
}
// Convert switch case to map(string, function)
caseType = caseType.trim().toLowerCase();
var conversion = caseMap[caseType];
// Make sure we got the conversion function
return conversion? caseMap[caseType](word) : null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment