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

Function formatProperty

lib/internal/util/inspect.js:2548–2612  ·  view source on GitHub ↗
(ctx, value, recurseTimes, key, type, desc,
                        original = value)

Source from the content-addressed store, hash-verified

2546}
2547
2548function formatProperty(ctx, value, recurseTimes, key, type, desc,
2549 original = value) {
2550 let name, str;
2551 let extra = ' ';
2552 desc ??= ObjectGetOwnPropertyDescriptor(value, key);
2553 if (desc.value !== undefined) {
2554 const diff = (ctx.compact !== true || type !== kObjectType) ? 2 : 3;
2555 ctx.indentationLvl += diff;
2556 str = formatValue(ctx, desc.value, recurseTimes);
2557 if (diff === 3 && ctx.breakLength < getStringWidth(str, ctx.colors)) {
2558 extra = `\n${StringPrototypeRepeat(' ', ctx.indentationLvl)}`;
2559 }
2560 ctx.indentationLvl -= diff;
2561 } else if (desc.get !== undefined) {
2562 const label = desc.set !== undefined ? 'Getter/Setter' : 'Getter';
2563 const s = ctx.stylize;
2564 const sp = 'special';
2565 if (ctx.getters && (ctx.getters === true ||
2566 (ctx.getters === 'get' && desc.set === undefined) ||
2567 (ctx.getters === 'set' && desc.set !== undefined))) {
2568 ctx.indentationLvl += 2;
2569 try {
2570 const tmp = FunctionPrototypeCall(desc.get, original);
2571 if (tmp === null) {
2572 str = `${s(`[${label}:`, sp)} ${s('null', 'null')}${s(']', sp)}`;
2573 } else if (typeof tmp === 'object') {
2574 str = `${s(`[${label}]`, sp)} ${formatValue(ctx, tmp, recurseTimes)}`;
2575 } else {
2576 const primitive = formatPrimitive(s, tmp, ctx);
2577 str = `${s(`[${label}:`, sp)} ${primitive}${s(']', sp)}`;
2578 }
2579 } catch (err) {
2580 const message = `<Inspection threw (${formatValue(ctx, err, recurseTimes)})>`;
2581 str = `${s(`[${label}:`, sp)} ${message}${s(']', sp)}`;
2582 }
2583 ctx.indentationLvl -= 2;
2584 } else {
2585 str = ctx.stylize(`[${label}]`, sp);
2586 }
2587 } else if (desc.set !== undefined) {
2588 str = ctx.stylize('[Setter]', 'special');
2589 } else {
2590 str = ctx.stylize('undefined', 'undefined');
2591 }
2592 if (type === kArrayType) {
2593 return str;
2594 }
2595 if (typeof key === 'symbol') {
2596 const tmp = RegExpPrototypeSymbolReplace(
2597 strEscapeSequencesReplacer,
2598 SymbolPrototypeToString(key),
2599 escapeFn,
2600 );
2601 name = ctx.stylize(tmp, 'symbol');
2602 } else if (RegExpPrototypeExec(keyStrRegExp, key) !== null) {
2603 name = key === '__proto__' ? "['__proto__']" : ctx.stylize(key, 'name');
2604 } else {
2605 name = ctx.stylize(strEscape(key), 'string');

Callers 5

addPrototypePropertiesFunction · 0.85
formatRawFunction · 0.85
formatNamespaceObjectFunction · 0.85
formatSpecialArrayFunction · 0.85
formatArrayFunction · 0.85

Calls 4

formatValueFunction · 0.85
formatPrimitiveFunction · 0.85
strEscapeFunction · 0.85
sFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…