# All files / serialization/utils prepost-array-of.js

13.33% Statements 2/15
0% Branches 0/17
28.57% Functions 2/7
20% Lines 2/10

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
    4x

    6x

     export function preArrayOf (index, detect, convert) {
      return (...args) => {
        if (Array.isArray(args[index])) {
          args[index] = args[index].map((item) => detect(item) ? convert(item) : item)
        }

        return args
      }
    }

    // specify falsey prop for root
    export function postArrayOf (prop, detect, convert) {
      return (res) => {
        if (prop && res && Array.isArray(res[prop])) {
          res[prop] = res[prop].map((item) => detect(item) ? convert(item) : item)
        } else if (!prop && Array.isArray(res)) {
          res = res.map((item) => detect(item) ? convert(item) : item)
        }

        return res
      }
    }