Functionutilsv0.10.0
renderTable
Renders a grid of strings as a framed monospace table for Discord output.
Column widths use display width, so emoji, astral, and CJK cells line up. The first row is a header by default with a separator beneath it. Ragged rows are padded to the widest row.
Pass budget to get one string per page instead of a single string, splitting the body across a
character limit and re-emitting the header on each page.
renderTable(
data: readonly (readonly string[])[],
options: PagedTableOptions
): string[]renderTable([
['Name', 'Age'],
['Alice', '30'],
['Bob', '25']
]);
// ╭───────┬─────╮
// │ Name │ Age │
// ├───────┼─────┤
// │ Alice │ 30 │
// ├───────┼─────┤
// │ Bob │ 25 │
// ╰───────┴─────╯budget returns one page per chunk, each within the limit, with the header repeated.
const pages = renderTable(
[['ID', 'Value'], ['0', 'xxxxx'], ['1', 'xxxxx'], ['2', 'xxxxx'], ['3', 'xxxxx']],
{ budget: 120 }
);
// pages.length is 2, and pages[0] renders as
// ╭────┬───────╮
// │ ID │ Value │
// ├────┼───────┤
// │ 0 │ xxxxx │
// ├────┼───────┤
// │ 1 │ xxxxx │
// ╰────┴───────╯data
data: readonly (readonly string[])[]Rows of cells. The widest row sets the column count.
options
options: PagedTableOptionsRendering options, see TableOptions and PagedTableOptions.