Skip to content

Instantly share code, notes, and snippets.

@Ugarz
Created January 24, 2018 14:17
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 Ugarz/d21742050df9495bf67615519a6e178b to your computer and use it in GitHub Desktop.
Save Ugarz/d21742050df9495bf67615519a6e178b to your computer and use it in GitHub Desktop.
Javascript tricks

Force an object to have camelCase keys

const camelCase = require('lodash/camelCase');

/**
 * Force object key to camelCase
 * @param  {object} obj
 * @return {object} newObj
 */
const toCamelCase = obj => reduce(obj, (newObj, value, key) => {
  newObj[camelCase(key)] = value;
  return newObj;
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment