MCPcopy Create free account
hub / github.com/CashScript/cashscript / formatArray

Function formatArray

packages/utils/src/artifact.ts:115–130  ·  view source on GitHub ↗
(
  array: readonly any[],
  format: 'json' | 'ts',
  indentationLevel: number,
  isArrayElement: boolean,
)

Source from the content-addressed store, hash-verified

113}
114
115function formatArray(
116 array: readonly any[],
117 format: 'json' | 'ts',
118 indentationLevel: number,
119 isArrayElement: boolean,
120): string {
121 if (array.length === 0) return '[]';
122
123 const items = array.map((item) => stringify(item, format, indentationLevel + 1, true));
124
125 if (isArrayElement && canInline(array)) return `[${items.join(', ')}]`;
126
127 const lines = items.map((item) => `${indent(indentationLevel)}${item}`).join(',\n');
128 const trailingComma = format === 'ts' ? ',' : '';
129 return `[\n${lines}${trailingComma}\n${indent(indentationLevel - 1)}]`;
130}
131
132function formatObject(
133 obj: any,

Callers 1

stringifyFunction · 0.85

Calls 3

stringifyFunction · 0.85
canInlineFunction · 0.85
indentFunction · 0.85

Tested by

no test coverage detected