Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {
- camelCase,
- mapKeys,
- mapValues,
- pick,
- isPlainObject,
- isArray
- } from 'lodash';
- const toCamelCaseKey = obj => mapKeys(obj, (value, key) => camelCase(key));
- // recursively traverse an object to convert all keys to camel case
- const toCamelCaseDeep = obj => {
- if (isPlainObject(obj)) {
- return mapValues(toCamelCaseKey(obj), toCamelCaseDeep);
- } else if (isArray(obj)) {
- return obj.map(toCamelCaseDeep);
- } else {
- return obj;
- }
- };
Add Comment
Please, Sign In to add comment