Socket
Socket
Sign inDemoInstall

tty-table

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tty-table - npm Package Compare versions

Comparing version 2.8.2 to 2.8.3

66

examples/auttomatic-cli-table-tests.js
//var Table = require('cli-table');
var Table = require('../')('automattic-cli-table');
const Table = require("../")("automattic-cli-table")
/* col widths */
var table = new Table({
head: ['Rel', 'Change', 'By', 'When']
, colWidths: [6, 21, 25, 17]
});
table.push(
['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago']
, ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago']
);
console.log(table.toString());
const t1 = new Table({
head: ["Rel", "Change", "By", "When"]
, colWidths: [6, 21, 25, 17]
})
t1.push(
["v0.1", "Testing something cool", "rauchg@gmail.com", "7 minutes ago"]
, ["v0.1", "Testing something cool", "rauchg@gmail.com", "8 minutes ago"]
)
console.log(t1.toString())
/* compact */
var table = new Table({
head: ['Rel', 'Change', 'By', 'When']
, colWidths: [6, 21, 25, 17]
, style : {compact : true, 'padding-left' : 1}
});
table.push(
['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago']
, ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago']
, []
, ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago']
);
console.log(table.toString());
const t2 = new Table({
head: ["Rel", "Change", "By", "When"]
, colWidths: [6, 21, 25, 17]
, style: {compact: true, "padding-left": 1}
})
t2.push(
["v0.1", "Testing something cool", "rauchg@gmail.com", "7 minutes ago"]
, ["v0.1", "Testing something cool", "rauchg@gmail.com", "8 minutes ago"]
, []
, ["v0.1", "Testing something cool", "rauchg@gmail.com", "8 minutes ago"]
)
console.log(t2.toString())
/* headless */
var headless_table = new Table();
headless_table.push(['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago']);
console.log(headless_table.toString());
var headless_table = new Table()
headless_table.push(["v0.1", "Testing something cool", "rauchg@gmail.com", "7 minutes ago"])
console.log(headless_table.toString())
/* vertical */
var vertical_table = new Table({
style : {
head : ['green']
style: {
head: ["green"]
}
});
})
vertical_table.push({ "Some Key": "Some Value"},
{"Another much longer key": "And its corresponding longer value"}
);
console.log(vertical_table.toString());
)
console.log(vertical_table.toString())
/* cross */
var cross_table = new Table({ head: ["", "Header #1", "Header #2"] });
var cross_table = new Table({ head: ["", "Header #1", "Header #2"] })
cross_table.push({ "Header #3": ["Value 1", "Value 2"] },
{ "Header #4": ["Value 3", "Value 4"] });
console.log(cross_table.toString());
{ "Header #4": ["Value 3", "Value 4"] })
console.log(cross_table.toString())

@@ -1,6 +0,6 @@

let cp = require('child_process');
let pwd = __dirname;
let output = cp.execSync('cat '+pwd+'/data/data.csv | node '+pwd+'/../adapters/terminal-adapter.js',{
encoding:'utf8'
});
console.log(output);
let cp = require("child_process")
let pwd = __dirname
let output = cp.execSync(`cat ${pwd}/data/data.csv | node ${pwd}/../adapters/terminal-adapter.js`,{
encoding: "utf8"
})
console.log(output)

@@ -10,9 +10,9 @@ let chalk = require("chalk")

