MCPcopy Create free account
hub / github.com/pacexy/flow / flatTree

Function flatTree

apps/reader/src/models/tree.ts:8–14  ·  view source on GitHub ↗
(node: T, depth = 1)

Source from the content-addressed store, hash-verified

6}
7
8export function flatTree<T extends INode>(node: T, depth = 1): T[] {
9 if (!node.subitems || !node.subitems.length || !node.expanded) {
10 return [{ ...node, depth }]
11 }
12 const children = node.subitems.flatMap((i) => flatTree(i, depth + 1)) as T[]
13 return [{ ...node, depth }, ...children]
14}
15
16export function find<T extends INode>(
17 nodes: T[] = [],

Callers 2

TocPaneFunction · 0.90
ResultListFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected