MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / printComplexValue

Method printComplexValue

packages/alphatab/test/PrettyFormat.ts:182–226  ·  view source on GitHub ↗

* Handles more complex objects ( such as objects with circular references. * maps and sets etc )

(
        val: unknown,
        config: PrettyFormatConfig,
        indentation: string,
        depth: number,
        refs: unknown[]
    )

Source from the content-addressed store, hash-verified

180 * maps and sets etc )
181 */
182 static printComplexValue(
183 val: unknown,
184 config: PrettyFormatConfig,
185 indentation: string,
186 depth: number,
187 refs: unknown[]
188 ): string {
189 if (refs.includes(val)) {
190 return '[Circular]';
191 }
192 refs = [...refs];
193 refs.push(val);
194
195 const hitMaxDepth = ++depth > config.maxDepth;
196 const min = config.min;
197
198 const arrayTypeName = PrettyFormat.tryGetIterableType(val);
199 if (arrayTypeName) {
200 return hitMaxDepth
201 ? `[${arrayTypeName}]`
202 : `${
203 min || arrayTypeName.startsWith('_') ? '' : `${arrayTypeName} `
204 }[${PrettyFormat.printIterableValues(TestPlatform.typedArrayAsUnknownIterable(val), config, indentation, depth, refs, PrettyFormat.printer)}]`;
205 }
206
207 if (val instanceof Map) {
208 return hitMaxDepth
209 ? '[Map]'
210 : `Map {${PrettyFormat.printIteratorEntries(TestPlatform.mapAsUnknownIterable(val), config, indentation, depth, refs, PrettyFormat.printer, ' => ')}}`;
211 }
212 if (val instanceof Set) {
213 return hitMaxDepth
214 ? '[Set]'
215 : `Set {${PrettyFormat.printIterableValues(TestPlatform.setAsUnknownIterable(val), config, indentation, depth, refs, PrettyFormat.printer)}}`;
216 }
217
218 // Avoid failure to serialize global window object in jsdom test environment.
219 // For example, not even relevant if window is prop of React element.
220 const constructorName = TestPlatform.getConstructorName(val);
221 return hitMaxDepth
222 ? `[${constructorName}]`
223 : `${
224 min ? '' : !config.printBasicPrototype && constructorName === 'Object' ? '' : `${constructorName} `
225 }{${PrettyFormat._printObjectProperties(val as object, config, indentation, depth, refs)}}`;
226 }
227
228 private static _printObjectProperties(
229 val: object,

Callers 1

printerMethod · 0.80

Calls 10

includesMethod · 0.80
tryGetIterableTypeMethod · 0.80
printIterableValuesMethod · 0.80
printIteratorEntriesMethod · 0.80
pushMethod · 0.45
mapAsUnknownIterableMethod · 0.45
setAsUnknownIterableMethod · 0.45
getConstructorNameMethod · 0.45

Tested by

no test coverage detected