All files descend-from.js

88.89% Statements 16/18
78.57% Branches 11/14
100% Functions 2/2
88.24% Lines 15/17
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 297x   1x 9x 3x   6x     6x   6x 3x   3x     3x   3x 7x 2x   5x     1x    
const hasClass = (node, className) => ` ${node.classList} `.includes(` ${className} `);
 
module.exports = (node, from) => {
  if (from && typeof from === 'object')
    return from.contains(node);
 
  Iif (typeof from !== 'string')
    return false;
 
  from = from.trim();
 
  if (from.charAt(0) === '#')
    return document.getElementById(from.replace('#', '')).contains(node);
 
  Iif (from.charAt(0) !== '.')
    return false;
 
  from = from.replace('.', '');
 
  while (node !== document.body.parentNode) {
    if (hasClass(node, from))
      return true;
 
    node = node.parentNode;
  }
 
  return false;
};