console-table-printer 2.15.2 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/src/console-table-printer.d.ts +1 -0
- package/dist/src/console-table-printer.js +4 -0
- package/dist/src/internalTable/internal-table.d.ts +1 -0
- package/dist/src/internalTable/internal-table.js +18 -17
- package/dist/src/utils/table-helpers.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -159,6 +159,7 @@ new Table({
|
|
|
159
159
|
|
|
160
160
|
- `addRow(rowObjet, options)` adding single row. This can be chained
|
|
161
161
|
- `addRows(rowObjects, options)` adding multiple rows. array of row object. This case options will be applied to all the objects in row
|
|
162
|
+
- `clearRows()` removes all rows while keeping the table columns and options. This can be chained
|
|
162
163
|
- `addColumn(columnObject)` adding single column
|
|
163
164
|
- `addColumns(columnObjects)` adding multiple columns
|
|
164
165
|
- `printTable()` Prints the table on your console
|
|
@@ -9,6 +9,7 @@ export default class Table {
|
|
|
9
9
|
addColumns(columns: string[] | ColumnOptionsRaw[]): this;
|
|
10
10
|
addRow(text: Dictionary, rowOptions?: RowOptionsRaw): this;
|
|
11
11
|
addRows(toBeInsertedRows: Dictionary[], rowOptions?: RowOptionsRaw): this;
|
|
12
|
+
clearRows(): this;
|
|
12
13
|
printTable(): void;
|
|
13
14
|
render(): string;
|
|
14
15
|
}
|
|
@@ -25,6 +25,10 @@ class Table {
|
|
|
25
25
|
this.table.addRows(toBeInsertedRows, (0, table_helpers_1.convertRawRowOptionsToStandard)(rowOptions));
|
|
26
26
|
return this;
|
|
27
27
|
}
|
|
28
|
+
clearRows() {
|
|
29
|
+
this.table.clearRows();
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
28
32
|
printTable() {
|
|
29
33
|
const tableRendered = this.table.renderTable();
|
|
30
34
|
console.log(tableRendered);
|
|
@@ -26,6 +26,7 @@ declare class TableInternal {
|
|
|
26
26
|
addColumns(toBeInsertedColumns: string[] | ColumnOptionsRaw[]): void;
|
|
27
27
|
addRow(text: Dictionary, options?: RowOptions): void;
|
|
28
28
|
addRows(toBeInsertedRows: Dictionary[], options?: RowOptions): void;
|
|
29
|
+
clearRows(): void;
|
|
29
30
|
renderTable(): string;
|
|
30
31
|
}
|
|
31
32
|
export default TableInternal;
|
|
@@ -17,23 +17,23 @@ class TableInternal {
|
|
|
17
17
|
}
|
|
18
18
|
initDetailed(options) {
|
|
19
19
|
var _a;
|
|
20
|
-
this.title =
|
|
21
|
-
this.tableStyle = Object.assign(Object.assign({}, this.tableStyle), options
|
|
22
|
-
this.sortFunction =
|
|
23
|
-
this.filterFunction =
|
|
24
|
-
this.enabledColumns =
|
|
25
|
-
this.disabledColumns =
|
|
26
|
-
this.computedColumns =
|
|
20
|
+
this.title = options.title || this.title;
|
|
21
|
+
this.tableStyle = Object.assign(Object.assign({}, this.tableStyle), options.style);
|
|
22
|
+
this.sortFunction = options.sort || this.sortFunction;
|
|
23
|
+
this.filterFunction = options.filter || this.filterFunction;
|
|
24
|
+
this.enabledColumns = options.enabledColumns || this.enabledColumns;
|
|
25
|
+
this.disabledColumns = options.disabledColumns || this.disabledColumns;
|
|
26
|
+
this.computedColumns = options.computedColumns || this.computedColumns;
|
|
27
27
|
this.columns =
|
|
28
|
-
((_a = options
|
|
29
|
-
this.rowSeparator =
|
|
30
|
-
this.charLength =
|
|
28
|
+
((_a = options.columns) === null || _a === void 0 ? void 0 : _a.map((column) => (0, input_converter_1.rawColumnToInternalColumn)(column, options.defaultColumnOptions))) || this.columns;
|
|
29
|
+
this.rowSeparator = options.rowSeparator || this.rowSeparator;
|
|
30
|
+
this.charLength = options.charLength || this.charLength;
|
|
31
31
|
this.defaultColumnOptions =
|
|
32
|
-
|
|
33
|
-
if (options
|
|
32
|
+
options.defaultColumnOptions || this.defaultColumnOptions;
|
|
33
|
+
if (options.shouldDisableColors) {
|
|
34
34
|
this.colorMap = {};
|
|
35
35
|
}
|
|
36
|
-
else if (options
|
|
36
|
+
else if (options.colorMap) {
|
|
37
37
|
this.colorMap = Object.assign(Object.assign({}, this.colorMap), options.colorMap);
|
|
38
38
|
}
|
|
39
39
|
if (options.rows !== undefined) {
|
|
@@ -59,7 +59,7 @@ class TableInternal {
|
|
|
59
59
|
if (options instanceof Array) {
|
|
60
60
|
this.initSimple(options);
|
|
61
61
|
}
|
|
62
|
-
else if (typeof options === 'object') {
|
|
62
|
+
else if (typeof options === 'object' && options !== null) {
|
|
63
63
|
this.initDetailed(options);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -84,15 +84,16 @@ class TableInternal {
|
|
|
84
84
|
}
|
|
85
85
|
addRow(text, options) {
|
|
86
86
|
this.createColumnFromRow(text);
|
|
87
|
-
this.rows.push((0, table_helpers_1.createRow)((options === null || options === void 0 ? void 0 : options.color) || table_constants_1.DEFAULT_ROW_FONT_COLOR, text, (options === null || options === void 0 ? void 0 : options.separator) !== undefined
|
|
88
|
-
? options === null || options === void 0 ? void 0 : options.separator
|
|
89
|
-
: this.rowSeparator));
|
|
87
|
+
this.rows.push((0, table_helpers_1.createRow)((options === null || options === void 0 ? void 0 : options.color) || table_constants_1.DEFAULT_ROW_FONT_COLOR, text, (options === null || options === void 0 ? void 0 : options.separator) !== undefined ? options.separator : this.rowSeparator));
|
|
90
88
|
}
|
|
91
89
|
addRows(toBeInsertedRows, options) {
|
|
92
90
|
toBeInsertedRows.forEach((toBeInsertedRow) => {
|
|
93
91
|
this.addRow(toBeInsertedRow, options);
|
|
94
92
|
});
|
|
95
93
|
}
|
|
94
|
+
clearRows() {
|
|
95
|
+
this.rows = [];
|
|
96
|
+
}
|
|
96
97
|
renderTable() {
|
|
97
98
|
return (0, internal_table_printer_1.renderTable)(this);
|
|
98
99
|
}
|
|
@@ -56,7 +56,7 @@ const findLenOfColumn = (column, rows, charLength) => {
|
|
|
56
56
|
const columnId = column.name;
|
|
57
57
|
const columnTitle = column.title;
|
|
58
58
|
const datatransform = column.transform;
|
|
59
|
-
let length = max(0,
|
|
59
|
+
let length = max(0, column.minLen || 0);
|
|
60
60
|
if (column.maxLen) {
|
|
61
61
|
// if customer input is mentioned a max width, lets see if all other can fit here
|
|
62
62
|
// if others cant fit find the max word length so that at least the table can be printed
|