Comparing version 2.8.10 to 2.8.11
{ | ||
"name": "tty-table", | ||
"version": "2.8.10", | ||
"version": "2.8.11", | ||
"description": "Node cli table", | ||
@@ -5,0 +5,0 @@ "main": "src/main.js", |
@@ -44,3 +44,3 @@ const defaults = { | ||
paddingTop: 0, | ||
tableType: null, | ||
showHeader: null, // undocumented | ||
truncate: false, | ||
@@ -50,3 +50,2 @@ width: "auto", | ||
columnSettings: [], | ||
headerEmpty: false, | ||
// save so cell options can be merged into column options | ||
@@ -53,0 +52,0 @@ table: { |
@@ -144,3 +144,2 @@ const defaults = require("./defaults.js") | ||
config.table.header = header | ||
config.headerEmpty = (header.length === 0) ? true : false | ||
@@ -147,0 +146,0 @@ // match header geometry with body array |
@@ -18,11 +18,9 @@ const Style = require("./style.js") | ||
// because automattic/cli-table syntax infers table type based on | ||
// how rows are passed (array of arrays, objects, etc) | ||
config.rowFormat = exports.getRowFormat(inputData[0] || [], config) | ||
// support backwards compatibility cli-table's multiple constructor geometries | ||
// @TODO deprecate and support only a single format | ||
const constructorType = exports.getConstructorGeometry(inputData[0] || [], config) | ||
const rows = exports.coerceConstructor(config, inputData, constructorType) | ||
// now translate them | ||
const rowData = exports.transformRows(config, inputData) | ||
// when streaming values to tty-table, we don't want column widths to change | ||
// from one rowData set to the next, so we save the first set of widths and reuse | ||
// from one rows set to the next, so we save the first set of widths and reuse | ||
if(!global.columnWidths) { | ||
@@ -35,17 +33,26 @@ global.columnWidths = {} | ||
} else { | ||
global.columnWidths[config.tableId] = config.table.columnWidths = Format.getColumnWidths(config, rowData) | ||
global.columnWidths[config.tableId] = config.table.columnWidths = Format.getColumnWidths(config, rows) | ||
} | ||
// stringify header cells | ||
if(!config.headerEmpty) { | ||
sections.header = config.table.header.map(row => { | ||
return exports.buildRow(config, row, "header", null, rowData, inputData) | ||
}) | ||
} else { | ||
sections.header = [] | ||
// hide header if no column names or if specified in config | ||
switch (true) { | ||
case (config.showHeader !== null && !config.showHeader): // explicitly false, hide | ||
sections.header = [] | ||
break | ||
case (config.showHeader === true): // explicitly true, show | ||
case (!!config.table.header[0].find(obj => obj.value)): // atleast one named column, show | ||
sections.header = config.table.header.map(row => { | ||
return exports.buildRow(config, row, "header", null, rows, inputData) | ||
}) | ||
break | ||
default: // no named columns, hide | ||
sections.header = [] | ||
} | ||
// stringify body cells | ||
sections.body = rowData.map((row, rowIndex) => { | ||
return exports.buildRow(config, row, "body", rowIndex, rowData, inputData) | ||
sections.body = rows.map((row, rowIndex) => { | ||
return exports.buildRow(config, row, "body", rowIndex, rows, inputData) | ||
}) | ||
@@ -57,3 +64,3 @@ | ||
sections.footer = sections.footer.map(row => { | ||
return exports.buildRow(config, row, "footer", null, rowData, inputData) | ||
return exports.buildRow(config, row, "footer", null, rows, inputData) | ||
}) | ||
@@ -271,3 +278,6 @@ | ||
module.exports.getRowFormat = (row, config) => { | ||
/** | ||
* Check for a backwards compatible (cli-table) constructor | ||
*/ | ||
module.exports.getConstructorGeometry = (row, config) => { | ||
let type | ||
@@ -302,29 +312,9 @@ | ||
// @todo For rotating horizontal data into a vertical table | ||
// assumes all rows are same length | ||
module.exports.verticalizeMatrix = (config, inputArray) => { | ||
// grow to # arrays equal to number of columns in input array | ||
let outputArray = [] | ||
let headers = config.table.columns | ||
// create a row for each heading, and prepend the row | ||
// with the heading name | ||
headers.forEach(name => outputArray.push([name])) | ||
inputArray.forEach(row => { | ||
row.forEach((element, index) => outputArray[index].push(element)) | ||
}) | ||
return outputArray | ||
} | ||
/** | ||
* Transforms input data arrays to base rendering structure. | ||
* Coerce backwards compatible constructor styles | ||
*/ | ||
module.exports.transformRows = (config, rows) => { | ||
module.exports.coerceConstructor = (config, rows, constructorType) => { | ||
let output = [] | ||
switch(config.rowFormat) { | ||
switch(constructorType) { | ||
case("automattic-cross"): | ||
@@ -376,1 +366,21 @@ // assign header styles to first column | ||
} | ||
// @TODO For rotating horizontal data into a vertical table | ||
// assumes all rows are same length | ||
module.exports.verticalizeMatrix = (config, inputArray) => { | ||
// grow to # arrays equal to number of columns in input array | ||
let outputArray = [] | ||
let headers = config.table.columns | ||
// create a row for each heading, and prepend the row | ||
// with the heading name | ||
headers.forEach(name => outputArray.push([name])) | ||
inputArray.forEach(row => { | ||
row.forEach((element, index) => outputArray[index].push(element)) | ||
}) | ||
return outputArray | ||
} |
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
42624
945