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

Function formatPrimitive

lib/internal/util/inspect.js:2233–2267  ·  view source on GitHub ↗
(fn, value, ctx)

Source from the content-addressed store, hash-verified

2231}
2232
2233function formatPrimitive(fn, value, ctx) {
2234 if (typeof value === 'string') {
2235 let trailer = '';
2236 if (value.length > ctx.maxStringLength) {
2237 const remaining = value.length - ctx.maxStringLength;
2238 value = StringPrototypeSlice(value, 0, ctx.maxStringLength);
2239 trailer = `... ${remaining} more character${remaining > 1 ? 's' : ''}`;
2240 }
2241 if (ctx.compact !== true &&
2242 // We do not support handling unicode characters width with
2243 // the readline getStringWidth function as there are
2244 // performance implications.
2245 value.length > kMinLineLength &&
2246 value.length > ctx.breakLength - ctx.indentationLvl - 4) {
2247 return ArrayPrototypeJoin(
2248 ArrayPrototypeMap(
2249 RegExpPrototypeSymbolSplit(/(?<=\n)/, value),
2250 (line) => fn(strEscape(line), 'string'),
2251 ),
2252 ` +\n${StringPrototypeRepeat(' ', ctx.indentationLvl + 2)}`,
2253 ) + trailer;
2254 }
2255 return fn(strEscape(value), 'string') + trailer;
2256 }
2257 if (typeof value === 'number')
2258 return formatNumber(fn, value, ctx.numericSeparator);
2259 if (typeof value === 'bigint')
2260 return formatBigInt(fn, value, ctx.numericSeparator);
2261 if (typeof value === 'boolean')
2262 return fn(`${value}`, 'boolean');
2263 if (typeof value === 'undefined')
2264 return fn('undefined', 'undefined');
2265 // es6 symbol primitive
2266 return fn(SymbolPrototypeToString(value), 'symbol');
2267}
2268
2269function formatNamespaceObject(keys, ctx, value, recurseTimes) {
2270 const output = new Array(keys.length);

Callers 3

formatValueFunction · 0.85
getBoxedBaseFunction · 0.85
formatPropertyFunction · 0.85

Calls 4

strEscapeFunction · 0.85
formatBigIntFunction · 0.85
formatNumberFunction · 0.70
fnFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…