MCPcopy
hub / github.com/posthtml/posthtml / match

Function match

lib/api.js:81–95  ·  view source on GitHub ↗

* Matches an expression to search for nodes in the tree * * @memberof tree * * @param {String|RegExp|Object|Array} expression - Matcher(s) to search * @param {Function} cb Callback * * @return {Function} Callback(node) * * @example * ```js * export const match = (tree) => { * // Sing

(expression, cb)

Source from the content-addressed store, hash-verified

79 * ```
80 */
81function match (expression, cb) {
82 return Array.isArray(expression)
83 ? traverse(this, node => {
84 for (let i = 0; i < expression.length; i++) {
85 if (compare(expression[i], node)) return cb(node)
86 }
87
88 return node
89 })
90 : traverse(this, node => {
91 if (compare(expression, node)) return cb(node)
92
93 return node
94 })
95}
96
97module.exports = Api
98module.exports.match = match

Callers

nothing calls this directly

Calls 2

traverseFunction · 0.85
compareFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…