Last active
March 31, 2020 11:08
-
-
Save lesleh/6e275a3aa186476fe194c426943110c4 to your computer and use it in GitHub Desktop.
Case conversion between camel case and snake case
This file contains 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
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