# All files / src/utils value-names.js

65.63% Statements 21/32
47.83% Branches 11/23
100% Functions 2/2
66.67% Lines 18/27

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
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    402x

    2x
    421x
    421x
    421x

    421x

    421x
    209x

    2x
    421x
    421x
    421x
    209x

    209x

    209x
    209x
    209x

    2x
     var getByClass = require('./get-by-class')

    const getDefinitionFromName = (name, valueNames) => {
      for (var i = 0, il = valueNames.length; i < il; i++) {
        var valueName = valueNames[i]
        Iif (valueName.data) {
          var data = valueName.data
          for (var j = 0, jl = data.length; j < jl; j++) {
            if (data[j] === name) {
              return { data: name }
            }
          }
        } else Iif (valueName.attr && valueName.name && valueName.name == name) {
          return valueName
        } else if (valueName === name) {
          return name
        }
      }
    }
    const set = (el, name, value, valueNames) => {
      var elm = undefined,
        valueName = getDefinitionFromName(name, valueNames)
      if (!valueName) return
      Iif (valueName.data) {
        el.setAttribute('data-' + valueName.data, value)
      } else Iif (valueName.attr && valueName.name) {
        elm = getByClass(el, valueName.name, true)
        if (elm) {
          elm.setAttribute(valueName.attr, value)
        }
      } else {
        elm = getByClass(el, valueName, true)
        Eif (elm) {
          elm.innerHTML = value
        }
      }
    }

    module.exports = { getDefinitionFromName, set }