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

Function treeify

source code/utils/treeify.ts:41–172  ·  view source on GitHub ↗
(obj: TreeNode, options: TreeifyOptions = {})

Source from the content-addressed store, hash-verified

39 * Based on https://github.com/notatestuser/treeify
40 */
41export function treeify(obj: TreeNode, options: TreeifyOptions = {}): string {
42 const {
43 showValues = true,
44 hideFunctions = false,
45 themeName = 'dark',
46 treeCharColors = {},
47 } = options
48
49 const lines: string[] = []
50 const visited = new WeakSet<object>()
51
52 function colorize(text: string, colorKey?: keyof Theme): string {
53 if (!colorKey) return text
54 return color(colorKey, themeName)(text)
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)

Callers 1

ValidationErrorsListFunction · 0.85

Calls 3

growBranchFunction · 0.85
keysMethod · 0.80
colorizeFunction · 0.70

Tested by

no test coverage detected