All files / src/lib extract-node-recursively.ts

100% Statements 10/10
100% Branches 4/4
100% Functions 3/3
100% Lines 10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 253x               3x 1486x 544x     942x   942x 1867x 3392x   1867x     942x    
import nodeMatchesFilter = require('./node-matches-filter');
 
import { IFilter } from '../interfaces/IFilter';
import { IFilterGroup } from '../interfaces/IFilterGroup';
 
/**
 * Whiteliste a node if it (or one of the nodes parents) matches the given filter.
 */
export = function extractNodeRecursively(node: { parent: any }, filterGroups: IFilterGroup[]): boolean {
  if (node.parent && node.parent.type !== `root`) {
    return extractNodeRecursively(node.parent, filterGroups);
  }
 
  let extractNode = false;
 
  filterGroups.some((filterGroup) => {
    extractNode = filterGroup.filter(
      (filter) => !nodeMatchesFilter(node, filter),
    ).length === 0;
    return extractNode;
  });
 
  return extractNode;
};