Table
Basic table
Section titled “Basic table”import { table } from "@arshad-shah/clif";
console.log( table( [ ["Alice", "30", "Engineer"], ["Bob", "25", "Designer"], ], { headers: ["Name", "Age", "Role"] }, ),);Without borders
Section titled “Without borders”table( [ ["a", "b"], ["c", "d"], ], { border: false },);Column width limit
Section titled “Column width limit”table([["A very long cell value that should be truncated", "short"]], { maxColumnWidth: 20,});Wrapping instead of truncating
Section titled “Wrapping instead of truncating”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,});Custom header color
Section titled “Custom header color”import { table, cyan } from "@arshad-shah/clif";table([["data"]], { headers: ["Column"], headerColor: cyan });Column alignment
Section titled “Column alignment”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 columntable( [ ["clif", "11"], ["commander", "26000"], ], { headers: ["Package", "Stars"], align: ["left", "right"] },);
// Center every columntable([["a", "b", "c"]], { align: "center" });Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
headers | string[] | — | Column headers |
border | boolean | true | Show borders |
headerColor | Formatter | bold | Header text style |
compact | boolean | false | Suppress the separator row between header and body |
maxColumnWidth | number | — | Truncate columns |
align | Align | Align[] | "left" | Per-column alignment ("left" | "center" | "right"); single or array |
wrap | boolean | false | Wrap cells past maxColumnWidth onto multiple lines instead of truncating |