@mcabreradev/filter
Version:
A powerful, SQL-like array filtering library for TypeScript and JavaScript with advanced pattern matching, MongoDB-style operators, deep object comparison, and zero dependencies
34 lines • 1.22 kB
JavaScript
import { createPredicateFn } from '../predicate';
export const evaluateWithDebug = (array, tree, expression, config) => {
const predicate = createPredicateFn(expression, config);
const decoratedPredicate = createDecoratedPredicate(predicate, tree);
const startTime = performance.now();
const items = array.filter(decoratedPredicate);
tree.evaluationTime = performance.now() - startTime;
return { items, tree };
};
const createDecoratedPredicate = (predicate, node) => {
return (item) => {
const result = predicate(item);
node.total = (node.total || 0) + 1;
if (result) {
node.matched = (node.matched || 0) + 1;
}
if (node.children) {
updateChildrenStats(node.children, item, result);
}
return result;
};
};
const updateChildrenStats = (children, item, parentResult) => {
for (const child of children) {
child.total = (child.total || 0) + 1;
if (parentResult) {
child.matched = (child.matched || 0) + 1;
}
if (child.children) {
updateChildrenStats(child.children, item, parentResult);
}
}
};
//# sourceMappingURL=debug-evaluator.js.map