as-table
A simple function that print objects and arrays as ASCII tables. Supports ANSI styling and weird 💩 Unicode emoji symbols (they won't break the layout), thanks to printable-characters
.
npm install as-table
Printing objects
asTable =
foo string num
----------------------
true abcde 42
false qwertyuiop 43
null 44
Printing arrays
qwe 123456789 zxcvbnm
qwerty 12 zxcvb
qwertyiop 1234567 z
Limiting total width by proportionally trimming cells setting columns delimiter
asTable data
qwe | 1234… | zxc…
qwer… | 12 | zxc…
qwer… | 1234… | z
Right align
asTable data
foo bar baz
-----------------------------
qwe 123456789 zxcvbnm
qwerty 12 zxcvb
qwertyiop 1234567 z
Providing a custom object printer
asTable data
foo string num
--------------------
yes abcde 42
no qwertyuiop 43
null 44
The callback also receives a field name (in case of objects) or a column index (in case of arrays):
asTable =
Obtaining a pre-configured function
asTable =
Customizing the title rendering and the header separator
With string coloring by ansicolor
(just for the demo purposes, any library will fit):
asTable = console