Skip to content

Instantly share code, notes, and snippets.

@pseudosavant
Created October 17, 2019 18:02
Show Gist options
  • Save pseudosavant/abb1ec183ddac438f4158db626fdd5d4 to your computer and use it in GitHub Desktop.
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
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