All files / Shared/Utils mapDataToCamelCase.js

100% Statements 15/15
100% Branches 8/8
100% Functions 4/4
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 221x   1x   1986x   402x     1668x 1668x 1668x 372x 1614x 126x   1668x 1668x        
import is from 'ramda/src/is';
 
import camelCase from './camelCase';
 
const isObject = value => is(Object, value) && !Array.isArray(value);
 
const mapDataToCamelCase = inputData =>
    Object.keys(inputData)
        .reduce((outputData, next) => {
            const key = camelCase(next);
            let value = inputData[next];
            if (Array.isArray(value)) {
                value = value.map(child => (isObject(child) ? mapDataToCamelCase(child) : child));
            } else if (isObject(value)) {
                value = mapDataToCamelCase(value);
            }
            outputData[key] = value;
            return outputData;
        }, {});
 
export default mapDataToCamelCase;