Files
freecodecamp--freecodecamp/tools/challenge-parser/parser/plugins/utils/find-all.js
T
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

28 lines
789 B
JavaScript

const visit = require('unist-util-visit');
const _ = require('lodash');
/**
* Finds all nodes in a tree that match a given condition. This is a trivial
* extension of `unist-util-find` that returns all matching nodes.
*
* @param {Object} tree - The unist tree to search through.
* @param {Function|Object} condition - The condition to match nodes
* against. This can be a function that accepts a single node argument or an object to match.
* @returns {Array} An array of nodes that match the condition.
*/
function findAll(tree, condition) {
const predicate = _.iteratee(condition);
const results = [];
visit(tree, node => {
if (predicate(node)) {
results.push(node);
}
return visit.CONTINUE;
});
return results;
}
module.exports.findAll = findAll;