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