Comparing version 2.8.4 to 2.8.5
@@ -22,3 +22,3 @@ var Factory = require("../src/factory.js") | ||
if(options.colWidths) { | ||
options.colWidths.forEach(function(val,i) { | ||
options.colWidths.forEach(function(val, i) { | ||
header[i].width = val | ||
@@ -30,3 +30,3 @@ }) | ||
if(options.colAligns) { | ||
options.colAligns.forEach(function(val,i) { | ||
options.colAligns.forEach(function(val, i) { | ||
header[i].align = val | ||
@@ -66,3 +66,3 @@ header[i].headerAlign = val | ||
//inherited from prototype | ||
let t = Factory(header,[],[],options) | ||
let t = Factory(header, [], [], options) | ||
t.toString = t.render | ||
@@ -69,0 +69,0 @@ return t |
@@ -10,7 +10,7 @@ #!/usr/bin/env node | ||
Yargs.option("config",{ | ||
Yargs.option("config", { | ||
describe: "Specify the configuration for your table." | ||
}) | ||
Yargs.option("csv-delimiter",{ | ||
Yargs.option("csv-delimiter", { | ||
describe: "Set the field delimiter. One character only.", | ||
@@ -20,7 +20,7 @@ default: "," | ||
Yargs.option("csv-escape",{ | ||
Yargs.option("csv-escape", { | ||
describe: "Set the escape character. One character only." | ||
}) | ||
Yargs.option("csv-rowDelimiter",{ | ||
Yargs.option("csv-rowDelimiter", { | ||
describe: "String used to delimit record rows. You can also use a special constant: \"auto\",\"unix\",\"max\",\"windows\",\"unicode\".", | ||
@@ -30,9 +30,9 @@ default: "\n" | ||
Yargs.option("format",{ | ||
Yargs.option("format", { | ||
describe: "Set input data format", | ||
choices: ["json","csv"], | ||
choices: ["json", "csv"], | ||
default: "csv" | ||
}) | ||
Yargs.option("options\u2010\u002A",{ | ||
Yargs.option("options\u2010\u002A", { | ||
describe: "Specify an optional setting where * is the setting name. See README.md for a complete list." | ||
@@ -44,3 +44,3 @@ }) | ||
let emitError = function(type,detail) { | ||
let emitError = function(type, detail) { | ||
console.log(`\n${ Chalk.bgRed.white(type) }\n\n${ Chalk.bold(detail)}`) | ||
@@ -87,3 +87,3 @@ process.exit(1) | ||
//because different dataFormats | ||
let runTable = function(header,body) { | ||
let runTable = function(header, body) { | ||
@@ -93,3 +93,3 @@ //footer = [], | ||
options.terminalAdapter = true | ||
let t1 = Table(header, body,options) | ||
let t1 = Table(header, body, options) | ||
@@ -136,3 +136,3 @@ //hide cursor | ||
} | ||
runTable(header,data) | ||
runTable(header, data) | ||
break | ||
@@ -142,3 +142,3 @@ default: | ||
Object.keys(Yargs).forEach(function(key) { | ||
if(key.slice(0,4) === "csv-" && typeof(Yargs[key]) !== "undefined") { | ||
if(key.slice(0, 4) === "csv-" && typeof(Yargs[key]) !== "undefined") { | ||
formatterOptions[key.slice(4)] = Yargs[key] | ||
@@ -148,3 +148,3 @@ } | ||
Csv.parse(chunk,formatterOptions,function(err, data) { | ||
Csv.parse(chunk, formatterOptions, function(err, data) { | ||
//validate csv | ||
@@ -157,3 +157,3 @@ if(typeof data === "undefined") { | ||
} | ||
runTable(header,data) | ||
runTable(header, data) | ||
}) | ||
@@ -160,0 +160,0 @@ } |
{ | ||
"name": "tty-table", | ||
"version": "2.8.4", | ||
"version": "2.8.5", | ||
"description": "Node cli table", | ||
@@ -12,3 +12,7 @@ "main": "src/main.js", | ||
}, | ||
"files": ["adapters/", "src/", "LICENSE.txt"], | ||
"files": [ | ||
"adapters/", | ||
"src/", | ||
"LICENSE" | ||
], | ||
"preferGlobal": false, | ||
@@ -22,4 +26,4 @@ "scripts": { | ||
"lint-fix": "npx eslint adapters/* src/* --fix", | ||
"lint-examples": "npx eslint adapters/* examples/*", | ||
"lint-examples-fix": "npx eslint adapters/* examples/* --fix" | ||
"lint-examples": "npx eslint examples/", | ||
"lint-examples-fix": "npx eslint examples/ --fix" | ||
}, | ||
@@ -48,7 +52,7 @@ "repository": { | ||
"chalk": "^2.4.2", | ||
"csv": "^5.1.3", | ||
"smartwrap": "^1.2.0", | ||
"csv": "^5.3.1", | ||
"smartwrap": "^1.2.1", | ||
"strip-ansi": "^5.2.0", | ||
"wcwidth": "^1.0.1", | ||
"yargs": "^13.2.4" | ||
"yargs": "^13.3.0" | ||
}, | ||
@@ -55,0 +59,0 @@ "devDependencies": { |
@@ -15,19 +15,19 @@ # tty-table 电传打字台 | ||
- [tty-table 电传打字台](#tty-table-%E7%94%B5%E4%BC%A0%E6%89%93%E5%AD%97%E5%8F%B0) | ||
- [Examples](#examples) | ||
- [Terminal (Static)](#terminal-static) | ||
- [Terminal (Streaming)](#terminal-streaming) | ||
- [Browser & Browser Console](#browser--browser-console) | ||
- [API Reference](#api-reference) | ||
- [Table(header ```array```, rows ```array```, options ```object```)](#tableheader-array-rows-array-options-object) | ||
- [header <code>array of objects</code>](#header-codearray-of-objectscode) | ||
- [rows <code>array</code>](#rows-codearraycode) | ||
- [options <code>object</code>](#options-codeobjectcode) | ||
- [Table.render() ⇒ <code>String</code>](#tablerender-%E2%87%92-codestringcode) | ||
- [Installation](#installation) | ||
- [Running tests](#running-tests) | ||
- [Saving the output of new unit tests](#saving-the-output-of-new-unit-tests) | ||
- [Dev Tips](#dev-tips) | ||
- [Packaging as a distributable](#packaging-as-a-distributable) | ||
- [License](#license) | ||
- [Examples](#examples) | ||
- [Terminal (Static)](#terminal-static) | ||
- [Terminal (Streaming)](#terminal-streaming) | ||
- [Browser & Browser Console](#browser--browser-console) | ||
- [API Reference](#api-reference) | ||
- [Table(header ```array```, rows ```array```, options ```object```)](#tableheader-array-rows-array-options-object) | ||
- [header <code>array of objects</code>](#header-codearray-of-objectscode) | ||
- [rows <code>array</code>](#rows-codearraycode) | ||
- [footer <code>array</code>](#footer-codearraycode) | ||
- [options <code>object</code>](#options-codeobjectcode) | ||
- [Table.render() ⇒ <code>String</code>](#tablerender-%E2%87%92-codestringcode) | ||
- [Installation](#installation) | ||
- [Running tests](#running-tests) | ||
- [Saving the output of new unit tests](#saving-the-output-of-new-unit-tests) | ||
- [Dev Tips](#dev-tips) | ||
- [Packaging as a distributable](#packaging-as-a-distributable) | ||
- [License](#license) | ||
@@ -94,3 +94,3 @@ <!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
#### header <code>array of objects</code> | ||
#### header ```array of objects``` | ||
@@ -118,2 +118,3 @@ | Param | Type | Description | | ||
**Example** | ||
```js | ||
@@ -145,3 +146,2 @@ let header = [ | ||
<br/> | ||
@@ -151,3 +151,3 @@ <br/> | ||
#### rows <code>array</code> | ||
#### rows ```array``` | ||
@@ -174,5 +174,30 @@ **Example** | ||
<br/> | ||
<a name="footer_example"></a> | ||
#### footer ```array``` | ||
- Footer is optional | ||
**Example** | ||
```js | ||
const footer = [ | ||
"TOTAL", | ||
(cellValue, columnIndex, rowIndex, rowData, inputData) => { | ||
return rowData.reduce((prev, curr) => { | ||
return prev + curr[1] | ||
}, 0) | ||
}, | ||
(cellValue, columnIndex, rowIndex, rowData, inputData) => { | ||
let total = rowData.reduce((prev, curr) => { | ||
return prev + ((curr[2] === "yes") ? 1 : 0) | ||
}, 0) | ||
return `${ (total / rowData.length * 100).toFixed(2) }%` | ||
} | ||
] | ||
``` | ||
<br/> | ||
<br/> | ||
<a name="options_properties"></a> | ||
#### options <code>object</code> | ||
#### options ```object``` | ||
@@ -248,3 +273,3 @@ | Param | Type | Description | | ||
```sh | ||
$ npx grunt test | ||
$ npm test | ||
``` | ||
@@ -255,3 +280,3 @@ | ||
```sh | ||
$ npx grunt st | ||
$ npm run test-save | ||
``` | ||
@@ -283,2 +308,2 @@ - Because: | ||
Copyright 2015-2019, Tecfu. | ||
Copyright 2015-2020, Tecfu. |
@@ -175,3 +175,3 @@ const Defaults = require("./defaults.js") | ||
//return Render.stringifyData(configCopy,this.slice(0)); //get string output | ||
let output = Render.stringifyData(this[_configKey],this.slice(0)) //get string output | ||
let output = Render.stringifyData(this[_configKey], this.slice(0)) //get string output | ||
tableObject.height = this[_configKey].height | ||
@@ -178,0 +178,0 @@ return output |
@@ -29,3 +29,3 @@ const StripAnsi = require("strip-ansi") | ||
//remove ANSI start-of-line chars | ||
string = string.replace(startAnsiRegexp,"") | ||
string = string.replace(startAnsiRegexp, "") | ||
@@ -39,3 +39,3 @@ //ANSI chararacters that demarcate the end of a line | ||
//remove ANSI end-of-line chars | ||
string = string.replace(endAnsiRegexp,"") | ||
string = string.replace(endAnsiRegexp, "") | ||
@@ -59,3 +59,3 @@ let alignTgt | ||
cellOptions.paddingLeft = cellOptions.paddingRight = | ||
Math.max(cellOptions.paddingRight,cellOptions.paddingLeft,0) | ||
Math.max(cellOptions.paddingRight, cellOptions.paddingLeft, 0) | ||
} | ||
@@ -95,3 +95,3 @@ | ||
default: | ||
string = Format.handleNonWideChars(string,cellOptions,innerWidth) | ||
string = Format.handleNonWideChars(string, cellOptions, innerWidth) | ||
} | ||
@@ -145,3 +145,3 @@ | ||
Format.handleTruncatedValue = function(string,cellOptions,maxWidth) { | ||
Format.handleTruncatedValue = function(string, cellOptions, maxWidth) { | ||
const stringWidth = Wcwidth(string) | ||
@@ -159,3 +159,3 @@ if(maxWidth < stringWidth) { | ||
Format.handleWideChars = function(string,cellOptions,innerWidth) { | ||
Format.handleWideChars = function(string, cellOptions, innerWidth) { | ||
let count = 0 | ||
@@ -180,4 +180,4 @@ let start = 0 | ||
Format.handleNonWideChars = function(string,cellOptions,innerWidth) { | ||
let outstring = Smartwrap(string,{ | ||
Format.handleNonWideChars = function(string, cellOptions, innerWidth) { | ||
let outstring = Smartwrap(string, { | ||
width: innerWidth, | ||
@@ -199,3 +199,3 @@ trim: true//, | ||
*/ | ||
Format.inferColumnWidth = function(columnOptions,rows,columnIndex) { | ||
Format.inferColumnWidth = function(columnOptions, rows, columnIndex) { | ||
@@ -225,3 +225,3 @@ let iterable | ||
Format.getColumnWidths = function(config,rows) { | ||
Format.getColumnWidths = function(config, rows) { | ||
@@ -233,3 +233,3 @@ //iterate over the header if we have it, iterate over the first row | ||
let widths = iterable.map(function(column,columnIndex) { //iterate through column settings | ||
let widths = iterable.map(function(column, columnIndex) { //iterate through column settings | ||
let result | ||
@@ -250,3 +250,3 @@ switch(true) { | ||
let measurableRows = (rows.length) ? rows : config.table.header[0] | ||
result = Format.inferColumnWidth(columnOptions,measurableRows,columnIndex) | ||
result = Format.inferColumnWidth(columnOptions, measurableRows, columnIndex) | ||
@@ -263,3 +263,3 @@ //add spaces for padding if not centered | ||
//calculate sum of all column widths (including marginLeft) | ||
let totalWidth = widths.reduce(function(prev,curr) { | ||
let totalWidth = widths.reduce(function(prev, curr) { | ||
return prev + curr | ||
@@ -266,0 +266,0 @@ }) |
@@ -8,3 +8,3 @@ const Style = require("./style.js") | ||
*/ | ||
Render.stringifyData = function(config,inputData) { | ||
Render.stringifyData = function(config, inputData) { | ||
const sections = { | ||
@@ -21,6 +21,6 @@ header: [], | ||
//how rows are passed (array of arrays, objects, etc) | ||
config.rowFormat = Render.getRowFormat(inputData[0] || [],config) | ||
config.rowFormat = Render.getRowFormat(inputData[0] || [], config) | ||
//now translate them | ||
const rowData = Render.transformRows(config,inputData) | ||
const rowData = Render.transformRows(config, inputData) | ||
@@ -36,3 +36,3 @@ //when streaming values to tty-table, we don't want column widths to change | ||
} else{ | ||
global.columnWidths[config.tableId] = config.table.columnWidths = Format.getColumnWidths(config,rowData) | ||
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",null,rowData,inputData) | ||
return buildRow(config, row, "header", null, rowData, inputData) | ||
}) | ||
@@ -52,3 +52,3 @@ } else{ | ||
sections.body = rowData.map(function(row, rowIndex) { | ||
return buildRow(config,row,"body",rowIndex,rowData,inputData) | ||
return buildRow(config, row, "body", rowIndex, rowData, inputData) | ||
}) | ||
@@ -60,3 +60,3 @@ | ||
sections.footer = sections.footer.map(function(row) { | ||
return buildRow(config,row,"footer",null,rowData,inputData) | ||
return buildRow(config, row, "footer", null, rowData, inputData) | ||
}) | ||
@@ -68,3 +68,3 @@ | ||
borders.push("") | ||
config.table.columnWidths.forEach(function(w,i,arr) { | ||
config.table.columnWidths.forEach(function(w, i, arr) { | ||
borders[a] += Array(w).join(borderStyle[a].h) + | ||
@@ -86,3 +86,3 @@ ((i+1 !== arr.length) ? borderStyle[a].j : borderStyle[a].r) | ||
//for each section (header,body,footer) | ||
Object.keys(sections).forEach(function(p,i) { | ||
Object.keys(sections).forEach(function(p, i) { | ||
@@ -143,3 +143,3 @@ //for each row in the section | ||
const buildRow = function(config,row,rowType,rowIndex,rowData,inputData) { | ||
const buildRow = function(config, row, rowType, rowIndex, rowData, inputData) { | ||
@@ -175,3 +175,3 @@ let minRowHeight = 0 | ||
let c = Render.buildCell(config,row[index],index,rowType,rowIndex,rowData,inputData) | ||
let c = Render.buildCell(config, row[index], index, rowType, rowIndex, rowData, inputData) | ||
let cellArr = c.cellArr | ||
@@ -194,8 +194,8 @@ | ||
//convert array of cell arrays to array of lines | ||
let lines = Array.apply(null,{length: minRowHeight}) | ||
.map(Function.call,function() { | ||
let lines = Array.apply(null, {length: minRowHeight}) | ||
.map(Function.call, function() { | ||
return [] | ||
}) | ||
cArrs.forEach(function(cellArr,a) { | ||
cArrs.forEach(function(cellArr, a) { | ||
let whiteline = Array(config.table.columnWidths[a]).join(" ") | ||
@@ -223,3 +223,3 @@ | ||
Render.buildCell = function(config,cell,columnIndex,rowType,rowIndex,rowData,inputData) { | ||
Render.buildCell = function(config, cell, columnIndex, rowType, rowIndex, rowData, inputData) { | ||
@@ -248,3 +248,3 @@ let cellValue | ||
case(typeof cell === "function"): | ||
cellValue = cell(cellValue,columnIndex,rowIndex,rowData,inputData) | ||
cellValue = cell(cellValue, columnIndex, rowIndex, rowData, inputData) | ||
break | ||
@@ -258,3 +258,3 @@ default: | ||
if(typeof cellOptions.formatter === "function") { | ||
cellValue = cellOptions.formatter(cellValue,columnIndex,rowIndex,rowData,inputData) | ||
cellValue = cellOptions.formatter(cellValue, columnIndex, rowIndex, rowData, inputData) | ||
} | ||
@@ -264,3 +264,3 @@ } | ||
//colorize cellValue | ||
cellValue = Style.colorizeCell(cellValue,cellOptions,rowType) | ||
cellValue = Style.colorizeCell(cellValue, cellOptions, rowType) | ||
@@ -278,3 +278,3 @@ //textwrap cellValue | ||
Render.getRowFormat = function(row,config) { | ||
Render.getRowFormat = function(row, config) { | ||
let type | ||
@@ -308,3 +308,3 @@ | ||
//assumes all rows are same length | ||
Render.verticalizeMatrix = function(config,inputArray) { | ||
Render.verticalizeMatrix = function(config, inputArray) { | ||
@@ -322,3 +322,3 @@ //grow to # arrays equal to number of columns in input array | ||
inputArray.forEach(function(row) { | ||
row.forEach(function(element,index) { | ||
row.forEach(function(element, index) { | ||
outputArray[index].push(element) | ||
@@ -334,3 +334,3 @@ }) | ||
*/ | ||
Render.transformRows = function(config,rows) { | ||
Render.transformRows = function(config, rows) { | ||
@@ -358,3 +358,3 @@ let output = [] | ||
let key = Object.keys(value)[0] | ||
return [key,value[key]] | ||
return [key, value[key]] | ||
}) | ||
@@ -361,0 +361,0 @@ break |
const Chalk = require("chalk") | ||
exports.colorizeCell = function(str,cellOptions,rowType) { | ||
exports.colorizeCell = function(str, cellOptions, rowType) { | ||
@@ -5,0 +5,0 @@ let color = false //false will keep terminal default |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
44017
301
0
Updatedcsv@^5.3.1
Updatedsmartwrap@^1.2.1
Updatedyargs@^13.3.0