MCPcopy
hub / github.com/codeaashu/claude-code / growBranch

Function growBranch

src/utils/treeify.ts:55–144  ·  view source on GitHub ↗
(
    node: TreeNode | string,
    prefix: string,
    _isLast: boolean,
    depth: number = 0,
  )

Source from the content-addressed store, hash-verified

53 }
54
55 function growBranch(
56 node: TreeNode | string,
57 prefix: string,
58 _isLast: boolean,
59 depth: number = 0,
60 ): void {
61 if (typeof node === 'string') {
62 lines.push(prefix + colorize(node, treeCharColors.value))
63 return
64 }
65
66 if (typeof node !== 'object' || node === null) {
67 if (showValues) {
68 const valueStr = String(node)
69 lines.push(prefix + colorize(valueStr, treeCharColors.value))
70 }
71 return
72 }
73
74 // Check for circular references
75 if (visited.has(node)) {
76 lines.push(prefix + colorize('[Circular]', treeCharColors.value))
77 return
78 }
79 visited.add(node)
80
81 const keys = Object.keys(node).filter(key => {
82 const value = node[key]
83 if (hideFunctions && typeof value === 'function') return false
84 return true
85 })
86
87 keys.forEach((key, index) => {
88 const value = node[key]
89 const isLastKey = index === keys.length - 1
90 const nodePrefix = depth === 0 && index === 0 ? '' : prefix
91
92 // Determine which tree character to use
93 const treeChar = isLastKey
94 ? DEFAULT_TREE_CHARS.lastBranch
95 : DEFAULT_TREE_CHARS.branch
96 const coloredTreeChar = colorize(treeChar, treeCharColors.treeChar)
97 const coloredKey =
98 key.trim() === '' ? '' : colorize(key, treeCharColors.key)
99
100 let line =
101 nodePrefix + coloredTreeChar + (coloredKey ? ' ' + coloredKey : '')
102
103 // Check if we should add a colon (not for empty/whitespace keys)
104 const shouldAddColon = key.trim() !== ''
105
106 // Check for circular reference before recursing
107 if (value && typeof value === 'object' && visited.has(value)) {
108 const coloredValue = colorize('[Circular]', treeCharColors.value)
109 lines.push(
110 line + (shouldAddColon ? ': ' : line ? ' ' : '') + coloredValue,
111 )
112 } else if (value && typeof value === 'object' && !Array.isArray(value)) {

Callers 1

treeifyFunction · 0.85

Calls 6

keysMethod · 0.80
forEachMethod · 0.80
colorizeFunction · 0.70
pushMethod · 0.45
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected