Skip to content

Instantly share code, notes, and snippets.

@lesleh
Last active March 31, 2020 11:08
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 lesleh/6e275a3aa186476fe194c426943110c4 to your computer and use it in GitHub Desktop.
Save lesleh/6e275a3aa186476fe194c426943110c4 to your computer and use it in GitHub Desktop.
Case conversion between camel case and snake case
const toCamel = (s) => {
return s.replace(/([-_][a-z])/ig, ($1) => {
return $1.toUpperCase()
.replace('-', '')
.replace('_', '');
});
};
const toSnake = (s) => {
return s.split(/(?=[A-Z])/).join('_').toLowerCase();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment