MCPcopy Index your code
hub / github.com/subquery/subql / tsStringify

Function tsStringify

packages/cli/src/controller/generate-controller.ts:481–507  ·  view source on GitHub ↗
(
  obj: SubqlRuntimeHandler | SubqlRuntimeHandler[] | string,
  indent = 2,
  currentIndent = 0
)

Source from the content-addressed store, hash-verified

479}
480
481export function tsStringify(
482 obj: SubqlRuntimeHandler | SubqlRuntimeHandler[] | string,
483 indent = 2,
484 currentIndent = 0
485): string {
486 if (typeof obj !== 'object' || obj === null) {
487 if (typeof obj === 'string' && obj.includes('EthereumHandlerKind')) {
488 return obj; // Return the string as-is without quotes
489 }
490 return JSON.stringify(obj);
491 }
492
493 if (Array.isArray(obj)) {
494 const items = obj.map((item) => tsStringify(item, indent, currentIndent + indent));
495 return `[\n${items.map((item) => ' '.repeat(currentIndent + indent) + item).join(',\n')}\n${' '.repeat(
496 currentIndent
497 )}]`;
498 }
499
500 const entries = Object.entries(obj);
501 const result = entries.map(([key, value]) => {
502 const valueStr = tsStringify(value, indent, currentIndent + indent);
503 return `${' '.repeat(currentIndent + indent)}${key}: ${valueStr}`;
504 });
505
506 return `{\n${result.join(',\n')}\n${' '.repeat(currentIndent)}}`;
507}

Callers 2

constructDatasourcesTsFunction · 0.85

Calls 1

mapMethod · 0.80

Tested by

no test coverage detected