All files / src/lib node-matches-filter.ts

100% Statements 8/8
100% Branches 8/8
100% Functions 1/1
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16          4x 3395x 900x 2495x 786x 1709x 25x   1684x    
import { IFilter } from '../interfaces/IFilter';
 
/**
 * Check if a node matches the given filter.
 */
export = function nodeMatchesFilter(node: any, filter: IFilter) {
  if (!node[filter.property]) {
    return false;
  } else if (node[filter.property] === filter.value) {
    return true;
  } else if (filter.value instanceof RegExp && filter.value.test(node[filter.property])) {
    return true;
  }
  return false;
};