Skip to content

Instantly share code, notes, and snippets.

@dutchcelt
Created October 26, 2023 13:02
Show Gist options
  • Save dutchcelt/7a00676e2ad010400e4b4331d1bb52bd to your computer and use it in GitHub Desktop.
Save dutchcelt/7a00676e2ad010400e4b4331d1bb52bd to your computer and use it in GitHub Desktop.
camelCase and PascalCase
/**
* 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