MCPcopy Index your code
hub / github.com/simstudioai/sim / visit

Function visit

apps/sim/lib/logs/execution/logger.ts:94–141  ·  view source on GitHub ↗
(item: unknown)

Source from the content-addressed store, hash-verified

92 }
93
94 const visit = (item: unknown): void => {
95 if (item === undefined || typeof item === 'function' || typeof item === 'symbol') {
96 add(4)
97 return
98 }
99 if (item === null) {
100 add(4)
101 return
102 }
103 if (typeof item === 'string') {
104 add(Buffer.byteLength(JSON.stringify(item), 'utf8'))
105 return
106 }
107 if (typeof item === 'bigint') {
108 add(Buffer.byteLength(JSON.stringify(item.toString()), 'utf8'))
109 return
110 }
111 if (typeof item === 'number' || typeof item === 'boolean') {
112 add(Buffer.byteLength(JSON.stringify(item) ?? 'null', 'utf8'))
113 return
114 }
115 if (typeof item !== 'object') {
116 add(4)
117 return
118 }
119 if (seen.has(item)) {
120 return
121 }
122 seen.add(item)
123
124 if (Array.isArray(item)) {
125 add(2)
126 item.forEach((entry, index) => {
127 if (index > 0) add(1)
128 visit(entry)
129 })
130 return
131 }
132
133 const entries = Object.entries(item)
134 add(2)
135 entries.forEach(([key, entry], index) => {
136 if (entry === undefined || typeof entry === 'function' || typeof entry === 'symbol') return
137 if (index > 0) add(1)
138 add(Buffer.byteLength(JSON.stringify(key), 'utf8') + 1)
139 visit(entry)
140 })
141 }
142
143 try {
144 visit(value)

Callers 1

getJsonByteSizeFunction · 0.70

Calls 3

addFunction · 0.70
toStringMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected