All files descended-from.js

100% Statements 18/18
92.86% Branches 13/14
100% Functions 2/2
100% Lines 17/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 13x 3x   10x 3x   7x   7x 3x   4x 1x   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);
 
  if (typeof from !== 'string')
    return false;
 
  from = from.trim();
 
  if (from.charAt(0) === '#')
    return document.getElementById(from.replace('#', '')).contains(node);
 
  if (from.charAt(0) !== '.')
    return false;
 
  from = from.replace('.', '');
 
  while (node !== document.body.parentNode) {
    if (hasClass(node, from))
      return true;
 
    node = node.parentNode;
  }
 
  return false;
};