mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
improve indentation when displaying objects with console.log (#5909)
This commit is contained in:
parent
088fc1556c
commit
6d9b06619d
1 changed files with 5 additions and 9 deletions
|
@ -124,23 +124,19 @@ function createIterableString<T>(
|
||||||
|
|
||||||
const iPrefix = `${config.displayName ? config.displayName + " " : ""}`;
|
const iPrefix = `${config.displayName ? config.displayName + " " : ""}`;
|
||||||
|
|
||||||
|
const initIndentation = `\n${DEFAULT_INDENT.repeat(level + 1)}`;
|
||||||
|
const entryIndentation = `,\n${DEFAULT_INDENT.repeat(level + 1)}`;
|
||||||
|
const closingIndentation = `\n${DEFAULT_INDENT.repeat(level)}`;
|
||||||
|
|
||||||
let iContent: string;
|
let iContent: string;
|
||||||
if (config.group && entries.length > MIN_GROUP_LENGTH) {
|
if (config.group && entries.length > MIN_GROUP_LENGTH) {
|
||||||
const groups = groupEntries(entries, level, value);
|
const groups = groupEntries(entries, level, value);
|
||||||
const initIndentation = `\n${DEFAULT_INDENT.repeat(level + 1)}`;
|
|
||||||
const entryIndentation = `,\n${DEFAULT_INDENT.repeat(level + 1)}`;
|
|
||||||
const closingIndentation = `\n${DEFAULT_INDENT.repeat(level)}`;
|
|
||||||
|
|
||||||
iContent = `${initIndentation}${groups.join(
|
iContent = `${initIndentation}${groups.join(
|
||||||
entryIndentation
|
entryIndentation
|
||||||
)}${closingIndentation}`;
|
)}${closingIndentation}`;
|
||||||
} else {
|
} else {
|
||||||
iContent = entries.length === 0 ? "" : ` ${entries.join(", ")} `;
|
iContent = entries.length === 0 ? "" : ` ${entries.join(", ")} `;
|
||||||
if (stripColor(iContent).length > LINE_BREAKING_LENGTH) {
|
if (stripColor(iContent).length > LINE_BREAKING_LENGTH) {
|
||||||
const initIndentation = `\n${DEFAULT_INDENT.repeat(level + 1)}`;
|
|
||||||
const entryIndentation = `,\n${DEFAULT_INDENT.repeat(level + 1)}`;
|
|
||||||
const closingIndentation = `\n`;
|
|
||||||
|
|
||||||
iContent = `${initIndentation}${entries.join(
|
iContent = `${initIndentation}${entries.join(
|
||||||
entryIndentation
|
entryIndentation
|
||||||
)}${closingIndentation}`;
|
)}${closingIndentation}`;
|
||||||
|
@ -343,7 +339,7 @@ function createArrayString(
|
||||||
const ending = emptyItems > 1 ? "s" : "";
|
const ending = emptyItems > 1 ? "s" : "";
|
||||||
return dim(`<${emptyItems} empty item${ending}>`);
|
return dim(`<${emptyItems} empty item${ending}>`);
|
||||||
} else {
|
} else {
|
||||||
return stringifyWithQuotes(val, ctx, level + 1, maxLevel);
|
return stringifyWithQuotes(val, ctx, level, maxLevel);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
group: true,
|
group: true,
|
||||||
|
|
Loading…
Reference in a new issue