Styleable plain-text table generator. Useful for formatting console output. Available as both a command-line tool and isomorphic Javascript library.
Install as a library
Add table-layout to your project:
$ npm install --save table-layout
Display an array of objects as a table
Trivial example. Read a JSON file from disk and output a table with a maximum width (in characters) of 60.
import Table from 'table-layout'import { promises as fs } from 'fs'const issues = await fs.readFile('./issues.json', 'utf8')const table = new Table(JSON.parse(issues), { maxWidth: 60 })console.log(table.toString())
This is the example input file:
[ { "number": 15134, "title": "Coveralls has no source available ", "login": "ndelangen", "comments": 0 }, { "number": 15133, "title": "Fixing --preserve-symlinks. Enhancing node to exploit.", "login": "phestermcs", "comments": 0 }, { "number": 15131, "title": "Question - Confused about NPM's local installation philosophy", "login": "the1mills", "comments": 0
This is the output:
15134 Coveralls has no source available ndelangen 0 15133 Fixing --preserve-symlinks. phestermcs 0 Enhancing node to exploit. 15131 Question - Confused about NPM's the1mills 0 local installation philosophy 15130 Question - global npm cache ORESoftware 0 directory if user is root? 15127 how to installa gulp fontfacegen aramgreat 0 on Windows 10 15097 Cannot install package from mastertinner 3 tarball out of package.json entry generated by npm 15067 npm "SELF_SIGNED_CERT_IN_CHAIN" LegendsLyfe 3 error when installing discord.js with .log
Cherry-picked and computed values
Sometimes, your input data might contain a deeper structure or you want to transform or compute some values. Some example input data with structural depth and large numbers you'd like to reformat: