Created
November 20, 2018 18:42
-
-
Save alex-cory/2f503aeb3b3a22f3a69cdf8750f9a878 to your computer and use it in GitHub Desktop.
converts strings to a different case
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
/** | |
* this_is_snake_case | |
* thisIsCamelCase | |
* this-is-cabob-case | |
*/ | |
const camelToSnakeCase = w => w.replace(/([A-Z])/g, l => '_' + l.toLowerCase()) | |
const toCamel = s => s.replace(/(\-[a-z])/g, l => l.toUpperCase().replace('-','')) | |
const cabobToCamelCase = s => s.replace(/([A-Z])/g, l => "-"+l.toLowerCase()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment