src/services/utils.js
/** Takes a data object and returns a nested object based on the keys and the nestingString
*/
Takes a data object and returns a nested object based on the keys and the nestingString
Takes a data object and returns a nested object based on the keys and the nestingString
function formatNestedData(data, nestingString = '.') {
  const formattedObj = {};
  Object.keys(data).forEach((fieldKey) => {
    const value = data[fieldKey];
    const keys = fieldKey.split(nestingString);
    const nestedSubObj = keys.reverse().reduce((acc, currentKey, index) => {
      if (index === 0) {
        acc[currentKey] = value;
        return acc;
      }
      acc = merge({}, { [currentKey]: acc });
      return acc;
    }, {});
    merge(formattedObj, nestedSubObj);
  });
  return formattedObj;
}
function formatNestedData ( data , nestingString = '.' ) { const formattedObj = { } ; Object . keys ( data ) . forEach ( ( fieldKey ) => { const value = data [ fieldKey ] ; const keys = fieldKey . split ( nestingString ) ; const nestedSubObj = keys . reverse ( ) . reduce ( ( acc , currentKey , index ) => { if ( index === 0 ) { acc [ currentKey ] = value ; return acc ; } acc = merge ( { } , { [ currentKey ] : acc } ) ; return acc ; } , { } ) ; merge ( formattedObj , nestedSubObj ) ; } ) ; return formattedObj ; }
Takes a data object and returns a nested object based on the keys and the nestingString
Takes a data object and returns a nested object based on the keys and the nestingString