Created
October 17, 2019 18:02
-
-
Save pseudosavant/abb1ec183ddac438f4158db626fdd5d4 to your computer and use it in GitHub Desktop.
Convert strings or object keys from underscore_naming to camelCaseNaming. Example here: https://glitch.com/edit/#!/camelize
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
function camelize(s) { | |
return s.replace(/(?:-|_)([a-z])/g, (c) => c[1].toUpperCase()); | |
} | |
function camelizeObjectKeys(o) { | |
const entries = Object.entries(o); | |
const output = {}; | |
entries.forEach(([key, value]) => output[camelize(key)] = value); | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment