All files compatible.ts

100% Statements 27/27
100% Branches 6/6
100% Functions 2/2
100% Lines 27/27

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 22 23 24 25 26 27 281x 1x 1x 1x 1x 1x 1x 8x 8x 8x 8x 8x 8x 5x 5x 5x 5x 6x 3x 3x 8x 8x 8x 8x 8x 8x 8x  
import { cloneDeep } from "lodash";
 
interface CompatibleWithDefaultConfigParams {
  [key: string]: any;
}
// todo  {name:'',book:[1,2,3],test:{age:1,ss:{1233}}}
export function CompatibleWithDefaultConfig(
  defaultConfig: CompatibleWithDefaultConfigParams,
  listData: Array<any> | CompatibleWithDefaultConfigParams = {}
) {
  for (const key in defaultConfig) {
    if (Object.prototype.hasOwnProperty.call(defaultConfig, key)) {
      if (Array.isArray(listData)) {
        listData.forEach((item) => {
          const cloneItem = cloneDeep(defaultConfig[key]);
          item[key] = item[key] ?? cloneItem;
        });
      } else {
        listData[key] = listData[key] ?? cloneDeep(defaultConfig[key]);
      }
      // if(typeof  defaultConfig[key] === 'object'){  // {}
      //   CompatibleWithDefaultConfig(defaultConfig[key],listDataData[key])
      // }
    }
  }
  return listData;
}