-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ 🔀 new
options.wrap
property that's more powerful with auto
, `si…
…ngle-line`, `multi-line` or `number` for line breaking + old `options.lineLength` is now removed in favor of `options.wrap` + `consoleTable()` now shows as much of the object inline as it can + removed `consoleGroup()` usage when object is at root level
- Loading branch information
Showing
10 changed files
with
141 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,66 @@ | ||
import consoleInline from "../../utils/consoleInline"; | ||
import inspectInline from "../../inspect/inspectors/inspectInline"; | ||
import inspectAny from "../../inspect/inspectors/inspectAny"; | ||
import { ConsoleText, consoleText } from "../../core/consoleText"; | ||
import createTableCell, { ConsoleTableCell } from "./createTableCell"; | ||
import spansLength from "../../utils/spansLength"; | ||
|
||
export default function consoleTableCell( | ||
value: unknown, | ||
theme: "light" | "dark", | ||
maxCellLength: number, | ||
): ConsoleTableCell { | ||
const spans = inspectAny( | ||
value, | ||
{ | ||
theme, | ||
lineLength: maxCellLength, | ||
print: false, | ||
line: false, | ||
indent: 0, | ||
depth: 2, | ||
}, | ||
{ | ||
depth: 1, | ||
indent: 0, | ||
}, | ||
).map((span) => { | ||
return typeof span === "string" | ||
? consoleText(span) | ||
: span.type === "object" | ||
? consoleInline(span, theme) | ||
: span; | ||
}); | ||
return spans.every( | ||
(span): span is ConsoleText => | ||
span.type === "text" && !span.text.includes("\n"), | ||
) | ||
? createTableCell(spans) | ||
: createTableCell(consoleInline(value, theme)); | ||
const spans = findOptimalExpansion(value, theme, maxCellLength); | ||
return spans === undefined | ||
? createTableCell(inspectInline(value, theme)) | ||
: createTableCell(spans); | ||
} | ||
|
||
function findOptimalExpansion( | ||
value: unknown, | ||
theme: "light" | "dark", | ||
maxCellLength: number, | ||
): ConsoleText[] | undefined { | ||
let optimal: ConsoleText[] | undefined; | ||
let depth = 1; | ||
while (true) { | ||
let hasObject = false; | ||
const spans = inspectAny( | ||
value, | ||
{ | ||
theme, | ||
wrap: "single-line", | ||
print: false, | ||
line: false, | ||
indent: 0, | ||
depth: depth + 1, | ||
}, | ||
{ | ||
depth: depth, | ||
indent: 0, | ||
wrap: Number.MAX_SAFE_INTEGER, | ||
}, | ||
).map((span) => { | ||
return typeof span === "string" | ||
? consoleText(span) | ||
: span.type === "object" | ||
? ((hasObject = true), inspectInline(span, theme)) | ||
: span; | ||
}); | ||
if ( | ||
spans.every((span): span is ConsoleText => span.type === "text") && | ||
spansLength(spans) <= maxCellLength | ||
) { | ||
depth += 1; | ||
optimal = spans; | ||
if (!hasObject) { | ||
break; | ||
} | ||
if (depth > 6) { | ||
break; | ||
} | ||
} else { | ||
break; | ||
} | ||
} | ||
return optimal; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
src/utils/consoleInline.ts → src/inspect/inspectors/inspectInline.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.