Guest User

Untitled

a guest
Feb 14th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import {
  2. camelCase,
  3. mapKeys,
  4. mapValues,
  5. pick,
  6. isPlainObject,
  7. isArray
  8. } from 'lodash';
  9.  
  10. const toCamelCaseKey = obj => mapKeys(obj, (value, key) => camelCase(key));
  11.  
  12. // recursively traverse an object to convert all keys to camel case
  13. const toCamelCaseDeep = obj => {
  14. if (isPlainObject(obj)) {
  15. return mapValues(toCamelCaseKey(obj), toCamelCaseDeep);
  16. } else if (isArray(obj)) {
  17. return obj.map(toCamelCaseDeep);
  18. } else {
  19. return obj;
  20. }
  21. };
Add Comment
Please, Sign In to add comment