Skip to content

Class: Table ​

An immutable table of named, equally long columns. Built by toTable (which every Express function calls on its data) or fromCSV.

Example ​

ts
const t = toTable([
  { a: 1, b: 'x' },
  { a: 2, b: 'y' },
]);
t.names; // ['a', 'b']
t.column('a'); // [1, 2]
t.type('b'); // 'categorical'

Constructors ​

Constructor ​

ts
new Table(columns): Table;

Parameters ​

ParameterTypeDescription
columns| Record<string, readonly unknown[]> | ReadonlyMap<string, readonly unknown[]>Columns by name; they must all have the same length.

Returns ​

Table

Throws ​

When columns differ in length.

Properties ​

PropertyModifierTypeDescription
lengthreadonlynumberNumber of rows.
namesreadonlyreadonly string[]Column names, in order.

Methods ​

column() ​

ts
column(name): readonly unknown[];

The values of a column.

Parameters ​

ParameterType
namestring

Returns ​

readonly unknown[]

Throws ​

When there is no such column (the message lists the columns).


has() ​

ts
has(name): boolean;

Whether the table has a column called name.

Parameters ​

ParameterType
namestring

Returns ​

boolean


toColumns() ​

ts
toColumns(): Record<string, readonly unknown[]>;

The table as an object of columns (the arrays themselves, not copies).

Returns ​

Record<string, readonly unknown[]>


toRows() ​

ts
toRows(): Record<string, unknown>[];

The table as row objects.

Returns ​

Record<string, unknown>[]


type() ​

ts
type(name): ColumnType;

The inferred type of a column (see inferColumnType); computed once.

Parameters ​

ParameterType
namestring

Returns ​

ColumnType


withColumn() ​

ts
withColumn(name, values): Table;

A new table with one more column (or a column replaced).

Parameters ​

ParameterType
namestring
valuesreadonly unknown[]

Returns ​

Table

Released under the MIT License.