Comparing version 2.4.1 to 2.4.2
@@ -147,3 +147,3 @@ /** | ||
example1 = example1.replace('../','tty-table'); | ||
example1 = '\n```\n' + example1 + '\n```'; | ||
example1 = '\n```js\n' + example1 + '\n```'; | ||
readme = readme.replace(/<!--EXAMPLE-USAGE-->((?:.|[\r\n])*)<!--END-EXAMPLE-USAGE-->/m, | ||
@@ -150,0 +150,0 @@ '<!--EXAMPLE-USAGE-->\n'+example1+'\n<!--END-EXAMPLE-USAGE-->'); |
{ | ||
"name": "tty-table", | ||
"version": "2.4.1", | ||
"version": "2.4.2", | ||
"description": "Command line table generator.", | ||
@@ -5,0 +5,0 @@ "main": "src/main.js", |
206
README.md
@@ -11,3 +11,3 @@ # tty-table | ||
``` | ||
```sh | ||
$ sudo apt-get install nodejs | ||
@@ -19,3 +19,3 @@ $ npm install tty-table -g | ||
``` | ||
```sh | ||
npm install tty-table | ||
@@ -87,3 +87,3 @@ ``` | ||
``` | ||
```js | ||
var Table = require('tty-table'); | ||
@@ -93,40 +93,22 @@ var chalk = require('chalk'); | ||
var header = [ | ||
{ | ||
value : "item", | ||
headerColor : "cyan", | ||
color: "white", | ||
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); | ||
} | ||
return str; | ||
} | ||
}, | ||
{ | ||
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); | ||
} | ||
else{ | ||
value = chalk.white.bgRed(value); | ||
} | ||
return value; | ||
} | ||
} | ||
{ | ||
value : "item", | ||
headerColor : "cyan", | ||
color: "white", | ||
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); | ||
} | ||
return str; | ||
} | ||
} | ||
]; | ||
@@ -136,31 +118,27 @@ | ||
var rows = [ | ||
["hamburger",2.50,"no"], | ||
["el jefe's special cream sauce",0.10,"yes"], | ||
["two tacos, rice and beans topped with cheddar cheese",9.80,"no"], | ||
["apple slices",1.00,"yes"], | ||
["ham sandwich",1.50,"no"], | ||
["macaroni, ham and peruvian mozzarella",3.75,"no"] | ||
["hamburger",2.50,"no"], | ||
["el jefe's special cream sauce",0.10,"yes"], | ||
]; | ||
var footer = [ | ||
"TOTAL", | ||
(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) + "%"; | ||
}())]; | ||
"TOTAL", | ||
(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) + "%"; | ||
}())]; | ||
var t1 = Table(header,rows,footer,{ | ||
borderStyle : 1, | ||
borderColor : "blue", | ||
paddingBottom : 0, | ||
headerAlign : "center", | ||
align : "center", | ||
color : "white" | ||
borderStyle : 1, | ||
borderColor : "blue", | ||
paddingBottom : 0, | ||
headerAlign : "center", | ||
align : "center", | ||
color : "white" | ||
}); | ||
@@ -174,40 +152,20 @@ | ||
var rows = [ | ||
{ | ||
item : "hamburger", | ||
price : 2.50, | ||
organic : "no" | ||
}, | ||
{ | ||
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 : "apple slices", | ||
price : 1.00, | ||
organic : "yes" | ||
}, | ||
{ | ||
item : "ham sandwich", | ||
price : 1.50, | ||
organic : "no" | ||
}, | ||
{ | ||
item : "macaroni, ham and peruvian mozzarella", | ||
price : 3.75, | ||
organic : "no" | ||
} | ||
{ | ||
item : "hamburger", | ||
price : 2.50, | ||
organic : "no" | ||
}, | ||
{ | ||
item : "el jefe's special cream sauce", | ||
price : 0.10, | ||
organic : "yes" | ||
} | ||
]; | ||
var t2 = Table(header,rows,{ | ||
borderStyle : 1, | ||
paddingBottom : 0, | ||
headerAlign : "center", | ||
align : "center", | ||
color : "white" | ||
borderStyle : 1, | ||
paddingBottom : 0, | ||
headerAlign : "center", | ||
align : "center", | ||
color : "white" | ||
}); | ||
@@ -230,20 +188,20 @@ | ||
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: "+"} | ||
] | ||
] | ||
```js | ||
[ | ||
[ | ||
{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: "+"} | ||
] | ||
] | ||
``` | ||
@@ -290,3 +248,3 @@ | ||
**Example** | ||
``` | ||
```js | ||
var Table = require('tty-table'); | ||
@@ -303,3 +261,3 @@ var t1 = Table(header,rows,options); | ||
**Example** | ||
``` | ||
```js | ||
var str = t1.render(); | ||
@@ -313,3 +271,3 @@ console.log(str); //outputs table | ||
``` | ||
```sh | ||
grunt test | ||
@@ -320,3 +278,3 @@ ``` | ||
``` | ||
```sh | ||
grunt st | ||
@@ -332,3 +290,3 @@ ``` | ||
``` | ||
```sh | ||
grunt tags | ||
@@ -339,3 +297,3 @@ ``` | ||
``` | ||
```sh | ||
grunt watch | ||
@@ -342,0 +300,0 @@ ``` |
#!/usr/bin/env node | ||
var yargs = require('yargs'); | ||
yargs.epilog('Copyright github.com/tecfu 2017'); | ||
yargs.option('format'); | ||
yargs.describe('format','Set input data format'); | ||
yargs.choices('format',['json','csv']); | ||
yargs.default('format','csv'); | ||
yargs.epilog('Copyight github.com/tecfu 2017'); | ||
yargs.option('csv-delimiter',{ | ||
describe:'Set the field delimiter. One character only.', | ||
default:',' | ||
}); | ||
yargs.option('csv-rowDelimiter',{ | ||
describe:'String used to delimit record rows or a special constant; special constants are "auto","unix","max","windows","unicode".', | ||
default:"'" | ||
}); | ||
yargs.option('escape',{ | ||
describe:'Set the escape character. One character only.', | ||
default:'"' | ||
}); | ||
yargs.option('format',{ | ||
describe:'Set input data format', | ||
choices:['json','csv'], | ||
default:'csv' | ||
}); | ||
yargs.version(function(){ | ||
var fs = require('fs'); | ||
var path =__dirname+'/../package.json'; | ||
var contents = fs.readFileSync(path,'utf-8'); | ||
var json = JSON.parse(contents); | ||
return json.version; | ||
}); | ||
@@ -9,0 +29,0 @@ var Chalk = require('chalk'); |
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
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
19943
1497379
297
25