Skip to content

Table

import { table } from "@arshad-shah/clif";
console.log(
table(
[
["Alice", "30", "Engineer"],
["Bob", "25", "Designer"],
],
{ headers: ["Name", "Age", "Role"] },
),
);
table(
[
["a", "b"],
["c", "d"],
],
{ border: false },
);
table([["A very long cell value that should be truncated", "short"]], {
maxColumnWidth: 20,
});

By default a cell wider than maxColumnWidth is truncated with an ellipsis. Set wrap: true to wrap it onto multiple lines instead — the row grows as tall as its tallest cell, and neighbouring cells stay aligned.

table([["The quick brown fox jumps", "ok"]], {
maxColumnWidth: 10,
wrap: true,
});
import { table, cyan } from "@arshad-shah/clif";
table([["data"]], { headers: ["Column"], headerColor: cyan });

Pass a single value to align every column the same way, or an array to align each column independently. Columns past the end of the array fall back to "left", and headers align with their column.

// Right-align a numeric column
table(
[
["clif", "11"],
["commander", "26000"],
],
{ headers: ["Package", "Stars"], align: ["left", "right"] },
);
// Center every column
table([["a", "b", "c"]], { align: "center" });
OptionTypeDefaultDescription
headersstring[]Column headers
borderbooleantrueShow borders
headerColorFormatterboldHeader text style
compactbooleanfalseSuppress the separator row between header and body
maxColumnWidthnumberTruncate columns
alignAlign | Align[]"left"Per-column alignment ("left" | "center" | "right"); single or array
wrapbooleanfalseWrap cells past maxColumnWidth onto multiple lines instead of truncating