# All files / src converters.js

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

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19

    48x

    28x

    28x
    36x
    36x

    48x
    48x

     // Convert object or array values
    export 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]'
    }