MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / growBranch

Function growBranch

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

Source from the content-addressed store, hash-verified

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

Callers 1

treeifyFunction · 0.85

Calls 4

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

Tested by

no test coverage detected