-
-
Save emcmanus/eb735299788c820b4eb85c38f02598e4 to your computer and use it in GitHub Desktop.
Revisions
-
emcmanus revised this gist
Mar 30, 2017 . 1 changed file with 15 additions and 14 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,30 +3,31 @@ /** * @example * import keysToCamelCase from './snakeToCamelCase'; * keysToCamelCase({bad_key: 1}); => {badKey: 1} * keysToCamelCase([{bad_key: 1}]); => [{badKey: 1}] */ function keysToCamelCase(object) { let camelCaseObject = _.cloneDeep(object); if (_.isArray(camelCaseObject)) { return _.map(camelCaseObject, keysToCamelCase); } else { camelCaseObject = _.mapKeys(camelCaseObject, (value, key) => { return _.camelCase(key); }); // Recursively apply throughout object return _.mapValues(camelCaseObject, (value) => { if (_.isPlainObject(value)) { return keysToCamelCase(value); } else if (_.isArray(value)) { return _.map(value, keysToCamelCase); } else { return value; } }); } } export default keysToCamelCase; -
emcmanus revised this gist
Mar 30, 2017 . 1 changed file with 3 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,11 +12,9 @@ export default function (object) { let camelCaseObject = _.cloneDeep(object); // Convert keys to camel case camelCaseObject = _.mapKeys(camelCaseObject, (value, key) => { return _.camelCase(key); }); // Recursively apply throughout object return _.mapValues( -
emcmanus revised this gist
Mar 30, 2017 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,9 +12,11 @@ export default function (object) { let camelCaseObject = _.cloneDeep(object); // Convert keys to camel case if (!_.isArray(camelCaseObject)) { camelCaseObject = _.mapKeys(camelCaseObject, (value, key) => { return _.camelCase(key); }); } // Recursively apply throughout object return _.mapValues( -
emcmanus revised this gist
Mar 3, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ export default function (object) { // Convert keys to camel case camelCaseObject = _.mapKeys(camelCaseObject, (value, key) => { return _.camelCase(key); }); // Recursively apply throughout object -
emcmanus revised this gist
Mar 3, 2017 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,19 @@ 'use strict'; /** * @example * import keysToCamelCase from './snakeToCamelCase'; * keysToCamelCase({bad_key: 1}); */ import 'lodash'; export default function (object) { let camelCaseObject = _.cloneDeep(object); // Convert keys to camel case camelCaseObject = _.mapKeys(camelCaseObject, (value, key) => { return key.replace(/(_\w)/g, match => match[1].toUpperCase()); }); // Recursively apply throughout object -
felixjung created this gist
Oct 23, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ 'use strict'; import 'lodash'; export default function (object) { let camelCaseObject = _.cloneDeep(object); // Convert keys to camel case camelCaseObject = _.mapKeys(camelCaseObject, (value, key) => { return key.replace(/(_\w)/, match => match[1].toUpperCase()); }); // Recursively apply throughout object return _.mapValues( camelCaseObject, value => { if (_.isPlainObject(value)) { return keysToCamelCase(value); } else if (_.isArray(value)) { return _.map(value, keysToCamelCase); } else { return value; } } ); }