DavyJonesLocker/client_side_validations

View on GitHub
src/utils.js

Summary

Maintainability
A
1 hr
Test Coverage
export const addClass = (element, customClass) => {
  if (customClass) {
    element.classList.add(...customClass.split(' '))
  }
}

export const arrayHasValue = (value, otherValues) => {
  for (let i = 0, l = otherValues.length; i < l; i++) {
    if (value === otherValues[i]) {
      return true
    }
  }

  return false
}

export const createElementFromHTML = (html) => {
  const element = document.createElement('div')
  element.innerHTML = html

  return element.firstChild
}

export const isValuePresent = (value) => {
  return !/^\s*$/.test(value || '')
}

export const removeClass = (element, customClass) => {
  if (customClass) {
    element.classList.remove(...customClass.split(' '))
  }
}

export default {
  addClass,
  arrayHasValue,
  createElementFromHTML,
  isValuePresent,
  removeClass
}