MCPcopy
hub / github.com/nestjs/nest / convertInspectToJSON

Function convertInspectToJSON

packages/common/test/services/logger.service.spec.ts:1022–1036  ·  view source on GitHub ↗
(inspectOutput: string)

Source from the content-addressed store, hash-verified

1020});
1021
1022function convertInspectToJSON(inspectOutput: string) {
1023 const jsonLikeString = inspectOutput
1024 .replace(/'([^']+)'/g, '"$1"') // single-quoted strings
1025 .replace(/([a-zA-Z0-9_]+):/g, '"$1":') // unquoted object keys
1026 .replace(/\bundefined\b/g, 'null')
1027 .replace(/\[Function(: [^\]]+)?\]/g, '"[Function]"')
1028 .replace(/\[Circular\]/g, '"[Circular]"');
1029
1030 try {
1031 return JSON.parse(jsonLikeString);
1032 } catch (error) {
1033 console.error('Error parsing the modified inspect output:', error);
1034 throw error;
1035 }
1036}

Callers 1

Calls 3

parseMethod · 0.80
errorMethod · 0.65
replaceMethod · 0.45

Tested by

no test coverage detected