"color": "red",
width : 10,
formatter : function(value){
var str = "$" + value.toFixed(2);
if(value > 138){
str = chalk.bold.green(str);
width: 10,
formatter: function(value) {
var str = `$${ value.toFixed(2)}`
if(value > 138) {
str = chalk.bold.green(str)
}
return str;
return str
}

@@ -19,0 +19,0 @@ }

var tickers = [
["AAPL",138],
["IBM",120],
["WMT",68],
["ABX",13],
["MSFT",35]
];
["AAPL",138],
["IBM",120],
["WMT",68],
["ABX",13],
["MSFT",35]
]
//http://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
var makeTicker = function(){
var text = [];
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var length = 25;
const makeTicker = function() {
let text = []
let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
let length = 25
for(var i=0;i<length;i++){
var char = possible.charAt(Math.floor(Math.random()*possible.length));
text.push(char);
}
for(let i=0; i<length; i++) {
let char = possible.charAt(Math.floor(Math.random()*possible.length))
text.push(char)
}
return [text.join(""),Math.floor(Math.random(3)*100)];
return [text.join(""),Math.floor(Math.random(3)*100)]
}
var cycle = function(iterator,tickers){
//remove or add a random ticker to test auto resizing
const cycle = function(iterator,tickers) {
//remove or add a random ticker to test auto resizing
// if(iterator % 6 === 0){

@@ -33,22 +33,22 @@ // tickers.pop();

//change ticker values
tickers = tickers.map(function(value){
var sign = (Math.random()) < .5 ? -1 : 1;
var increment = Math.random();
var newVal = (value[1]+sign*increment).toFixed(2)*1;
return [value[0],newVal];
})
//change ticker values
tickers = tickers.map(function(value) {
let sign = (Math.random()) < .5 ? -1 : 1
let increment = Math.random()
let newVal = (value[1]+sign*increment).toFixed(2)*1
return [value[0],newVal]
})
console.log(JSON.stringify(tickers));
iterator++;
console.log(JSON.stringify(tickers))
iterator++
setTimeout(function(){
cycle(iterator,tickers)
},500);
setTimeout(function() {
cycle(iterator,tickers)
},500)
}
process.stdout.on('error',function(){
process.exit(1);
});
process.stdout.on("error",function() {
process.exit(1)
})
cycle(1,tickers);
cycle(1,tickers)

@@ -1,43 +0,37 @@

var header = ['SYMBOL','LAST']
var baseline = {
"aapl" : 92,
"ibm" : 120.72,
"wmt" : 68.93,
"abx" : 13.36,
"msft" : 35.26
};
const header = ["SYMBOL","LAST"]
let baseline = {
"aapl": 92,
"ibm": 120.72,
"wmt": 68.93,
"abx": 13.36,
"msft": 35.26
}
var last = {};
setInterval(function() {
setInterval(function(){
// //Add imaginary ticker
// let newTicker = Math.random().toString(36).substring(7);
// baseline[newTicker] = Math.random();
//
// //Remove a random ticker
// let keys = Object.keys(baseline);
// let random = Math.floor(Math.random() * keys.length) + 0;
// delete baseline[keys[random]];
// //Add imaginary ticker
// var newTicker = Math.random().toString(36).substring(7);
// baseline[newTicker] = Math.random();
//
// //Remove a random ticker
// var keys = Object.keys(baseline);
// var random = Math.floor(Math.random() * keys.length) + 0;
// delete baseline[keys[random]];
let array = [header]
var array = [header];
for(var i in baseline){
for(let i in baseline) {
//give each symbol a 30% chance of changing
if(Math.random() >= .7){
baseline[i] = (baseline[i] + ((Math.random() > .5) ? .01 : -.01)).toFixed(2)*1;
if(Math.random() >= .7) {
baseline[i] = (baseline[i] + ((Math.random() > .5) ? .01 : -.01)).toFixed(2)*1
}
else {
baseline[i] = baseline[i];
}
array.push([i,'$ ' + baseline[i].toFixed(2)])
array.push([i,`$ ${ baseline[i].toFixed(2)}`])
}
var string = JSON.stringify(array);
console.log(string);
},500)
let string = JSON.stringify(array)
console.log(string)
},500)
process.stdout.on('error',function(){
process.exit(1);
});
process.stdout.on("error",function() {
process.exit(1)
})

@@ -1,27 +0,22 @@

var Table = require('../');
const Table = require("../")
const header = [
{ value: 'col1' },
{ value: 'col2' }
];
{ value: "col1" },
{ value: "col2" }
]
const rows = [];
const rows = []
const header2 = [
{ value: 'col1' },
{ value: 'col2' },
{ value: 'col3' }
];
{ value: "col1" },
{ value: "col2" },
{ value: "col3" }
]
const rows2 = [];
const rows2 = []
var a = Table(header2, rows2);
debugger;
console.log(a.render());
let a = Table(header2, rows2)
console.log(a.render())
var b = Table(header, rows);
debugger;
console.log(b.render());
//console.log(Table(header2, rows2).render());
//console.log(Table(header, rows).render());
let b = Table(header, rows)
console.log(b.render())

@@ -1,30 +0,25 @@

var Table = require('../');
const Table = require("../")
const header = [
{ value: 'col1' },
{ value: 'col2' }
];
{ value: "col1" },
{ value: "col2" }
]
const rows = [[1, 2]];
const rows = [[1, 2]]
const header2 = [
{ value: 'col1' },
{ value: 'col2' },
{ value: 'col3' }
];
{ value: "col1" },
{ value: "col2" },
{ value: "col3" }
]
const rows2 = [
[1, 2, 3],
[03,34,99]
];
[3,34,99]
]
var a = Table(header2, rows2);
debugger;
console.log(a.render());
let a = Table(header2, rows2)
console.log(a.render())
var b = Table(header, rows);
debugger;
console.log(b.render());
//console.log(Table(header2, rows2).render());
//console.log(Table(header, rows).render());
let b = Table(header, rows)
console.log(b.render())

