MCPcopy Create free account
hub / github.com/esengine/esengine / stringify

Method stringify

packages/core/src/Utils/Debug/DebugManager.ts:168–197  ·  view source on GitHub ↗
(value: any, depth: number)

Source from the content-addressed store, hash-verified

166 const seen = new WeakSet();
167
168 const stringify = (value: any, depth: number): any => {
169 if (value === null) return null;
170 if (value === undefined) return undefined;
171 if (typeof value !== 'object') return value;
172
173 if (depth >= maxDepth) {
174 return '[Max Depth Reached]';
175 }
176
177 if (seen.has(value)) {
178 return '[Circular]';
179 }
180
181 seen.add(value);
182
183 if (Array.isArray(value)) {
184 const result = value.map((item) => stringify(item, depth + 1));
185 seen.delete(value);
186 return result;
187 }
188
189 const result: any = {};
190 for (const key in value) {
191 if (Object.prototype.hasOwnProperty.call(value, key)) {
192 result[key] = stringify(value[key], depth + 1);
193 }
194 }
195 seen.delete(value);
196 return result;
197 };
198
199 return JSON.stringify(stringify(obj, 0));
200 }

Callers 15

serializeAssetMetaFunction · 0.80
convertToJsonMethod · 0.80
ParticleEditorPanelFunction · 0.80
TilemapEditorPanelFunction · 0.80
generatePackageJsonFunction · 0.80
toJSONMethod · 0.80
serializeToJSONMethod · 0.80
toEditorJSONMethod · 0.80

Calls 5

isArrayMethod · 0.80
hasMethod · 0.65
deleteMethod · 0.65
addMethod · 0.45
mapMethod · 0.45

Tested by 1

serializeFunction · 0.64