All files / serialization/utils convert-values.js

80% Statements 8/10
70% Branches 7/10
75% Functions 3/4
87.5% Lines 7/8

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    50x   36x       36x 44x 44x         50x 50x    
// Convert object or array values
export default function convertValues (obj, detect, convert) {
  if (!isObjectOrArray(obj)) return obj
 
  Iif (Array.isArray(obj)) {
    return obj.map((value, i) => detect(value) ? convert(value) : convertValues(value, detect, convert))
  }
 
  return Object.keys(obj).reduce((clone, key) => {
    clone[key] = detect(obj[key]) ? convert(obj[key]) : convertValues(obj[key], detect, convert)
    return clone
  }, {})
}
 
function isObjectOrArray (obj) {
  const type = Object.prototype.toString.call(obj)
  return type === '[object Object]' || type === '[object Array]'
}