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

Function formatWithOptionsInternal

lib/internal/util/inspect.js:2799–2923  ·  view source on GitHub ↗
(inspectOptions, args)

Source from the content-addressed store, hash-verified

2797}
2798
2799function formatWithOptionsInternal(inspectOptions, args) {
2800 const first = args[0];
2801 let a = 0;
2802 let str = '';
2803 let join = '';
2804
2805 if (typeof first === 'string') {
2806 if (args.length === 1) {
2807 return first;
2808 }
2809 let tempStr;
2810 let lastPos = 0;
2811
2812 for (let i = 0; i < first.length - 1; i++) {
2813 if (StringPrototypeCharCodeAt(first, i) === 37) { // '%'
2814 const nextChar = StringPrototypeCharCodeAt(first, ++i);
2815 if (a + 1 !== args.length) {
2816 switch (nextChar) {
2817 case 115: { // 's'
2818 const tempArg = args[++a];
2819 if (typeof tempArg === 'number') {
2820 tempStr = formatNumberNoColor(tempArg, inspectOptions);
2821 } else if (typeof tempArg === 'bigint') {
2822 tempStr = formatBigIntNoColor(tempArg, inspectOptions);
2823 } else if (typeof tempArg !== 'object' ||
2824 tempArg === null ||
2825 !hasBuiltInToString(tempArg)) {
2826 tempStr = String(tempArg);
2827 } else {
2828 tempStr = inspect(tempArg, {
2829 ...inspectOptions,
2830 compact: 3,
2831 colors: false,
2832 depth: 0,
2833 });
2834 }
2835 break;
2836 }
2837 case 106: // 'j'
2838 tempStr = tryStringify(args[++a]);
2839 break;
2840 case 100: { // 'd'
2841 const tempNum = args[++a];
2842 if (typeof tempNum === 'bigint') {
2843 tempStr = formatBigIntNoColor(tempNum, inspectOptions);
2844 } else if (typeof tempNum === 'symbol') {
2845 tempStr = 'NaN';
2846 } else {
2847 tempStr = formatNumberNoColor(Number(tempNum), inspectOptions);
2848 }
2849 break;
2850 }
2851 case 79: // 'O'
2852 tempStr = inspect(args[++a], inspectOptions);
2853 break;
2854 case 111: // 'o'
2855 tempStr = inspect(args[++a], {
2856 ...inspectOptions,

Callers 2

formatFunction · 0.85
formatWithOptionsFunction · 0.85

Calls 7

formatNumberNoColorFunction · 0.85
formatBigIntNoColorFunction · 0.85
hasBuiltInToStringFunction · 0.85
StringClass · 0.85
tryStringifyFunction · 0.85
NumberParseFloatFunction · 0.85
inspectFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…