Comparing version 2.8.5 to 2.8.6
@@ -153,2 +153,3 @@ #!/usr/bin/env node | ||
/* istanbul ignore next */ | ||
if (process.platform === "win32") { | ||
@@ -165,2 +166,3 @@ let rl = require("readline").createInterface({ | ||
/* istanbul ignore next */ | ||
process.on("SIGINT", function () { | ||
@@ -167,0 +169,0 @@ //graceful shutdown |
{ | ||
"name": "tty-table", | ||
"version": "2.8.5", | ||
"version": "2.8.6", | ||
"description": "Node cli table", | ||
@@ -52,5 +52,5 @@ "main": "src/main.js", | ||
"smartwrap": "^1.2.1", | ||
"strip-ansi": "^5.2.0", | ||
"strip-ansi": "^6.0.0", | ||
"wcwidth": "^1.0.1", | ||
"yargs": "^13.3.0" | ||
"yargs": "^15.1.0" | ||
}, | ||
@@ -57,0 +57,0 @@ "devDependencies": { |
@@ -11,26 +11,2 @@ # tty-table 电传打字台 | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
**Table of Contents** | ||
- [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) | ||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
## [Examples](examples/) | ||
@@ -37,0 +13,0 @@ |
@@ -6,3 +6,3 @@ const StripAnsi = require("strip-ansi") | ||
Format.calculateLength = function(line) { | ||
Format.calculateLength = line => { | ||
//return StripAnsi(line.replace(/[^\x00-\xff]/g,'XX')).length; | ||
@@ -12,3 +12,3 @@ return Wcwidth(StripAnsi(line)) | ||
Format.wrapCellContent = function( | ||
Format.wrapCellContent = ( | ||
config, | ||
@@ -19,10 +19,11 @@ cellValue, | ||
rowType | ||
) { | ||
) => { | ||
//ANSI chararacters that demarcate the start/end of a line | ||
const startAnsiRegexp = /^(\033\[[0-9;]*m)+/ | ||
const endAnsiRegexp = /(\033\[[0-9;]*m)+$/ | ||
//coerce cell value to string | ||
let string = cellValue.toString() | ||
//ANSI chararacters that demarcate the start of a line | ||
let startAnsiRegexp = /^(\033\[[0-9;]*m)+/ | ||
//store matching ANSI characters | ||
@@ -34,5 +35,2 @@ let startMatches = string.match(startAnsiRegexp) || [""] | ||
//ANSI chararacters that demarcate the end of a line | ||
let endAnsiRegexp = /(\033\[[0-9;]*m)+$/ | ||
//store matching ANSI characters so can be later re-attached | ||
@@ -64,9 +62,6 @@ let endMatches = string.match(endAnsiRegexp) || [""] | ||
let columnWidth = config.table.columnWidths[columnIndex] | ||
const columnWidth = config.table.columnWidths[columnIndex] | ||
//innerWidth is the width available for text within the cell | ||
let innerWidth = columnWidth - | ||
cellOptions.paddingLeft - | ||
cellOptions.paddingRight - | ||
config.GUTTER | ||
const innerWidth = columnWidth -cellOptions.paddingLeft -cellOptions.paddingRight -config.GUTTER | ||
@@ -76,11 +71,4 @@ switch(true) { | ||
case((typeof config.truncate === "string") || config.truncate === true): | ||
if(config.truncate === true) { | ||
config.truncate = "" | ||
} | ||
string = Format.handleTruncatedValue( | ||
string, | ||
cellOptions, | ||
innerWidth | ||
) | ||
if(config.truncate === true) config.truncate = "" | ||
string = Format.handleTruncatedValue(string, cellOptions, innerWidth) | ||
break | ||
@@ -90,7 +78,3 @@ //string has wide characters | ||
//case(string.length < Format.calculateLength(string)): | ||
string = Format.handleWideChars( | ||
string, | ||
cellOptions, | ||
innerWidth | ||
) | ||
string = Format.handleWideChars(string, cellOptions, innerWidth) | ||
break | ||
@@ -102,11 +86,8 @@ //string does not have wide characters | ||
//break string into array of lines | ||
let strArr = string.split("\n") | ||
//format each line | ||
strArr = strArr.map(function(line) { | ||
let strArr = string.split("\n").map( line => { | ||
line = line.trim() | ||
let lineLength = Format.calculateLength(line) | ||
const lineLength = Format.calculateLength(line) | ||
@@ -121,14 +102,15 @@ //alignment | ||
padRemainder = emptySpace % 2 | ||
line = Array(padBoth + 1).join(" ") + | ||
line + | ||
Array(padBoth + 1 + padRemainder).join(" ") | ||
line = Array(padBoth + 1).join(" ") | ||
+ line | ||
+ Array(padBoth + 1 + padRemainder).join(" ") | ||
break | ||
case(cellOptions[alignTgt] === "right"): | ||
line = Array(emptySpace - cellOptions.paddingRight).join(" ") + | ||
line + | ||
Array(cellOptions.paddingRight + 1).join(" ") | ||
line = Array(emptySpace - cellOptions.paddingRight).join(" ") | ||
+ line | ||
+ Array(cellOptions.paddingRight + 1).join(" ") | ||
break | ||
default: | ||
line = Array(cellOptions.paddingLeft + 1).join(" ") + | ||
line + Array(emptySpace - cellOptions.paddingLeft).join(" ") | ||
line = Array(cellOptions.paddingLeft + 1).join(" ") | ||
+ line | ||
+ Array(emptySpace - cellOptions.paddingLeft).join(" ") | ||
} | ||
@@ -138,6 +120,3 @@ } | ||
//put ANSI color codes BACK on the beginning and end of string | ||
line = startMatches[0] + line | ||
line = line + endMatches[0] | ||
return line | ||
return startMatches[0] + line + endMatches[0] | ||
}) | ||
@@ -151,3 +130,3 @@ | ||
Format.handleTruncatedValue = function(string, cellOptions, maxWidth) { | ||
Format.handleTruncatedValue = (string, cellOptions, maxWidth) => { | ||
const stringWidth = Wcwidth(string) | ||
@@ -165,3 +144,3 @@ if(maxWidth < stringWidth) { | ||
Format.handleWideChars = function(string, cellOptions, innerWidth) { | ||
Format.handleWideChars = (string, cellOptions, innerWidth) => { | ||
let count = 0 | ||
@@ -171,3 +150,3 @@ let start = 0 | ||
let outstring = characters.reduce(function (prev, cellValue, i) { | ||
let outstring = characters.reduce((prev, cellValue, i) => { | ||
count += Format.calculateLength(cellValue) | ||
@@ -187,3 +166,3 @@ if (count > innerWidth) { | ||
Format.handleNonWideChars = function(string, cellOptions, innerWidth) { | ||
Format.handleNonWideChars = (string, cellOptions, innerWidth) => { | ||
let outstring = Smartwrap(string, { | ||
@@ -206,3 +185,3 @@ width: innerWidth, | ||
*/ | ||
Format.inferColumnWidth = function(columnOptions, rows, columnIndex) { | ||
Format.inferColumnWidth = (columnOptions, rows, columnIndex) => { | ||
@@ -223,3 +202,3 @@ let iterable | ||
let widest = 0 | ||
iterable.forEach(function(row) { | ||
iterable.forEach( row => { | ||
if(row[columnIndex] && row[columnIndex].toString().length > widest) { | ||
@@ -233,3 +212,3 @@ //widest = row[columnIndex].toString().length; | ||
Format.getColumnWidths = function(config, rows) { | ||
Format.getColumnWidths = (config, rows) => { | ||
@@ -241,3 +220,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((column, columnIndex) => { //iterate through column settings | ||
let result | ||
@@ -270,3 +249,3 @@ switch(true) { | ||
//calculate sum of all column widths (including marginLeft) | ||
let totalWidth = widths.reduce(function(prev, curr) { | ||
let totalWidth = widths.reduce((prev, curr) => { | ||
return prev + curr | ||
@@ -287,3 +266,3 @@ }) | ||
if (prop > 0) { | ||
widths = widths.map(function(value) { | ||
widths = widths.map(value => { | ||
return Math.floor(prop*value) | ||
@@ -290,0 +269,0 @@ }) |
if(require.main === module) { | ||
//called directly in terminal | ||
/* istanbul ignore next */ | ||
require("./../adapters/terminal-adapter.js") | ||
@@ -4,0 +5,0 @@ } else { |
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
42633
986
277
- Removedansi-regex@4.1.1(transitive)
- Removedcliui@5.0.0(transitive)
- Removedemoji-regex@7.0.3(transitive)
- Removedfind-up@3.0.0(transitive)
- Removedis-fullwidth-code-point@2.0.0(transitive)
- Removedlocate-path@3.0.0(transitive)
- Removedp-locate@3.0.0(transitive)
- Removedpath-exists@3.0.0(transitive)
- Removedstring-width@3.1.0(transitive)
- Removedstrip-ansi@5.2.0(transitive)
- Removedwrap-ansi@5.1.0(transitive)
- Removedyargs@13.3.2(transitive)
- Removedyargs-parser@13.1.2(transitive)
Updatedstrip-ansi@^6.0.0
Updatedyargs@^15.1.0