all files / src/utils/ composeConstants.js

92.86% Statements 26/28
61.11% Branches 11/18
100% Functions 5/5
86.67% Lines 13/15
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                            
import _ from 'lodash';
 
export default function composeConstants(obj, prefix) {
  if (obj.constructor == Object) {
    Object.keys(obj).forEach(key => {
      obj[key] = composeConstants(obj[key], prefix ? `${prefix}.${key}` : key);
    });
 
    return obj;
  }
 
  Eif (obj.constructor == Array) E{
    Iif (!prefix) {
      return { ...obj };
    }
    const tmp = {};
    obj.forEach(key => {
      tmp[key] = `${prefix}.${key}`;
    });
    return tmp;
  }
 
  return prefix ? `${prefix}.${obj}` : { obj };
}