# All files / src/util valid-index-value.js

100% Statements 14/14
100% Branches 12/12
100% Functions 2/2
100% Lines 14/14

    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

    361x
    3x

    358x
    150x

    208x
    2x

    206x
    2x

    204x
    18x
    18x
    25x

    18x

    186x

     // Checks whether the return value is a valid primary or secondary
    // index value in RethinkDB.
    export default function validIndexValue(val) {
      if (val === null) {
        return false
      }
      if ([ 'boolean', 'number', 'string' ].indexOf(typeof val) !== -1) {
        return true
      }
      if (val instanceof ArrayBuffer) {
        return true
      }
      if (val instanceof Date) {
        return true
      }
      if (Array.isArray(val)) {
        let isValid = true
        val.forEach(v => {
          isValid = isValid && validIndexValue(v)
        })
        return isValid
      }
      return false
    }