@@ -1,8 +0,8 @@

const Table = require('../');
const Table = require("../")
//Example with arrays as rows
//Example with arrays as rows
const rows = [
['xxxyyyzzz'],
['zzzxxxyyy']
];
["xxxyyyzzz"],
["zzzxxxyyy"]
]

@@ -13,45 +13,42 @@ const t1 = Table(rows,{

marginLeft: 0,
align : "left",
color : "white"
});
align: "left",
color: "white"
})
str1 = t1.render();
console.log(str1);
console.log(t1.render())
//Example with arrays as rows
//Example with arrays as rows
const rows2 = [
['xxxyyyzzz'],
['zzzxxxyyy']
];
["xxxyyyzzz"],
["zzzxxxyyy"]
]
const t2 = Table(rows,{
borderStyle : "none",
const t2 = Table(rows2,{
borderStyle: "none",
compact: true,
marginTop: 0,
marginLeft: 0,
align : "left",
color : "white"
});
align: "left",
color: "white"
})
str2 = t2.render();
console.log(str2);
console.log(t2.render())
//Example with arrays as rows
//Another example with arrays as rows
const rows3 = [
['xxxyyyzzz', 'aaaaa'],
['zzzxxxyyy', 'bbbbbb']
];
["xxxyyyzzz", "aaaaa"],
["zzzxxxyyy", "bbbbbb"]
]
const t3 = Table(rows3,{
borderStyle : "none",
borderStyle: "none",
compact: true,
align : "left",
color : "white",
align: "left",
color: "white",
marginTop: 0,
marginLeft: 0
});
})
str3 = t3.render();
console.log(str3);
console.log(t3.render())

@@ -1,24 +0,24 @@

