Created
October 26, 2023 13:02
-
-
Save dutchcelt/7a00676e2ad010400e4b4331d1bb52bd to your computer and use it in GitHub Desktop.
camelCase and PascalCase
This file contains hidden or 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
/** | |
* pascalcase | |
* @param {string} s | |
*/ | |
const pascalcase = s => { | |
const wordList = s.split(/-|_|\./); | |
let str = ''; | |
for (const word of wordList) { | |
str += word.charAt(0).toUpperCase() + word.slice(1); | |
} | |
return str; | |
}; | |
/** | |
* camelcase | |
* @param {string} s | |
*/ | |
const camelcase = s => { | |
const str = pascalcase(s); | |
return str.charAt(0).toLowerCase() + str.slice(1); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment