Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/cliffy/table/mod.ts>Table

Command line framework for deno 🦕 Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...
Extremely Popular
Go to Latest
class Table
extends Array<TRow>
import { Table } from "https://deno.land/x/cliffy@v1.0.0-rc.1/table/mod.ts";

Table representation.

import { Row, Table } from "./mod.ts";

new Table()
  .header(new Row("Name", "Date", "City", "Country").border())
  .body([
    ["Baxter Herman", "Oct 1, 2020", "Harderwijk", "Slovenia"],
    ["Jescie Wolfe", "Dec 4, 2020", "Alto Hospicio", "Japan"],
    ["Allegra Cleveland", "Apr 16, 2020", "Avernas-le-Bauduin", "Samoa"],
    ["Aretha Gamble", "Feb 22, 2021", "Honolulu", "Georgia"],
  ])
  .render();

Type Parameters

optional
TRow extends RowType = RowType

Properties

private
optional
headerRow: Row
protected
options: TableSettings

Methods

align(direction: Direction, override?): this

Align table content.

body(rows: Array<TRow>): this

Set table body.

border(enable?, override?): this

Enable/disable cell border.

chars(chars: BorderOptions): this

Set border characters.

Clone table recursively with header and options.

column(index: number, column: Column | ColumnOptions): this

Set column options by index.

columns(columns: Array<Column | ColumnOptions>): this

Set column options.

fromJson(rows: Array<DataRow>): this

Read data from an array of json objects. An object represents a row and each property a column.

Get table alignment.

getBody(): Array<TRow>

Get table body.

getBorder(): boolean

Check if table has border.

getColumn(index: number): Column

Get column by column index.

getColumns(): Array<Column>

Get columns.

getHeader(): Row | undefined

Get table header.

getIndent(): number

Get table indentation.

getMaxColWidth(): number | Array<number>

Get max column width.

getMinColWidth(): number | Array<number>

Get min column width.

getPadding(): number | Array<number>

Get cell padding.

hasBodyBorder(): boolean

Check if table bordy has border.

hasBorder(): boolean

Check if table header or body has border.

hasHeaderBorder(): boolean

Check if header row has border.

header(header: RowType): this

Set table header.

indent(width: number, override?): this

Set table indentation.

maxColWidth(width: number | Array<number>, override?): this

Set max column width.

minColWidth(width: number | Array<number>, override?): this

Set min column width.

padding(padding: number | Array<number>, override?): this

Set cell padding.

render(): this

Write table to stdout.

toString(): string

Generate table string.

Static Properties

protected
_chars: Border

Static Methods

chars(chars: BorderOptions): Table

Set global default border characters.

from<TRow extends RowType>(rows: TableType<TRow>): Table<TRow>

Create a new table. If rows is a table, all rows and options of the table will be copied to the new table.

fromJson(rows: Array<DataRow>): Table

Create a new table from an array of json objects. An object represents a row and each property a column.

render<TRow extends RowType>(rows: TableType<TRow>): void

Write table or rows to stdout.