title: How to refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed
body: <ul>
  <li>How to refactor this function to reduce the complexicity</li>
  <li>When I am using switch case at that time code complixity is more so how to reduce it
  <blockquote>
  <blockquote>
  <p>How to achive this</p>
  </blockquote>
  </blockquote>
  </li>
  </ul>
  <pre><code>
  var has = Object.prototype.hasOwnProperty
  
  
  
  var toString = Object.prototype.toString
  
  
  function isEmpty(val) {
   
    if (val == null) return true
    if ('boolean' == typeof val) return false
    if ('number' == typeof val) return val === 0
    if ('string' == typeof val) return val.length === 0
    if ('function' == typeof val) return val.length === 0
    if (Array.isArray(val)) return val.length === 0
    if (val instanceof Error) return val.message === ''
    if (val.toString == toString) {
      switch (val.toString()) {
        case '[object File]':
        case '[object Map]':
        case '[object Set]': {
          return val.size === 0
        }
        case '[object Object]': {
          for (var key in val) {
            if (has.call(val, key)) return false
          }
  
          return true
        }
      }
    }
    return false
  }
  module.exports = isEmpty
  </code></pre>