spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / tests / fixtures / tree / text-of.ts
28 lines · 726 BRaw
1/**
2 * A rendered tree's text as it reads: its strings and its labels, in order.
3 *
4 * @param tree what `$.ui.render` resolved to, or a part of it
5 * @returns the text
6 */
7export function textOf(tree: unknown): string {
8 if (typeof tree === 'string' || typeof tree === 'number') {
9 return String(tree)
10 }
11
12 if (Array.isArray(tree)) {
13 return tree.map(textOf).join('')
14 }
15
16 if (typeof tree !== 'object' || !tree) {
17 return ''
18 }
19
20 const props: unknown = Reflect.get(tree, 'props')
21
22 const label: unknown =
23 typeof props === 'object' && props ? Reflect.get(props, 'label') : undefined
24
25 const lead = typeof label === 'string' ? label : ''
26
27 return `${lead}${textOf(Reflect.get(tree, 'children') ?? [])}`
28}