Socket
Socket
Sign inDemoInstall

tty-table

Package Overview
Dependencies
95
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tty-table

Command line table generator.


Version published
Weekly downloads
741K
increased by2.95%
Maintainers
1
Install size
3.37 MB
Created
Weekly downloads
 

Readme

Source

tty-table

Build Status Dependency Status NPM version Built with Grunt

Display yout data in a table using a terminal, browser, or browser console.

Installation

$ sudo apt-get install nodejs 
$ npm install tty-table -g
  • As a Nodejs module:
$ npm install tty-table
  • Browser (via browserify)
<script src="tty-table.bundle.min.js"></script>
<script>
 var Table = require('tty-table');
 ...
</script>

Why would someone do such a thing?

var Table = require('tty-table')('automattic-cli-table');
//now runs with same syntax as Automattic/cli-table
...

In addition to the fixes listed above, the native API also supports:

Output Examples

Terminal (Static)

examples/styles-and-formatting.js

Static

Terminal (Streaming)

$ node examples/data/fake-stream.js | tty-table --format=json

Streaming

  • *See the built-in help for the terminal version of tty-table with:
$ tty-table -h

Browser & Browser Console

Browser Console Example

Working Example in Browser

Note that neither ASCI colors nor default borders are rendered in the browser. An alternative border style, as shown below, should be used by setting the following option:

borderStyle : 2

Default API Reference

Table

Kind: global class
Note: Default border character sets:

[
[
 {v: " ", l: " ", j: " ", h: " ", r: " "},
 {v: " ", l: " ", j: " ", h: " ", r: " "},
 {v: " ", l: " ", j: " ", h: " ", r: " "}
],
[
 {v: "│", l: "┌", j: "┬", h: "─", r: "┐"},
 {v: "│", l: "├", j: "┼", h: "─", r: "┤"},
 {v: "│", l: "└", j: "┴", h: "─", r: "┘"}
],
[
 {v: "|", l: "+", j: "+", h: "-", r: "+"},
 {v: "|", l: "+", j: "+", h: "-", r: "+"},
 {v: "|", l: "+", j: "+", h: "-", r: "+"}
]
]

Table(header, rows, options)

ParamTypeDescription
headerarraySee example
header.columnobjectColumn options
header.column.aliasstringAlernate header column name
header.column.alignstringdefault: "center"
header.column.colorstringdefault: terminal default color
header.column.footerAlignstringdefault: "center"
header.column.footerColorstringdefault: terminal default color
header.column.formatterfunctionRuns a callback on each cell value in the parent column
header.column.headerAlignstringdefault: "center"
header.column.headerColorstringdefault: terminal's default color
header.column.marginLeftnumberdefault: 0
header.column.marginTopnumberdefault: 0
header.column.maxWidthnumberdefault: 20
header.column.paddingBottomnumberdefault: 0
header.column.paddingLeftnumberdefault: 0
header.column.paddingRightnumberdefault: 0
header.column.paddingTopnumberdefault: 0
rowsarraySee example
optionsobjectTable options
options.borderStylenumberdefault: 1 (0 = no border) Refers to the index of the desired character set.
options.borderCharactersarraySee @note
options.borderColorstringdefault: terminal's default color
options.compactbooleandefault: false Removes horizontal lines when true.
options.defaultErrorValuemixeddefault: 'ERROR!'
options.defaultValuemixeddefault: '?'
options.errorOnNullbooleandefault: false
options.truncatemixeddefault: false
When this property is set to a string, cell contents will be truncated by that string instead of wrapped when they extend beyond of the width of the cell.
For example if:
"truncate":"..."
the cell will be truncated with "..."

Example

let Table = require('tty-table');
let t1 = Table(header,rows,options);
console.log(t1.render()); 

Table.Cls.render() ⇒ String

Renders a table to a string

Kind: static method of Table
Example

let str = t1.render(); 
console.log(str); //outputs table

Running tests

$ grunt test

Saving the output of new unit tests

$ grunt st
  • Because:

node script.js --color=always

Dev Tips

  • To generate vim tags (make sure jsctags is installed globally)
$ grunt tags
  • To generate vim tags on file save
$ grunt watch

Packaging as a distributable

License

GPLv3 License

Copyright 2015-2017, Tecfu.

Keywords

FAQs

Last updated on 20 Jun 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc