MCPcopy Create free account
hub / github.com/ecomfe/tempad-dev / findOne

Function findOne

packages/plugins/src/index.ts:528–544  ·  view source on GitHub ↗
(
  node: ContainerNode,
  query: NodeQuery
)

Source from the content-addressed store, hash-verified

526 * ```
527 */
528export function findOne<T extends DesignNode = DesignNode>(
529 node: ContainerNode,
530 query: NodeQuery
531): T | null {
532 for (const child of node.children) {
533 if (matchNode(child, query)) {
534 return child as T
535 }
536 if ('children' in child) {
537 const result = findOne(child, query)
538 if (result) {
539 return result as T
540 }
541 }
542 }
543 return null
544}
545
546/**
547 * Depth-first search returning every node that matches the query.

Callers 2

index.test.tsFile · 0.90
queryAllFunction · 0.85

Calls 1

matchNodeFunction · 0.85

Tested by

no test coverage detected