0.4.0 • Published 4 years ago

sizeable-table v0.4.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

sizeable-table

add, remove rows and columns to / from 2 dimensional arrays

NPM version Build Status

installation

npm i sizeable-table 

usage

general

import { SizeableTable } from 'sizeable-table'

const array = [
  [1, 2],
  [3, 4]
]

const table = new SizeableTable(array, { 
  min: [2, 2], // min. table size 2x2
  max: [4, 4], // max. table size 4x4
  fill: 0      // fill new rows/ chars with 0
})
// table.table = [[1,2],[3,4]]

table.removeRow() // tries to remove row at end
//> false - min. rows exceeded
table.removeColumn() // tries to remove column at end
//> false - min. columns exceeded

table.addRow() // adds row at end
//> true
// table.table = [[1,2],[3,4],[0,0]]
table.addColumn()   // adds column at end
//> true
// table.table = [[1,2,0],[3,4,0],[0,0,0]]
table.addRow(0, 100)
//> true
// table.table = [[100,100,100],[1,2,0],[3,4,0],[0,0,0]]
table.addColumn(1, 20)
//> true
// table.table = [[100,20,100,100],[1,20,2,0],[3,20,4,0],[0,20,0,0]]
table.addColumn()
//> false - max. column exceeded

table.removeColumn(2)
//> true
// table.table = [[100,20,100],[1,20,0],[3,20,0],[0,20,0]]
table.removeRow(2)
//> true
// table.table = [[100,20,100],[1,20,0],[0,20,0]]

create table with defined dimensions

const table = new SizeableTable()
table.create([2,3], 1)
// table.table = [[1,1,1], [1,1,1]]
// table.dim = [2,3]

license

MIT licensed

0.4.0

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago