immutable-table
Immutable.js powered Table data type.
immutable-table exports a Table
class which can be used to represent a sized
two dimensional array as an Immutable.js data type.
Installation
npm install --save immutable-table
Usage
To import in ES6:
;
To import in ES5:
var Table = Table;
To create a table you must pass a width
and height
to the constructor. Here
a table of width 3
and height 4
is created:
var table = 3 4;
By default all values of the table are undefined
. To set a value in the table,
use the setCell(x, y, value)
function:
table = table;
Negative indicies can be used to index from the right or bottom. This is true
for all index accepting methods. Here the bottom, right cell is set to 99
:
table = table;
Values can be any type. Likewise, get a value using getCell(x, y)
:
console;
will print value
.
You can get a range of values, as a Table, by using
slice(startX, startY, [endX], [endY])
. When endX
and endY
are not
provided, the ends of the table are used:
var subTable = table;
will return the bottom right subtable of table of size 2,3.
The width and height of a table can be read using the width
and height
readonly properties:
console;
will print 3 4
.
You can compare a table to another table using the equal(otherTable)
method:
console;
will print false
.
console;
will print true
.
You can also create a table from a CSV string:
var otherTable = Table;
Tables can be serialized to JSON:
var text = JSON;
and later deserialized using a reviver:
var sameTableAsBefore = JSON;
running:
sameTableAsBefore;
will evaluate to true
.