Comparing version 2.5.9 to 2.6.0
@@ -1,72 +0,69 @@ | ||
var Public = require('../src/public.js'); | ||
var Factory = require('../src/factory.js'); | ||
var Table = function(options){ | ||
options = options || {}; | ||
options = options || {}; | ||
options.adapter = "automattic"; | ||
//translations | ||
//header | ||
var header = []; | ||
if(options.head && options.head instanceof Array){ | ||
options.head.forEach(function(val){ | ||
header.push({ | ||
value : val | ||
}); | ||
}); | ||
} | ||
//translations | ||
//header | ||
var header = []; | ||
if(options.head && options.head instanceof Array){ | ||
options.head.forEach(function(val){ | ||
header.push({ | ||
value : val | ||
}); | ||
}); | ||
} | ||
//colWidths | ||
if(options.colWidths){ | ||
options.colWidths.forEach(function(val,i){ | ||
header[i].width = val; | ||
}); | ||
} | ||
//colWidths | ||
if(options.colWidths){ | ||
options.colWidths.forEach(function(val,i){ | ||
header[i].width = val; | ||
}); | ||
} | ||
//colAligns | ||
if(options.colAligns){ | ||
options.colAligns.forEach(function(val,i){ | ||
header[i].align = val; | ||
header[i].headerAlign = val; | ||
}); | ||
} | ||
//colAligns | ||
if(options.colAligns){ | ||
options.colAligns.forEach(function(val,i){ | ||
header[i].align = val; | ||
header[i].headerAlign = val; | ||
}); | ||
} | ||
//style | ||
options.style = options.style || {}; | ||
//style | ||
options.style = options.style || {}; | ||
//style - padding | ||
if(options.style['padding-left']){ | ||
options.paddingLeft = options.style['padding-left']; | ||
} | ||
if(options.style['padding-right']){ | ||
options.paddingRight = options.style['padding-right']; | ||
} | ||
//style - colors | ||
if(options.style.head && options.style.head instanceof Array){ | ||
options.headerColor = options.style.head[0]; | ||
} | ||
//style - padding | ||
if(options.style['padding-left']){ | ||
options.paddingLeft = options.style['padding-left']; | ||
} | ||
if(options.style['padding-right']){ | ||
options.paddingRight = options.style['padding-right']; | ||
} | ||
//style - colors | ||
if(options.style.head && options.style.head instanceof Array){ | ||
options.headerColor = options.style.head[0]; | ||
} | ||
if(options.style.body && options.style.body instanceof Array){ | ||
options.color = options.style.body[0]; | ||
} | ||
//style - compact | ||
if(options.style.compact){ | ||
options.compact = true; | ||
} | ||
if(options.style.body && options.style.body instanceof Array){ | ||
options.color = options.style.body[0]; | ||
} | ||
//style - compact | ||
if(options.style.compact){ | ||
options.compact = true; | ||
} | ||
//@todo style - border color | ||
//inherited from prototype | ||
this.setup(header,[],[],options); | ||
//inherited from prototype | ||
this.toString = this.render.bind(this); | ||
//@todo style - border color | ||
//inherited from prototype | ||
let t = Factory(header,[],[],options); | ||
t.toString = t.render; | ||
return t; | ||
} | ||
Table.prototype.__proto__ = Public; | ||
module.exports = Table; |
#!/usr/bin/env node | ||
let csv = require('csv'); | ||
let yargs = require('yargs'); | ||
yargs.epilog('Copyight github.com/tecfu 2017'); | ||
yargs.epilog('Copyight github.com/tecfu 2018'); | ||
yargs.option('csv-delimiter',{ | ||
@@ -24,2 +24,4 @@ describe:'Set the field delimiter. One character only.', | ||
}); | ||
//run help only at the end | ||
yargs = yargs.help('h').argv; | ||
@@ -39,5 +41,5 @@ let Chalk = require('chalk'); | ||
switch(true){ | ||
case(typeof yargs.argv.format === 'undefined'): | ||
case(typeof yargs.format === 'undefined'): | ||
break; | ||
case(yargs.argv.format.toString().match(/json/i) !== null): | ||
case(yargs.format.toString().match(/json/i) !== null): | ||
dataFormat = 'json'; | ||
@@ -50,6 +52,6 @@ break; | ||
let options = {}; | ||
Object.keys(yargs.argv).forEach(function(key){ | ||
Object.keys(yargs).forEach(function(key){ | ||
let keyParts = key.split('-'); | ||
if(keyParts[0]==='options'){ | ||
options[keyParts[1]]=yargs.argv[key]; | ||
options[keyParts[1]]=yargs[key]; | ||
} | ||
@@ -59,3 +61,3 @@ }); | ||
//look for header-n-* | ||
//Object.keys(yargs.argv).forEach(function(key){ | ||
//Object.keys(yargs).forEach(function(key){ | ||
// let keyParts = key.split('-'); | ||
@@ -68,3 +70,3 @@ // if(keyParts[0] === 'header'){ | ||
// } | ||
// header[column][keyParts[2]] = yargs.argv[key]; | ||
// header[column][keyParts[2]] = yargs[key]; | ||
// } | ||
@@ -83,4 +85,5 @@ //}); | ||
let Table = require('../src/public.js'); | ||
let t1 = Table.setup(header,body,options); | ||
let Table = require('../src/factory.js'); | ||
options.terminalAdapter = true; | ||
let t1 = Table(header,body,options); | ||
@@ -132,5 +135,5 @@ //hide cursor | ||
let formatterOptions = {}; | ||
Object.keys(yargs.argv).forEach(function(key){ | ||
if(key.slice(0,4) === 'csv-' && typeof(yargs.argv[key]) !== 'undefined'){ | ||
formatterOptions[key.slice(4)] = yargs.argv[key]; | ||
Object.keys(yargs).forEach(function(key){ | ||
if(key.slice(0,4) === 'csv-' && typeof(yargs[key]) !== 'undefined'){ | ||
formatterOptions[key.slice(4)] = yargs[key]; | ||
} | ||
@@ -173,4 +176,1 @@ }); | ||
}); | ||
//run help only at the end | ||
yargs.argv = yargs.help('h').argv; |
@@ -84,3 +84,3 @@ var Chalk = require('chalk'); | ||
t1.push( | ||
t4.push( | ||
["chocolate cake",4.65,"no"] | ||
@@ -102,3 +102,3 @@ ); | ||
t1.push( | ||
t5.push( | ||
["chocolate cake",5.65,"no"] | ||
@@ -105,0 +105,0 @@ ); |
@@ -42,3 +42,3 @@ /** | ||
command: function () { | ||
var cmd = 'browserify --standalone=TtyTable '+_ignore+' -r ./src/default-adapter.js > ./dist/<%= pkg.name %>.js -t [ babelify --presets [ es2015 babili] ] -p [ browserify-banner --template "'+banner+'"]'; | ||
var cmd = 'browserify --standalone=TtyTable '+_ignore+' -r ./adapters/default-adapter.js > ./dist/<%= pkg.name %>.js -t [ babelify --presets [ es2015 babili] ] -p [ browserify-banner --template "'+banner+'"]'; | ||
return cmd; | ||
@@ -49,3 +49,3 @@ } | ||
command: function () { | ||
var cmd = 'browserify --debug --standalone=TtyTable '+_ignore+' -r ./src/default-adapter.js > ./dist/<%= pkg.name %>.devel.js -t [ babelify --presets [ es2015 babili] ]'; | ||
var cmd = 'browserify --debug --standalone=TtyTable '+_ignore+' -r ./adapters/default-adapter.js > ./dist/<%= pkg.name %>.devel.js -t [ babelify --presets [ es2015 babili] ]'; | ||
return cmd; | ||
@@ -56,3 +56,3 @@ } | ||
command: function () { | ||
var cmd = 'browserify '+_ignore+' -r ./src/default-adapter.js:<%= pkg.name %> > ./dist/<%= pkg.name %>.bundle.js -t [ babelify --presets [ es2015 babili] ]'; | ||
var cmd = 'browserify '+_ignore+' -r ./adapters/default-adapter.js:<%= pkg.name %> > ./dist/<%= pkg.name %>.bundle.js -t [ babelify --presets [ es2015 babili] ]'; | ||
return cmd; | ||
@@ -63,3 +63,3 @@ } | ||
command: function () { | ||
var cmd = 'browserify --debug '+_ignore+' -r ./src/default-adapter.js:<%= pkg.name %> > ./dist/<%= pkg.name %>.bundle.devel.js -t [ babelify --presets [ es2015 babili] ]'; | ||
var cmd = 'browserify --debug '+_ignore+' -r ./adapters/default-adapter.js:<%= pkg.name %> > ./dist/<%= pkg.name %>.bundle.devel.js -t [ babelify --presets [ es2015 babili] ]'; | ||
return cmd; | ||
@@ -92,6 +92,9 @@ } | ||
files: ['**/*.js'], | ||
tasks: ['shell:generate-vim-tags-file'], | ||
tasks: [ | ||
'shell:generate-vim-tags-file', | ||
'mochaTest:test' | ||
], | ||
options: { | ||
spawn: true, | ||
reload: false | ||
livereload: true //defaults to port 35729 | ||
} | ||
@@ -98,0 +101,0 @@ } |
{ | ||
"name": "tty-table", | ||
"version": "2.5.9", | ||
"version": "2.6.0", | ||
"description": "Command line table generator.", | ||
@@ -5,0 +5,0 @@ "main": "src/main.js", |
let Config = { | ||
borderCharacters : [ | ||
[ | ||
{v: " ", l: " ", j: " ", h: " ", r: " "}, | ||
{v: " ", l: " ", j: " ", h: " ", r: " "}, | ||
{v: " ", l: " ", j: " ", h: " ", r: " "} | ||
borderCharacters : [ | ||
[ | ||
{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: "+"} | ||
] | ||
], | ||
[ | ||
{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: "+"} | ||
] | ||
], | ||
align : "center", | ||
borderColor : null, | ||
borderStyle : 1, | ||
color : false, | ||
compact : false, | ||
defaultErrorValue : "[32m[37m[41m ERROR! [49m[32m[39m", | ||
defaultValue : "[32m[37m[41m ? [49m[32m[39m", | ||
errorOnNull : false, | ||
footerAlign : "center", | ||
footerColor : false, | ||
formatter : null, | ||
headerAlign : "center", | ||
headerColor : "yellow", | ||
marginLeft : 2, | ||
marginTop : 1, | ||
paddingBottom : 0, | ||
paddingLeft : 1, | ||
paddingRight : 1, | ||
paddingTop : 0, | ||
tableType : null, | ||
truncate: false, | ||
width : "auto", | ||
GUTTER : 1, //undocumented | ||
columnSettings : [], | ||
headerEmpty : false, | ||
//save so cell options can be merged into column options | ||
table : { | ||
body : '', | ||
columnInnerWidths : [], | ||
columnWidths : [], | ||
columns : [], | ||
footer : '', | ||
header : '', //post-rendered strings. | ||
height : 0, | ||
typeLocked : false //once a table type is selected can't switch | ||
} | ||
align : "center", | ||
borderColor : null, | ||
borderStyle : 1, | ||
color : false, | ||
compact : false, | ||
defaultErrorValue : "[32m[37m[41m ERROR! [49m[32m[39m", | ||
defaultValue : "[32m[37m[41m ? [49m[32m[39m", | ||
errorOnNull : false, | ||
footerAlign : "center", | ||
footerColor : false, | ||
formatter : null, | ||
headerAlign : "center", | ||
headerColor : "yellow", | ||
marginLeft : 2, | ||
marginTop : 1, | ||
paddingBottom : 0, | ||
paddingLeft : 1, | ||
paddingRight : 1, | ||
paddingTop : 0, | ||
tableType : null, | ||
truncate: false, | ||
width : "auto", | ||
GUTTER : 1, //undocumented | ||
columnSettings : [], | ||
headerEmpty : false, | ||
//save so cell options can be merged into column options | ||
table : { | ||
body : '', | ||
columnInnerWidths : [], | ||
columnWidths : [], | ||
columns : [], | ||
footer : '', | ||
header : '', //post-rendered strings. | ||
height : 0, | ||
typeLocked : false //once a table type is selected can't switch | ||
} | ||
}; | ||
module.exports = Config; |
@@ -68,3 +68,3 @@ let StripAnsi = require("strip-ansi"); | ||
config.GUTTER; | ||
switch(true){ | ||
@@ -71,0 +71,0 @@ //no wrap, truncate |
@@ -5,7 +5,7 @@ require('use-strict'); | ||
//called directly in terminal | ||
require('./terminal-adapter.js'); | ||
require('./../adapters/terminal-adapter.js'); | ||
} | ||
else{ | ||
//called as a module | ||
module.exports = require('./default-adapter.js'); | ||
module.exports = require('./../adapters/default-adapter.js'); | ||
} |
@@ -29,6 +29,10 @@ let Merge = require("merge"); | ||
if(!global.columnWidths){ | ||
global.columnWidths = config.table.columnWidths = Format.getColumnWidths(config,data); | ||
global.columnWidths = {}; | ||
} | ||
if(global.columnWidths[config.tableId]){ | ||
config.table.columnWidths = global.columnWidths[config.tableId]; | ||
} | ||
else{ | ||
config.table.columnWidths = global.columnWidths; | ||
global.columnWidths[config.tableId] = config.table.columnWidths = Format.getColumnWidths(config,data); | ||
} | ||
@@ -124,11 +128,7 @@ | ||
output += borders[2]; | ||
//remove all rows in prototype array | ||
this.splice(0,this.length); | ||
let finalOutput = Array(config.marginTop + 1).join('\n') + output; | ||
//record the height of the output | ||
this.height = finalOutput.split(/\r\n|\r|\n/).length; | ||
config.height = finalOutput.split(/\r\n|\r|\n/).length; | ||
return finalOutput; | ||
@@ -138,3 +138,3 @@ }; | ||
const buildRow = function(config,row,rowType){ | ||
let minRowHeight = 0; | ||
@@ -207,3 +207,3 @@ | ||
}); | ||
return lines; | ||
@@ -213,4 +213,5 @@ } | ||
Render.buildCell = function(config,cell,columnIndex,rowType){ | ||
let cellValue, | ||
cellOptions = Merge(true,config, | ||
let cellValue; | ||
let cellOptions = Merge(true,{},config, | ||
(rowType === 'body') ? | ||
@@ -217,0 +218,0 @@ config.columnSettings[columnIndex] : {}, //ignore columnSettings for footer |
@@ -24,29 +24,18 @@ | ||
┌──────┬─────────────────────┬─────────────────────────┬─────────────────┐ | ||
│ v0.1 │ Testing something │ rauchg@gmail.com │ 7 minutes ago │ | ||
│ │ cool │ │ │ | ||
└──────┴─────────────────────┴─────────────────────────┴─────────────────┘ | ||
┌──────┬────────────────────────┬──────────────────┬───────────────┐ | ||
│ v0.1 │ Testing something cool │ rauchg@gmail.com │ 7 minutes ago │ | ||
└──────┴────────────────────────┴──────────────────┴───────────────┘ | ||
┌──────┬─────────────────────┬─────────────────────────┬─────────────────┐ | ||
│[32m Some [39m│ Some Value │[32m[37m[41m ? [49m[32m[39m│[32m[37m[41m ? [49m[32m[39m│ | ||
│[32m Key [39m│ │ │ │ | ||
├──────┼─────────────────────┼─────────────────────────┼─────────────────┤ | ||
│[32m Anot [39m│ And its │[32m[37m[41m ? [49m[32m[39m│[32m[37m[41m ? [49m[32m[39m│ | ||
│[32m her [39m│ corresponding │ │ │ | ||
│[32m much [39m│ longer value │ │ │ | ||
│[32m long [39m│ │ │ │ | ||
│[32m er [39m│ │ │ │ | ||
│[32m key [39m│ │ │ │ | ||
└──────┴─────────────────────┴─────────────────────────┴─────────────────┘ | ||
┌─────────────────────────┬────────────────────────────────────┐ | ||
│[32m Some Key [39m│ Some Value │ | ||
├─────────────────────────┼────────────────────────────────────┤ | ||
│[32m Another much longer key [39m│ And its corresponding longer value │ | ||
└─────────────────────────┴────────────────────────────────────┘ | ||
┌──────┬─────────────────────┬─────────────────────────┬─────────────────┐ | ||
│ │[33m Header #1 [39m│[33m Header #2 [39m│ │ | ||
├──────┼─────────────────────┼─────────────────────────┼─────────────────┤ | ||
│[33m Head [39m│ Value 1 │ Value 2 │[32m[37m[41m ? [49m[32m[39m│ | ||
│[33m er [39m│ │ │ │ | ||
│[33m #3 [39m│ │ │ │ | ||
├──────┼─────────────────────┼─────────────────────────┼─────────────────┤ | ||
│[33m Head [39m│ Value 3 │ Value 4 │[32m[37m[41m ? [49m[32m[39m│ | ||
│[33m er [39m│ │ │ │ | ||
│[33m #4 [39m│ │ │ │ | ||
└──────┴─────────────────────┴─────────────────────────┴─────────────────┘ | ||
┌───────────┬───────────┬───────────┐ | ||
│ │[33m Header #1 [39m│[33m Header #2 [39m│ | ||
├───────────┼───────────┼───────────┤ | ||
│[33m Header #3 [39m│ Value 1 │ Value 2 │ | ||
├───────────┼───────────┼───────────┤ | ||
│[33m Header #4 [39m│ Value 3 │ Value 4 │ | ||
└───────────┴───────────┴───────────┘ |
@@ -40,8 +40,8 @@ | ||
┌──────────────────────────────┬──────────┬───────────────┐ | ||
│[33m name [39m│[33m price [39m│ │ | ||
├──────────────────────────────┼──────────┼───────────────┤ | ||
│ apple [31mmac [39m│ 92.5 │[32m[37m[41m ? [49m[32m[39m│ | ||
├──────────────────────────────┼──────────┼───────────────┤ | ||
│ ibm │ 120.15 │[32m[37m[41m ? [49m[32m[39m│ | ||
└──────────────────────────────┴──────────┴───────────────┘ | ||
┌──────────────────────────────┬──────────────────────────────┐ | ||
│[33m name [39m│[33m price [39m│ | ||
├──────────────────────────────┼──────────────────────────────┤ | ||
│ apple [31mmac [39m│ 92.5 │ | ||
├──────────────────────────────┼──────────────────────────────┤ | ||
│ ibm │ 120.15 │ | ||
└──────────────────────────────┴──────────────────────────────┘ |
@@ -20,11 +20,12 @@ | ||
+---------------------------+------+-----+ | ||
|[33m 项目 [39m|[33m 价 [39m|[33m 有 [39m| | ||
| |[33m 格 [39m|[33m 机 [39m| | ||
+---------------------------+------+-----+ | ||
|[37m abc [39m|[37m[32m[37m[41m ? [49m[32m[37m[39m|[37m[32m[37m[41m ? [49m[32m[37m[39m| | ||
+---------------------------+------+-----+ | ||
|[37m abć [39m|[37m[32m[37m[41m ? [49m[32m[37m[39m|[37m[32m[37m[41m ? [49m[32m[37m[39m| | ||
+---------------------------+------+-----+ | ||
|[37m ab한 [39m|[37m[32m[37m[41m ? [49m[32m[37m[39m|[37m[32m[37m[41m ? [49m[32m[37m[39m| | ||
+---------------------------+------+-----+ | ||
+-------+--------+--------+ | ||
|[33m 项 [39m|[33m 价格 [39m|[33m 有机 [39m| | ||
|[33m 目 [39m| | | | ||
+-------+--------+--------+ | ||
|[37m abc [39m|[37m[32m[37m[41m ? [49m[32m[37m[39m|[37m[32m[37m[41m ? [49m[32m[37m[39m| | ||
+-------+--------+--------+ | ||
|[37m abć [39m|[37m[32m[37m[41m ? [49m[32m[37m[39m|[37m[32m[37m[41m ? [49m[32m[37m[39m| | ||
+-------+--------+--------+ | ||
|[37m ab [39m|[37m[32m[37m[41m ? [49m[32m[37m[39m|[37m[32m[37m[41m ? [49m[32m[37m[39m| | ||
|[37m 한 [39m| | | | ||
+-------+--------+--------+ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
1162449
50
19257
24