Gathering detailed insights and metrics for tty-table
Gathering detailed insights and metrics for tty-table
Gathering detailed insights and metrics for tty-table
Gathering detailed insights and metrics for tty-table
Terminal table for Windows, Linux, and MacOS. Written in nodejs. Also works in browser console. Word wrap, padding, alignment, colors, Asian character support, per-column callbacks, and you can pass rows as objects or arrays. Backwards compatible with Automattic/cli-table.
npm install tty-table
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
291 Stars
447 Commits
31 Forks
7 Watching
3 Branches
14 Contributors
Updated on 30 Oct 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-37.4%
110,538
Compared to previous day
Last week
1.2%
838,457
Compared to previous week
Last month
-3.4%
3,423,095
Compared to previous month
Last year
84.2%
32,574,974
Compared to previous year
29
Display your data in a table using a terminal, browser, or browser console.
See here for complete example list
To view all example output:
1$ git clone https://github.com/tecfu/tty-table && cd tty-table && npm i 2$ npm run view-examples
examples/styles-and-formatting.js
$ node examples/data/fake-stream.js | tty-table --format json --header examples/config/header.js
$ tty-table -h
View in Chrome or Chromium at http://localhost:8070/examples/browser-example.html using a dockerized apache instance:
1git clone https://github.com/tecfu/tty-table 2cd tty-table 3docker run -dit --name tty-table-in-browser -p 8070:80 -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4
array
, rows array
, options object
)Param | Type | Description |
---|---|---|
header | array | Per-column configuration. An array of objects, one object for each column. Each object contains properties you can use to configure that particular column. See available properties |
rows | array | Your data. An array of arrays or objects. See examples |
options | object | Global table configuration. See available properties |
array of objects
Param | Type | Description |
---|---|---|
alias | string | Text to display in column header cell |
align | string | default: "center" |
color | string | default: terminal default color |
footerAlign | string | default: "center" |
footerColor | string | default: terminal default color |
formatter | function(cellValue, columnIndex, rowIndex, rowData, inputData | Runs a callback on each cell value in the parent column. Please note that fat arrow functions () => {} don't support scope overrides, and this feature won't work correctly within them. |
@formatter configure | function(object) | Configure cell properties. For example: this.configure({ truncate: false, align: "left" }) More here. |
@formatter resetStyle | function(cellValue) | Removes ANSI escape sequences. For example: this.resetStyle("[32m myText[39m") // "myText" |
@formatter style | function(cellValue, effect) | Style cell value. For example: this.style("mytext", "bold", "green", "underline") For a full list of options in the terminal: chalk. For a full list of options in the browser: kleur |
headerAlign | string | default: "center" |
headerColor | string | default: terminal's default color |
marginLeft | integer | default: 0 |
marginTop | integer | default: 0 |
paddingBottom | integer | default: 0 |
paddingLeft | integer | default: 1 |
paddingRight | integer | default: 1 |
paddingTop | integer | default: 0 |
value | string | Name of the property to display in each cell when data passed as an array of objects |
width | string || integer | default: "auto" Can be a percentage of table width i.e. "20%" or a fixed number of columns i.e. "20". When set to the default ("auto"), the column widths are made proportionate by the longest value in each column. Note: Percentage columns and fixed value colums not intended to be mixed in the same table. |
Example
1let header = [{ 2 value: "item", 3 headerColor: "cyan", 4 color: "white", 5 align: "left", 6 width: 20 7}, 8{ 9 value: "price", 10 color: "red", 11 width: 10, 12 formatter: function (value) { 13 let str = `$${value.toFixed(2)}` 14 return (value > 5) ? this.style(str, "green", "bold") : 15 this.style(str, "red", "underline") 16 } 17}]
array
Example
1const rows = [ 2 ["hamburger",2.50], 3]
1const rows = [ 2 { 3 item: "hamburger", 4 price: 2.50 5 } 6]
array
Example
1const footer = [ 2 "TOTAL", 3 function (cellValue, columnIndex, rowIndex, rowData) { 4 let total = rowData.reduce((prev, curr) => { 5 return prev + curr[1] 6 }, 0) 7 .toFixed(2) 8 9 return this.style(`$${total}`, "italic") 10 } 11]
object
Param | Type | Description |
---|---|---|
borderStyle | string | default: "solid". options: "solid", "dashed", "none" |
borderColor | string | default: terminal default color |
color | string | default: terminal default color |
compact | boolean | default: false Removes horizontal borders when true. |
defaultErrorValue | mixed | default: '�' |
defaultValue | mixed | default: '?' |
errorOnNull | boolean | default: false |
truncate | mixed | default: 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 "..." Note: tty-table wraps overflowing cell text into multiple lines by default, so you would likely only utilize truncate for extremely long values. |
width | string | default: "100%" Width of the table. Can be a percentage of i.e. "50%" or a fixed number of columns in the terminal viewport i.e. "100". Note: When you use a percentage, your table will be "responsive". |
Example
1const options = { 2 borderStyle: "solid", 3 borderColor: "blue", 4 headerAlign: "center", 5 align: "left", 6 color: "white", 7 truncate: "...", 8 width: "90%" 9}
String
Add method to render table to a string
Example
1const out = Table(header,rows,options).render() 2console.log(out); //prints output
1$ npm install tty-table -g
1$ npm install tty-table
1import Table from 'https://cdn.jsdelivr.net/gh/tecfu/tty-table/dist/tty-table.esm.js' 2let Table = require('tty-table') // https://cdn.jsdelivr.net/gh/tecfu/tty-table/dist/tty-table.cjs.js 3let Table = TTY_Table; // https://cdn.jsdelivr.net/gh/tecfu/tty-table/dist/tty-table.umd.js
Node Version | tty-table Version |
---|---|
8 | >= 2.0 |
0.11 | >= 0.0 |
1$ npm test
1$ npm run coverage
1$ npm run save-tests
1$ npm run tags
1$ npm run watch-tags
Pull requests are encouraged!
If you aren't familiar with Conventional Commits, here's a good article on the topic
TL/DR:
Copyright 2015-2020, Tecfu.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/16 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
23 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More