var Chalk = require('chalk');
var Table = require('../');
const Table = require("../")
const Chalk = require("chalk")
var header = [
let header = [
{
value : "item",
formatter : function(value){
return Chalk.cyan(value);
value: "item",
formatter: function(value) {
return Chalk.cyan(value)
}
},
{
value : "price",
width : 10
value: "price",
width: 10
},
{
value : "organic",
width : 10
value: "organic",
width: 10
}
];
]
//Example with arrays as rows
var rows = [
[],
//Example with arrays as rows
let rows = [
[],
["hamburger",2.50,null],

@@ -30,78 +30,76 @@ ["el jefe's special cream sauce",0.10],

["macaroni, ham and peruvian mozzarella",3.75,"no"]
];
]
var footer = [
let footer = [
"TOTAL",
(function(){
return rows.reduce(function(prev,curr){
return (typeof curr[1] === 'number') ? prev+curr[1] : prev
(function() {
return rows.reduce(function(prev,curr) {
return (typeof curr[1] === "number") ? prev+curr[1] : prev
},0)
}()),
'N/A'];
"N/A"]
var t1 = Table(header,rows,footer,{
borderStyle : 1,
paddingBottom : 0,
headerAlign : "center",
align : "center",
color : "green",
footerColor : "yellow",
footerAlign : "right"
});
let t1 = Table(header,rows,footer,{
borderStyle: 1,
paddingBottom: 0,
headerAlign: "center",
align: "center",
color: "green",
footerColor: "yellow",
footerAlign: "right"
})
t1.push(
["chocolate cake",4.65,"no"]
);
)
var str1 = t1.render();
console.log(str1);
console.log(t1.render())
//Example with objects as rows
var rows = [
//Example with objects as rows
let rows2 = [
{},
{
item : "hamburger",
price : 2.50,
organic : null
item: "hamburger",
price: 2.50,
organic: null
},
{
item : "el jefe's special cream sauce",
price : 0.10
item: "el jefe's special cream sauce",
price: 0.10
},
{
item : "two tacos, rice and beans topped with cheddar cheese",
price : 9.80,
organic : "no"
item: "two tacos, rice and beans topped with cheddar cheese",
price: 9.80,
organic: "no"
},
{
item : "apple slices",
price : 1.00,
organic : "yes"
},
item: "apple slices",
price: 1.00,
organic: "yes"
},
{
item : null,
price : 1.50,
organic : "no"
item: null,
price: 1.50,
organic: "no"
},
{
item : "macaroni, ham and peruvian mozzarella",
price : 3.75,
organic : "no"
item: "macaroni, ham and peruvian mozzarella",
price: 3.75,
organic: "no"
}
];
]
var t2 = Table(header,rows,{
borderStyle : 1,
paddingBottom : 0,
headerAlign : "center",
align : "center",
color : "cyan",
headerColor : "yellow"
});
let t2 = Table(header,rows2,{
borderStyle: 1,
paddingBottom: 0,
headerAlign: "center",
align: "center",
color: "cyan",
headerColor: "yellow"
})
var str2 = t2.render();
console.log(str2);
console.log(t2.render())
//var header3 = [
//let header3 = [
// {

@@ -115,3 +113,3 @@ // alias : "Is organic?",

////Example with objects as rows3
//var rows3 = [
//let rows3 = [
// {

@@ -137,3 +135,3 @@ // organic : "no"

//
//var t3 = Table(header3,rows3,{
//let t3 = Table(header3,rows3,{
// borderStyle : 1,

@@ -143,3 +141,3 @@ // paddingBottom : 0

//
//var str3 = t3.render();
//let str3 = t3.render();
//console.log(str3);

@@ -146,0 +144,0 @@

@@ -1,47 +0,46 @@

var Table = require('../');
var chalk = require('chalk');
const Table = require("../")
const chalk = require("chalk")
var header = [
let header = [
{
value : "item",
headerColor : "cyan",
value: "item",
headerColor: "cyan",
color: "white",
align : "left",
paddingLeft : 5,
width : 30
align: "left",
paddingLeft: 5,
width: 30
},
{
value : "price",
color : "red",
width : 10,
formatter : function(value){
var str = "$" + value.toFixed(2);
if(value > 5){
str = chalk.underline.green(str);
value: "price",
color: "red",
width: 10,
formatter: function(value) {
var str = `$${value.toFixed(2)}`
if(value > 5) {
str = chalk.underline.green(str)
}
return str;
return str
}
},
{
alias : "Is organic?",
value : "organic",
width : 15,
formatter : function(value){
//will convert an empty string to 0
alias: "Is organic?",
value: "organic",
width: 15,
formatter: function(value) {
//will convert an empty string to 0
//value = value * 1;
if(value === 'yes'){
value = chalk.black.bgGreen(value);
if(value === "yes") {
value = chalk.black.bgGreen(value)
} else{
value = chalk.white.bgRed(value)
}
else{
value = chalk.white.bgRed(value);
}
return value;
return value
}
}
];
]
//Example with arrays as rows
var rows = [
//Example with arrays as rows
const rows = [
["hamburger",2.50,"no"],

@@ -53,76 +52,74 @@ ["el jefe's special cream sauce",0.10,"yes"],

["macaroni, ham and peruvian mozzarella",3.75,"no"]
];
]
var footer = [
const footer = [
"TOTAL",
(function(){
return rows.reduce(function(prev,curr){
(function() {
return rows.reduce(function(prev,curr) {
return prev+curr[1]
},0)
}()),
(function(){
var total = rows.reduce(function(prev,curr){
return prev+((curr[2]==='yes') ? 1 : 0);
},0);
return (total/rows.length*100).toFixed(2) + "%";
}())];
(function() {
var total = rows.reduce(function(prev,curr) {
return prev+((curr[2]==="yes") ? 1 : 0)
},0)
return `${(total/rows.length*100).toFixed(2) }%`
}())]
var t1 = Table(header,rows,footer,{
borderStyle : 1,
borderColor : "blue",
paddingBottom : 0,
headerAlign : "center",
align : "center",
color : "white",
let t1 = Table(header,rows,footer,{
borderStyle: 1,
borderColor: "blue",
paddingBottom: 0,
headerAlign: "center",
align: "center",
color: "white",
truncate: "..."
});
})
str1 = t1.render();
console.log(str1);
console.log(t1.render())
//Example with objects as rows
var rows = [
//Example with objects as rows
const rows2 = [
{
item : "hamburger",
price : 2.50,
organic : "no"
item: "hamburger",
price: 2.50,
organic: "no"
},
{
item : "el jefe's special cream sauce",
price : 0.10,
organic : "yes"
item: "el jefe's special cream sauce",
price: 0.10,
organic: "yes"
},
{
item : "two tacos, rice and beans topped with cheddar cheese",
price : 9.80,
organic : "no"
item: "two tacos, rice and beans topped with cheddar cheese",
price: 9.80,
organic: "no"
},
{
item : "apple slices",
price : 1.00,
organic : "yes"
},
item: "apple slices",
price: 1.00,
organic: "yes"
},
{
item : "ham sandwich",
price : 1.50,
organic : "no"
item: "ham sandwich",
price: 1.50,
organic: "no"
},
{
item : "macaroni, ham and peruvian mozzarella",
price : 3.75,
organic : "no"
item: "macaroni, ham and peruvian mozzarella",
price: 3.75,
organic: "no"
}
];
]
var t2 = Table(header,rows,{
borderStyle : 1,
paddingBottom : 0,
headerAlign : "center",
align : "center",
color : "white"
});
const t2 = Table(header,rows2,{
borderStyle: 1,
paddingBottom: 0,
headerAlign: "center",
align: "center",
color: "white"
})
var str2 = t2.render();
console.log(str2);
console.log(t2.render())

@@ -132,16 +129,43 @@

let header3 = [
{ value: 'name', width: 30, headerAlign: 'left' },
{ value: 'price', width: 30, headerAlign: 'left' }
];
{ value: "name", width: 30, headerAlign: "left" },
{ value: "price", width: 30, headerAlign: "left" }
]
const opts = {
align: 'left'
};
align: "left"
}
const data = [
const rows3 = [
[`apple ${chalk.red("mac")}`,92.50],
["ibm",120.15]
]
]
let t3 = Table(header3,data, opts);
console.log(t3.render());
let t3 = Table(header3, rows3, opts)
console.log(t3.render())
const header4 = [
{
value: 'price',
formatter(cellValue, columnIndex, rowIndex, rowData, inputData) {
const row = inputData[rowIndex] // How to get the whole row
let _color
if(!row.enabled) _color = 'gray'
if(row.important) _color = 'red'
return chalk[_color](cellValue)
}
},
{
value: 'item'
}
]
const rows4 = [
{ item: 'banana', price: 1.99, important: true, enabled: true },
{ item: 'grapes', price: 2.99, important: false, enabled: false }
]
const t4 = Table(header4, rows4)
console.log(t4.render())

@@ -1,2 +0,2 @@

var Table = require('../');
var Table = require("../")

@@ -10,8 +10,8 @@ const rows = [[`The use of the secure-rm CLI is deprecated.

borderStyle: 1,
borderColor: 'yellow',
borderColor: "yellow",
paddingBottom: 0,
headerAlign: 'center',
headerColor: 'yellow',
align: 'center',
color: 'white'
headerAlign: "center",
headerColor: "yellow",
align: "center",
color: "white"
})

@@ -18,0 +18,0 @@

@@ -1,115 +0,115 @@

const Table = require('../');
const Chalk = require('chalk');
const Table = require("../")
const Chalk = require("chalk")
let header = [
{
value : "item",
formatter : function(value){
return Chalk.cyan(value);
value: "item",
formatter: function(value) {
return Chalk.cyan(value)
},
width : 10
width: 10
},
{
value : "price",
width : 10
value: "price",
width: 10
},
{
value : "organic",
width : 10
value: "organic",
width: 10
}
];
]
//test truncation with elipsis
let t1 = Table(header,[],{
borderStyle : 1,
paddingBottom : 0,
headerAlign : "center",
align : "center",
color : "green",
truncate : "..."
});
borderStyle: 1,
paddingBottom: 0,
headerAlign: "center",
align: "center",
color: "green",
truncate: "..."
})
t1.push(
["chocolate cake",4.65,"no"]
);
)
let str1 = t1.render();
console.log(str1);
let str1 = t1.render()
console.log(str1)
//test truncation with spaces
let t2 = Table(header,[],{
borderStyle : 1,
paddingBottom : 0,
headerAlign : "center",
align : "center",
color : "green",
truncate : "..."
});
borderStyle: 1,
paddingBottom: 0,
headerAlign: "center",
align: "center",
color: "green",
truncate: "..."
})
t2.push(
["pound cake",123456789123456789,"no"]
);
)
let str2 = t2.render();
console.log(str2);
let str2 = t2.render()
console.log(str2)
//test with padding
let t3 = Table(header,[],{
borderStyle : 1,
paddingLeft : 2,
borderStyle: 1,
paddingLeft: 2,
paddingRight: 2,
headerAlign : "center",
align : "center",
color : "green",
truncate : "..."
});
headerAlign: "center",
align: "center",
color: "green",
truncate: "..."
})
t3.push(
["pound cake",123456789123456789,"no"]
);
)
let str3 = t3.render();
console.log(str3);
let str3 = t3.render()
console.log(str3)
//test truncation with boolean false
let t4 = Table(header,[],{
borderStyle : 1,
paddingBottom : 0,
headerAlign : "center",
align : "center",
color : "green",
truncate : false
});
borderStyle: 1,
paddingBottom: 0,
headerAlign: "center",
align: "center",
color: "green",
truncate: false
})
t4.push(
["chocolate cake",4.65,"no"]
);
)
let str4 = t4.render();
console.log(str4);
let str4 = t4.render()
console.log(str4)
//test truncation with boolean false
let t5 = Table(header,[],{
borderStyle : 1,
paddingBottom : 0,
headerAlign : "center",
align : "center",
color : "green",
truncate : true
});
borderStyle: 1,
paddingBottom: 0,
headerAlign: "center",
align: "center",
color: "green",
truncate: true
})
t5.push(
["chocolate cake",5.65,"no"]
);
)
let str5 = t5.render();
console.log(str5);
let str5 = t5.render()
console.log(str5)
let t6 = Table([
{ width: 5}, { width: 4}, { width: 5}
],[],{
truncate: '...',
{ width: 5}, { width: 4}, { width: 5}
],[],{
truncate: "...",
paddingLeft: 0,
paddingRight: 0
});
})

@@ -122,3 +122,3 @@ t6.push(

let str6 = t6.render();
console.log(str6);
let str6 = t6.render()
console.log(str6)

@@ -1,16 +0,16 @@

var Table = require('../');
const Table = require("../")
var header = [
let header = [
{
value : "项目",
value: "项目",
},
{
value : "价格",
value: "价格",
},
{
value : "有机",
value: "有机",
}
];
]
var rows = [
let rows = [
["汉堡包",2.50,null],

@@ -22,45 +22,42 @@ ["特制的酱汁",0.10],

["意大利粉, 火腿, 意大利干酪",3.75,"no"]
];
]
var t1 = Table(header,rows,{
borderStyle : 1,
headerAlign : "right",
align : "center",
color : "white"
});
let t1 = Table(header,rows,{
borderStyle: 1,
headerAlign: "right",
align: "center",
color: "white"
})
str1 = t1.render();
console.log(str1);
console.log(t1.render())
var header2 = [
let header2 = [
{
value : "项目",
value: "项目",
},
{
value : "价格",
value: "价格",
},
{
value : "有机",
value: "有机",
}
];
]
var rows2 = [
let rows2 = [
["abc"],
["abć"],
["ab한"]
];
["ab한"]
]
var t2 = Table(header2,rows2,{
borderStyle : 2,
paddingBottom : 0,
let t2 = Table(header2,rows2,{
borderStyle: 2,
paddingBottom: 0,
paddingLeft: 2,
paddingRight: 2,
headerAlign : "right",
align : "center",
color : "white"
});
headerAlign: "right",
align: "center",
color: "white"
})
str2 = t2.render();
console.log(str2);
console.log(t2.render())
{
"name": "tty-table",
"version": "2.8.2",
"version": "2.8.3",
"description": "Command line table generator.",

@@ -18,3 +18,5 @@ "main": "src/main.js",

"lint": "./node_modules/.bin/eslint adapters/* src/*",
"lint-fix": "./node_modules/.bin/eslint adapters/* src/* --fix"
"lint-fix": "./node_modules/.bin/eslint adapters/* src/* --fix",
"lint-examples": "./node_modules/.bin/eslint adapters/* examples/*",
"lint-examples-fix": "./node_modules/.bin/eslint adapters/* examples/* --fix"
},

@@ -69,4 +71,4 @@ "repository": {

"mocha": "^6.1.4",
"orgy": "^2.2.0"
"orgy": "^2.2.1"
}
}

@@ -11,28 +11,7 @@ # tty-table 电传打字台

## Installation
## [Examples](examples/)
- [Terminal](docs/terminal.md):
[See here for complete example list](examples/)
```sh
$ npm install tty-table -g
```
- Node Module
```sh
$ npm install tty-table
```
- Browser
```html
<script src="tty-table.bundle.min.js"></script>
<script>
let Table = require('tty-table');
...
</script>
```
## [Examples](examples/)
### Terminal (Static)

@@ -72,64 +51,135 @@

<br/>
<br/>
## API Reference
<!--API-REF-->
<a name="Table"></a>
<a name="new_Table_new"></a>
### Table(header ```array```, rows ```array```, options ```object```)
## Table
**Kind**: global class
| Param | Type | Description |
| --- | --- | --- |
| [header](#header_options) | <code>array</code> | 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](#header_options) |
| [rows](#rows_examples) | <code>array</code> | Your data. An array of arrays or objects. [See examples](#rows_examples) |
| [options](#options_properties) | <code>object</code> | Global table configuration. [See available properties](#options_properties) |
* [Table](#Table)
* [Table(header, rows, options)](#new_Table_new)
* [.tableObject.render()](#Table.tableObject.render) ⇒ <code>String</code>
<a name="new_Table_new"></a>
<br/>
<a name="header_options"></a>
### Table(header, rows, options)
#### header <code>array of objects</code>
| Param | Type | Description |
| --- | --- | --- |
| header | <code>array</code> | [See example](#example-usage) |
| header.column | <code>object</code> | Column options |
| header.column.alias | <code>string</code> | Alternate header column name |
| header.column.align | <code>string</code> | default: "center" |
| header.column.color | <code>string</code> | default: terminal default color |
| header.column.footerAlign | <code>string</code> | default: "center" |
| header.column.footerColor | <code>string</code> | default: terminal default color |
| header.column.formatter | <code>function</code> | Runs a callback on each cell value in the parent column |
| header.column.headerAlign | <code>string</code> | default: "center" |
| header.column.headerColor | <code>string</code> | default: terminal's default color |
| header.column.marginLeft | <code>number</code> | default: 0 |
| header.column.marginTop | <code>number</code> | default: 0 |
| header.column.width | <code>string</code> \| <code>number</code> | default: "auto" |
| header.column.paddingBottom | <code>number</code> | default: 0 |
| header.column.paddingLeft | <code>number</code> | default: 1 |
| header.column.paddingRight | <code>number</code> | default: 1 |
| header.column.paddingTop | <code>number</code> | default: 0 |
| rows | <code>array</code> | [See example](#example-usage) |
| options | <code>object</code> | Table options |
| options.borderStyle | <code>string</code> | default: "solid". options: "solid", "dashed", "none" |
| options.borderCharacters | <code>object</code> | [See @note](#note) |
| options.borderColor | <code>string</code> | default: terminal's default color |
| options.compact | <code>boolean</code> | default: false Removes horizontal lines when true. |
| options.defaultErrorValue | <code>mixed</code> | default: 'ERROR!' |
| options.defaultValue | <code>mixed</code> | default: '?' |
| options.errorOnNull | <code>boolean</code> | default: false |
| options.truncate | <code>mixed</code> | default: false <br/> 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. <br/> For example if: <br/> <code>"truncate":"..."</code> <br/> the cell will be truncated with "..." |
| alias | <code>string</code> | Text to display in column header cell |
| align | <code>string</code> | default: "center" |
| color | <code>string</code> | default: terminal default color |
| footerAlign | <code>string</code> | default: "center" |
| footerColor | <code>string</code> | default: terminal default color |
| formatter | <code>function(cellValue, columnIndex, rowIndex, rowData,inputData)</code> | Runs a callback on each cell value in the parent column |
| headerAlign | <code>string</code> | default: "center" |
| headerColor | <code>string</code> | default: terminal's default color |
| marginLeft | <code>integer</code> | default: 0 |
| marginTop | <code>integer</code> | default: 0 |
| width | <code>string</code> \|\| <code>integer</code> | default: "auto" |
| paddingBottom | <code>integer</code> | default: 0 |
| paddingLeft | <code>integer</code> | default: 1 |
| paddingRight | <code>integer</code> | default: 1 |
| paddingTop | <code>integer</code> | default: 0 |
| value | <code>string</code> | Name of the property to display in each cell when data passed as an array of objects |
**Example**
**Example**
```js
let Table = require('tty-table');
let t1 = Table(header,rows,options);
console.log(t1.render());
let header = [
{
alias: "my items",
value: "item",
headerColor: "cyan",
color: "white",
align: "left",
paddingLeft: 5,
width: 30
},
{
value: "price", // if not set, alias will default to "price"
color: "red",
width: 10,
formatter: function(cellValue) {
var str = `$${cellValue.toFixed(2)}`
if(value > 5) {
str = chalk.underline.green(str)
}
return str
}
}
]
```
<br/>
<br/>
<a name="rows_examples"></a>
#### rows <code>array</code>
**Example**
- each row an array
```js
const rows = [
["hamburger",2.50],
]
```
- each row an object
```js
const rows = [
{
item: "hamburger",
price: 2.50
}
]
```
<br/>
<br/>
<a name="options_properties"></a>
#### options <code>object</code>
| Param | Type | Description |
| --- | --- | --- |
| borderStyle | <code>string</code> | default: "solid". "solid", "dashed", "none" |
| borderColor | <code>string</code> | default: terminal default color |
| color | <code>string</code> | default: terminal default color |
| compact | <code>boolean</code> | default: false Removes horizontal lines when true. |
| defaultErrorValue | <code>mixed</code> | default: 'ERROR!' |
| defaultValue | <code>mixed</code> | default: '?' |
| errorOnNull | <code>boolean</code> | default: false |
| truncate | <code>mixed</code> | default: false <br/> 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. <br/> For example if: <br/> <code>"truncate":"..."</code> <br/> the cell will be truncated with "..." |
**Example**
```js
const options = {
borderStyle: 1,
borderColor: "blue",
headerAlign: "center",
align: "left",
color: "white",
truncate: "..."
}
```
<br/>
### Table.render() ⇒ <code>String</code>
<a name="Table.tableObject.render"></a>
### Table.tableObject.render() ⇒ <code>String</code>
Add method to render table to a string
**Kind**: static method of [<code>Table</code>](#Table)
**Example**
```js
let str = t1.render();
console.log(str); //outputs table
const out = Table(header,rows,options).render()
console.log(out); //prints output
```

@@ -139,2 +189,30 @@

<br/>
<br/>
## Installation
- [Terminal](docs/terminal.md):
```sh
$ npm install tty-table -g
```
- Node Module
```sh
$ npm install tty-table
```
- Browser
```html
<script src="tty-table.bundle.min.js"></script>
<script>
const Table = require('tty-table');
...
</script>
```
## Running tests

@@ -141,0 +219,0 @@

@@ -148,3 +148,3 @@ const StripAnsi = require("strip-ansi")

breakword: true
}).split('\n')[0]
}).split("\n")[0]
string = string + cellOptions.truncate

@@ -151,0 +151,0 @@ }

@@ -8,3 +8,3 @@ const Style = require("./style.js")

*/
Render.stringifyData = function(config,data) {
Render.stringifyData = function(config,inputData) {
const sections = {

@@ -21,9 +21,9 @@ header: [],

//how rows are passed (array of arrays, objects, etc)
config.rowFormat = Render.getRowFormat(data[0] || [],config)
config.rowFormat = Render.getRowFormat(inputData[0] || [],config)
//now translate them
data = Render.transformRows(config,data)
const rowData = Render.transformRows(config,inputData)
//when streaming values to tty-table, we don't want column widths to change
//from one data set to the next, so we save the first set of widths and reuse
//from one rowData set to the next, so we save the first set of widths and reuse
if(!global.columnWidths) {

@@ -36,3 +36,3 @@ global.columnWidths = {}

} else{
global.columnWidths[config.tableId] = config.table.columnWidths = Format.getColumnWidths(config,data)
global.columnWidths[config.tableId] = config.table.columnWidths = Format.getColumnWidths(config,rowData)
}

@@ -43,3 +43,3 @@

sections.header = config.table.header.map(function(row) {
return buildRow(config,row,"header")
return buildRow(config,row,"header",null,rowData,inputData)
})

@@ -51,4 +51,4 @@ } else{

//stringify body cells
sections.body = data.map(function(row) {
return buildRow(config,row,"body")
sections.body = rowData.map(function(row, rowIndex) {
return buildRow(config,row,"body",rowIndex,rowData,inputData)
})

@@ -60,3 +60,3 @@

sections.footer = sections.footer.map(function(row) {
return buildRow(config,row,"footer")
return buildRow(config,row,"footer",null,rowData,inputData)
})

@@ -141,3 +141,3 @@

const buildRow = function(config,row,rowType) {
const buildRow = function(config,row,rowType,rowIndex,rowData,inputData) {

@@ -173,3 +173,3 @@ let minRowHeight = 0

let c = Render.buildCell(config,row[index],index,rowType)
let c = Render.buildCell(config,row[index],index,rowType,rowIndex,rowData,inputData)
let cellArr = c.cellArr

@@ -220,3 +220,3 @@

Render.buildCell = function(config,cell,columnIndex,rowType) {
Render.buildCell = function(config,cell,columnIndex,rowType,rowIndex,rowData,inputData) {

@@ -251,3 +251,3 @@ let cellValue

if(typeof cellOptions.formatter === "function") {
cellValue = cellOptions.formatter(cellValue)
cellValue = cellOptions.formatter(cellValue,columnIndex,rowIndex,rowData,inputData)
}

@@ -254,0 +254,0 @@ }

@@ -1,2 +0,2 @@

let Chalk = require("chalk")
const Chalk = require("chalk")

@@ -3,0 +3,0 @@ exports.colorizeCell = function(str,cellOptions,rowType) {

@@ -47,1 +47,9 @@

└──────────────────────────────┴──────────────────────────────┘
┌───────┬────────┐
│ price │ item │
├───────┼────────┤
│ 1.99 │ banana │
├───────┼────────┤
│ 2.99 │ grapes │
└───────┴────────┘

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc