function reduceToSingleString(ctx, output, base, braces, addLn) { const breakLength = ctx.breakLength; var i = 0; if (ctx.compact === false) { const indentation = ' '.repeat(ctx.indentationLvl); var res = `${base ? `${base} ` : ''}${braces[0]}\n${indentation} `; for (; i < output.length - 1; i++) { res += `${output[i]},\n${indentation} `; } res += `${output[i]}\n${indentation}${braces[1]}`; return res; } if (output.length * 2 <= breakLength) { var length = 0; for (; i < output.length && length <= breakLength; i++) { if (ctx.colors) { length += output[i].replace(colorRegExp, '').length + 1; } else { length += output[i].length + 1; } } if (length <= breakLength) return `${braces[0]}${base ? ` ${base}` : ''} ${join(output, ', ')} ` + braces[1]; } // If the opening "brace" is too large, like in the case of "Set {", // we need to force the first item to be on the next line or the // items will not line up correctly. const indentation = ' '.repeat(ctx.indentationLvl); const extraLn = addLn === true ? `\n${indentation}` : ''; const ln = base === '' && braces[0].length === 1 ? ' ' : `${base ? ` ${base}` : base}\n${indentation} `; const str = join(output, `,\n${indentation} `); return `${extraLn}${braces[0]}${ln}${str} ${braces[1]}`; }
function reduceToSingleString(ctx, output, base, braces, combine = false) { if (ctx.compact !== true) { if (combine) { // Line up all entries on a single line in case the entries do not exceed // `breakLength`. Add 10 as constant to start next to all other factors // that may reduce `breakLength`. const start = output.length + ctx.indentationLvl + braces[0].length + base.length + 10; if (isBelowBreakLength(ctx, output, start)) { return `${base ? `${base} ` : ''}${braces[0]} ${join(output, ', ')} ` + braces[1]; } } // Line up each entry on an individual line. const indentation = `\n${' '.repeat(ctx.indentationLvl)}`; return `${base ? `${base} ` : ''}${braces[0]}${indentation} ` + `${join(output, `,${indentation} `)}${indentation}${braces[1]}`; } // Line up all entries on a single line in case the entries do not exceed // `breakLength`. if (isBelowBreakLength(ctx, output, 0)) { return `${braces[0]}${base ? ` ${base}` : ''} ${join(output, ', ')} ` + braces[1]; } const indentation = ' '.repeat(ctx.indentationLvl); // If the opening "brace" is too large, like in the case of "Set {", // we need to force the first item to be on the next line or the // items will not line up correctly. const ln = base === '' && braces[0].length === 1 ? ' ' : `${base ? ` ${base}` : ''}\n${indentation} `; // Line up each entry on an individual line. return `${braces[0]}${ln}${join(output, `,\n${indentation} `)} ${braces[1]}`; }