MCPcopy Index your code
hub / github.com/nodejs/node / formatMapIterInner

Function formatMapIterInner

lib/internal/util/inspect.js:2457–2493  ·  view source on GitHub ↗
(ctx, recurseTimes, entries, state)

Source from the content-addressed store, hash-verified

2455}
2456
2457function formatMapIterInner(ctx, recurseTimes, entries, state) {
2458 const maxArrayLength = MathMax(ctx.maxArrayLength, 0);
2459 // Entries exist as [key1, val1, key2, val2, ...]
2460 const len = entries.length / 2;
2461 const remaining = len - maxArrayLength;
2462 const maxLength = MathMin(maxArrayLength, len);
2463 const output = new Array(maxLength);
2464 let i = 0;
2465 ctx.indentationLvl += 2;
2466 if (state === kWeak) {
2467 for (; i < maxLength; i++) {
2468 const pos = i * 2;
2469 output[i] =
2470 `${formatValue(ctx, entries[pos], recurseTimes)} => ${formatValue(ctx, entries[pos + 1], recurseTimes)}`;
2471 }
2472 // Sort all entries to have a halfway reliable output (if more entries than
2473 // retrieved ones exist, we can not reliably return the same output) if the
2474 // output is not sorted anyway.
2475 if (!ctx.sorted)
2476 ArrayPrototypeSort(output);
2477 } else {
2478 for (; i < maxLength; i++) {
2479 const pos = i * 2;
2480 const res = [
2481 formatValue(ctx, entries[pos], recurseTimes),
2482 formatValue(ctx, entries[pos + 1], recurseTimes),
2483 ];
2484 output[i] = reduceToSingleString(
2485 ctx, res, '', ['[', ']'], kArrayExtrasType, recurseTimes);
2486 }
2487 }
2488 ctx.indentationLvl -= 2;
2489 if (remaining > 0) {
2490 ArrayPrototypePush(output, remainingText(remaining));
2491 }
2492 return output;
2493}
2494
2495function formatWeakCollection(ctx) {
2496 return [ctx.stylize('<items unknown>', 'special')];

Callers 2

formatWeakMapFunction · 0.85
formatIteratorFunction · 0.85

Calls 3

formatValueFunction · 0.85
reduceToSingleStringFunction · 0.85
remainingTextFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…