Skip to content

util: add util.table()#63984

Open
watilde wants to merge 1 commit into
nodejs:mainfrom
watilde:util-table
Open

util: add util.table()#63984
watilde wants to merge 1 commit into
nodejs:mainfrom
watilde:util-table

Conversation

@watilde

@watilde watilde commented Jun 18, 2026

Copy link
Copy Markdown
Member

Add util.table(tabularData[, properties][, options]), which renders tabular data with the same layout as console.table but returns it as a string instead of writing to a stream. This is useful for logging, writing to a file, or building output without a console.

The row-building logic is extracted from console.table into a shared internal module so both APIs produce identical output.

Add `util.table(tabularData[, properties][, options])`, which renders
tabular data with the same layout as `console.table` but returns it as
a string instead of writing to a stream. This is useful for logging,
writing to a file, or building output without a console.

The row-building logic is extracted from `console.table` into a shared
internal module so both APIs produce identical output.

Signed-off-by: Daijiro Wachi <daijiro.wachi@gmail.com>
@nodejs-github-bot nodejs-github-bot added console Issues and PRs related to the console subsystem. needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Jun 18, 2026
@TheOneTheOnlyJJ

Copy link
Copy Markdown
Contributor

Would this be a lot faster if the shared helper were implemented in C++?

if (setlike) {
const values = [];
let length = 0;
for (const v of tabularData) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a normal for loop - both for perf and to avoid needing a primordial for iteration

valuesKeyArray[i] = _inspect(item);
} else {
const keys = properties || ObjectKeys(item);
for (const key of keys) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

console Issues and PRs related to the console subsystem. needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants