console-table-printer 2.10.0 → 2.11.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 +10 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/src/console-table-printer.d.ts +4 -4
- package/dist/src/console-table-printer.js +6 -2
- package/dist/src/internalTable/input-converter.js +1 -1
- package/dist/src/internalTable/internal-table-printer.js +20 -20
- package/dist/src/internalTable/internal-table.d.ts +2 -0
- package/dist/src/internalTable/internal-table.js +13 -5
- package/dist/src/internalTable/table-pre-processors.js +1 -1
- package/dist/src/models/external-table.d.ts +4 -1
- package/dist/src/utils/colored-console-line.d.ts +6 -2
- package/dist/src/utils/colored-console-line.js +9 -6
- package/dist/src/utils/console-utils.js +1 -1
- package/dist/src/utils/string-utils.js +3 -3
- package/dist/src/utils/table-helpers.js +7 -7
- package/package.json +15 -15
- package/CHANGELOG.md +0 -108
package/README.md
CHANGED
|
@@ -89,14 +89,20 @@ You can also put properties based on columns (color/alignment/title)
|
|
|
89
89
|
```javascript
|
|
90
90
|
const p = new Table({
|
|
91
91
|
columns: [
|
|
92
|
-
{ name: 'index', alignment: 'left', color: 'blue' }, //with alignment and color
|
|
92
|
+
{ name: 'index', alignment: 'left', color: 'blue' }, // with alignment and color
|
|
93
93
|
{ name: 'text', alignment: 'right' },
|
|
94
94
|
{ name: 'is_priority_today', title: 'Is This Priority?' }, // with Title as separate Text
|
|
95
95
|
],
|
|
96
|
+
colorMap: {
|
|
97
|
+
custom_green: '\x1b[32m', // define customized color
|
|
98
|
+
},
|
|
96
99
|
});
|
|
97
100
|
|
|
98
101
|
p.addRow({ index: 1, text: 'red wine', value: 10.212 }, { color: 'green' });
|
|
99
|
-
p.addRow(
|
|
102
|
+
p.addRow(
|
|
103
|
+
{ index: 2, text: 'green gemuse', value: 20.0 },
|
|
104
|
+
{ color: 'custom_green' } // your green
|
|
105
|
+
);
|
|
100
106
|
p.addRow(
|
|
101
107
|
{ index: 3, text: 'gelb bananen', value: 100, is_priority_today: 'Y' },
|
|
102
108
|
{ color: 'yellow' }
|
|
@@ -108,7 +114,7 @@ p.addRow(
|
|
|
108
114
|
p.printTable();
|
|
109
115
|
```
|
|
110
116
|
|
|
111
|
-

|
|
117
|
+

|
|
112
118
|
|
|
113
119
|
## CLI
|
|
114
120
|
|
|
@@ -136,6 +142,7 @@ new Table({
|
|
|
136
142
|
{ name: 'column2', alignment: 'right', maxLen: 30 }, // lines bigger than this will be splitted in multiple lines
|
|
137
143
|
{ name: 'column3', title: 'Column3' }, // Title is what will be shown while printing, by default title = name
|
|
138
144
|
],
|
|
145
|
+
rows: [{ column1: 'row1' }, { column2: 'row2' }, { column3: 'row3' }],
|
|
139
146
|
sort: (row1, row2) => row2.column1 - row1.column1, // sorting order of rows (optional), this is normal js sort function for Array.sort
|
|
140
147
|
filter: (row) => row.column1 < 3, // filtering rows (optional)
|
|
141
148
|
enabledColumns: ['column1'], // array of columns that you want to see, all other will be ignored (optional)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import Table from './src/console-table-printer';
|
|
2
|
-
import { printSimpleTable as printTable } from './src/internalTable/internal-table-printer';
|
|
2
|
+
import { printSimpleTable as printTable, renderSimpleTable as renderTable } from './src/internalTable/internal-table-printer';
|
|
3
3
|
import { COLOR, ALIGNMENT } from './src/models/external-table';
|
|
4
|
-
export { Table, printTable, COLOR, ALIGNMENT };
|
|
4
|
+
export { Table, printTable, renderTable, COLOR, ALIGNMENT };
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.printTable = exports.Table = void 0;
|
|
6
|
+
exports.renderTable = exports.printTable = exports.Table = void 0;
|
|
7
7
|
const console_table_printer_1 = __importDefault(require("./src/console-table-printer"));
|
|
8
8
|
exports.Table = console_table_printer_1.default;
|
|
9
9
|
const internal_table_printer_1 = require("./src/internalTable/internal-table-printer");
|
|
10
10
|
Object.defineProperty(exports, "printTable", { enumerable: true, get: function () { return internal_table_printer_1.printSimpleTable; } });
|
|
11
|
+
Object.defineProperty(exports, "renderTable", { enumerable: true, get: function () { return internal_table_printer_1.renderSimpleTable; } });
|
|
@@ -5,10 +5,10 @@ import { RowOptionsRaw } from './utils/table-helpers';
|
|
|
5
5
|
export default class Table {
|
|
6
6
|
table: TableInternal;
|
|
7
7
|
constructor(options?: ComplexOptions | string[]);
|
|
8
|
-
addColumn(column: string):
|
|
9
|
-
addColumns(columns: string[]):
|
|
10
|
-
addRow(text: Dictionary, rowOptions?: RowOptionsRaw):
|
|
11
|
-
addRows(toBeInsertedRows: any, rowOptions?: RowOptionsRaw):
|
|
8
|
+
addColumn(column: string): this;
|
|
9
|
+
addColumns(columns: string[]): this;
|
|
10
|
+
addRow(text: Dictionary, rowOptions?: RowOptionsRaw): this;
|
|
11
|
+
addRows(toBeInsertedRows: any, rowOptions?: RowOptionsRaw): this;
|
|
12
12
|
printTable(): void;
|
|
13
13
|
render(): string;
|
|
14
14
|
}
|
|
@@ -11,15 +11,19 @@ class Table {
|
|
|
11
11
|
}
|
|
12
12
|
addColumn(column) {
|
|
13
13
|
this.table.addColumn(column);
|
|
14
|
+
return this;
|
|
14
15
|
}
|
|
15
16
|
addColumns(columns) {
|
|
16
17
|
this.table.addColumns(columns);
|
|
18
|
+
return this;
|
|
17
19
|
}
|
|
18
20
|
addRow(text, rowOptions) {
|
|
19
|
-
this.table.addRow(text, table_helpers_1.convertRawRowOptionsToStandard(rowOptions));
|
|
21
|
+
this.table.addRow(text, (0, table_helpers_1.convertRawRowOptionsToStandard)(rowOptions));
|
|
22
|
+
return this;
|
|
20
23
|
}
|
|
21
24
|
addRows(toBeInsertedRows, rowOptions) {
|
|
22
|
-
this.table.addRows(toBeInsertedRows, table_helpers_1.convertRawRowOptionsToStandard(rowOptions));
|
|
25
|
+
this.table.addRows(toBeInsertedRows, (0, table_helpers_1.convertRawRowOptionsToStandard)(rowOptions));
|
|
26
|
+
return this;
|
|
23
27
|
}
|
|
24
28
|
printTable() {
|
|
25
29
|
const tableRendered = this.table.renderTable();
|
|
@@ -11,5 +11,5 @@ const objIfExists = (key, val) => {
|
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
13
|
exports.objIfExists = objIfExists;
|
|
14
|
-
const rawColumnToInternalColumn = (column) => (Object.assign(Object.assign(Object.assign(Object.assign({ name: column.name, title: column.title || column.name }, exports.objIfExists('color', column.color)), exports.objIfExists('maxLen', column.maxLen)), exports.objIfExists('minLen', column.minLen)), { alignment: column.alignment || table_constants_1.DEFAULT_ROW_ALIGNMENT }));
|
|
14
|
+
const rawColumnToInternalColumn = (column) => (Object.assign(Object.assign(Object.assign(Object.assign({ name: column.name, title: column.title || column.name }, (0, exports.objIfExists)('color', column.color)), (0, exports.objIfExists)('maxLen', column.maxLen)), (0, exports.objIfExists)('minLen', column.minLen)), { alignment: column.alignment || table_constants_1.DEFAULT_ROW_ALIGNMENT }));
|
|
15
15
|
exports.rawColumnToInternalColumn = rawColumnToInternalColumn;
|
|
@@ -11,29 +11,29 @@ const table_helpers_1 = require("../utils/table-helpers");
|
|
|
11
11
|
const internal_table_1 = __importDefault(require("./internal-table"));
|
|
12
12
|
const table_pre_processors_1 = require("./table-pre-processors");
|
|
13
13
|
// ║ Index ║ ║ ║
|
|
14
|
-
const renderOneLine = (tableStyle, columns, currentLineIndex, widthLimitedColumnsArray, isHeader, row) => {
|
|
15
|
-
const line = new colored_console_line_1.default();
|
|
14
|
+
const renderOneLine = (tableStyle, columns, currentLineIndex, widthLimitedColumnsArray, isHeader, row, colorMap) => {
|
|
15
|
+
const line = new colored_console_line_1.default(colorMap);
|
|
16
16
|
line.addCharsWithColor(table_constants_1.DEFAULT_ROW_FONT_COLOR, tableStyle.vertical);
|
|
17
17
|
columns.forEach((column) => {
|
|
18
18
|
const thisLineHasText = currentLineIndex < widthLimitedColumnsArray[column.name].length;
|
|
19
19
|
const textForThisLine = thisLineHasText
|
|
20
|
-
? table_helpers_1.cellText(widthLimitedColumnsArray[column.name][currentLineIndex])
|
|
20
|
+
? (0, table_helpers_1.cellText)(widthLimitedColumnsArray[column.name][currentLineIndex])
|
|
21
21
|
: '';
|
|
22
22
|
line.addCharsWithColor(table_constants_1.DEFAULT_ROW_FONT_COLOR, ' ');
|
|
23
|
-
line.addCharsWithColor((isHeader && table_constants_1.DEFAULT_HEADER_FONT_COLOR) || column.color || row.color, string_utils_1.textWithPadding(textForThisLine, column.alignment || table_constants_1.DEFAULT_ROW_ALIGNMENT, column.length || table_constants_1.DEFAULT_COLUMN_LEN));
|
|
23
|
+
line.addCharsWithColor((isHeader && table_constants_1.DEFAULT_HEADER_FONT_COLOR) || column.color || row.color, (0, string_utils_1.textWithPadding)(textForThisLine, column.alignment || table_constants_1.DEFAULT_ROW_ALIGNMENT, column.length || table_constants_1.DEFAULT_COLUMN_LEN));
|
|
24
24
|
line.addCharsWithColor(table_constants_1.DEFAULT_ROW_FONT_COLOR, ` ${tableStyle.vertical}`);
|
|
25
25
|
});
|
|
26
26
|
return line.renderConsole();
|
|
27
27
|
};
|
|
28
28
|
// ║ Bold ║ text ║ value ║
|
|
29
29
|
// ║ Index ║ ║ ║
|
|
30
|
-
const renderWidthLimitedLines = (tableStyle, columns, row, isHeader) => {
|
|
30
|
+
const renderWidthLimitedLines = (tableStyle, columns, row, colorMap, isHeader) => {
|
|
31
31
|
// { col1: ['How', 'Is', 'Going'], col2: ['I am', 'Tom'], }
|
|
32
|
-
const widthLimitedColumnsArray = table_helpers_1.getWidthLimitedColumnsArray(columns, row);
|
|
32
|
+
const widthLimitedColumnsArray = (0, table_helpers_1.getWidthLimitedColumnsArray)(columns, row);
|
|
33
33
|
const totalLines = Object.values(widthLimitedColumnsArray).reduce((a, b) => Math.max(a, b.length), 0);
|
|
34
34
|
const ret = [];
|
|
35
35
|
for (let currentLineIndex = 0; currentLineIndex < totalLines; currentLineIndex += 1) {
|
|
36
|
-
const singleLine = renderOneLine(tableStyle, columns, currentLineIndex, widthLimitedColumnsArray, isHeader, row);
|
|
36
|
+
const singleLine = renderOneLine(tableStyle, columns, currentLineIndex, widthLimitedColumnsArray, isHeader, row, colorMap);
|
|
37
37
|
ret.push(singleLine);
|
|
38
38
|
}
|
|
39
39
|
return ret;
|
|
@@ -41,7 +41,7 @@ const renderWidthLimitedLines = (tableStyle, columns, row, isHeader) => {
|
|
|
41
41
|
// ║ 1 ║ I would like some red wine please ║ 10.212 ║
|
|
42
42
|
const renderRow = (table, row) => {
|
|
43
43
|
let ret = [];
|
|
44
|
-
ret = ret.concat(renderWidthLimitedLines(table.tableStyle, table.columns, row));
|
|
44
|
+
ret = ret.concat(renderWidthLimitedLines(table.tableStyle, table.columns, row, table.colorMap));
|
|
45
45
|
return ret;
|
|
46
46
|
};
|
|
47
47
|
/*
|
|
@@ -61,8 +61,8 @@ const renderTableTitle = (table) => {
|
|
|
61
61
|
.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN)
|
|
62
62
|
.reduce(reducer, 1);
|
|
63
63
|
};
|
|
64
|
-
const titleWithPadding = string_utils_1.textWithPadding(table.title, table_constants_1.DEFAULT_HEADER_ALIGNMENT, getTableWidth());
|
|
65
|
-
const styledText = new colored_console_line_1.default();
|
|
64
|
+
const titleWithPadding = (0, string_utils_1.textWithPadding)(table.title, table_constants_1.DEFAULT_HEADER_ALIGNMENT, getTableWidth());
|
|
65
|
+
const styledText = new colored_console_line_1.default(table.colorMap);
|
|
66
66
|
styledText.addCharsWithColor(table_constants_1.DEFAULT_HEADER_FONT_COLOR, titleWithPadding);
|
|
67
67
|
// The analysis Result
|
|
68
68
|
ret.push(styledText.renderConsole());
|
|
@@ -76,18 +76,18 @@ const renderTableTitle = (table) => {
|
|
|
76
76
|
const renderTableHeaders = (table) => {
|
|
77
77
|
let ret = [];
|
|
78
78
|
// ╔═══════╦═══════════════════════════════════════╦════════╗
|
|
79
|
-
ret.push(table_helpers_1.renderTableHorizontalBorders(table.tableStyle.headerTop, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN)));
|
|
79
|
+
ret.push((0, table_helpers_1.renderTableHorizontalBorders)(table.tableStyle.headerTop, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN)));
|
|
80
80
|
// ║ index ║ text ║ value ║
|
|
81
|
-
const row = table_helpers_1.createHeaderAsRow(table_helpers_1.createRow, table.columns);
|
|
82
|
-
ret = ret.concat(renderWidthLimitedLines(table.tableStyle, table.columns, row, true));
|
|
81
|
+
const row = (0, table_helpers_1.createHeaderAsRow)(table_helpers_1.createRow, table.columns);
|
|
82
|
+
ret = ret.concat(renderWidthLimitedLines(table.tableStyle, table.columns, row, table.colorMap, true));
|
|
83
83
|
// ╟═══════╬═══════════════════════════════════════╬════════╢
|
|
84
|
-
ret.push(table_helpers_1.renderTableHorizontalBorders(table.tableStyle.headerBottom, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN)));
|
|
84
|
+
ret.push((0, table_helpers_1.renderTableHorizontalBorders)(table.tableStyle.headerBottom, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN)));
|
|
85
85
|
return ret;
|
|
86
86
|
};
|
|
87
87
|
const renderTableEnding = (table) => {
|
|
88
88
|
const ret = [];
|
|
89
89
|
// ╚═══════╩═══════════════════════════════════════╩════════╝
|
|
90
|
-
ret.push(table_helpers_1.renderTableHorizontalBorders(table.tableStyle.tableBottom, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN)));
|
|
90
|
+
ret.push((0, table_helpers_1.renderTableHorizontalBorders)(table.tableStyle.tableBottom, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN)));
|
|
91
91
|
return ret;
|
|
92
92
|
};
|
|
93
93
|
const renderRowSeparator = (table, row) => {
|
|
@@ -96,13 +96,13 @@ const renderRowSeparator = (table, row) => {
|
|
|
96
96
|
const currentRowIndex = table.rows.indexOf(row);
|
|
97
97
|
if (currentRowIndex !== lastRowIndex && row.separator) {
|
|
98
98
|
// ╟═══════╬═══════════════════════════════════════╬════════╢
|
|
99
|
-
ret.push(table_helpers_1.renderTableHorizontalBorders(table.tableStyle.rowSeparator, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN)));
|
|
99
|
+
ret.push((0, table_helpers_1.renderTableHorizontalBorders)(table.tableStyle.rowSeparator, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN)));
|
|
100
100
|
}
|
|
101
101
|
return ret;
|
|
102
102
|
};
|
|
103
103
|
const renderTable = (table) => {
|
|
104
|
-
table_pre_processors_1.preProcessColumns(table); // enable / disable cols, find maxLn of each col/ computed Columns
|
|
105
|
-
table_pre_processors_1.preProcessRows(table); // sort and filter
|
|
104
|
+
(0, table_pre_processors_1.preProcessColumns)(table); // enable / disable cols, find maxLn of each col/ computed Columns
|
|
105
|
+
(0, table_pre_processors_1.preProcessRows)(table); // sort and filter
|
|
106
106
|
const ret = [];
|
|
107
107
|
renderTableTitle(table).forEach((row) => ret.push(row));
|
|
108
108
|
renderTableHeaders(table).forEach((row) => ret.push(row));
|
|
@@ -117,10 +117,10 @@ exports.renderTable = renderTable;
|
|
|
117
117
|
const renderSimpleTable = (rows) => {
|
|
118
118
|
const table = new internal_table_1.default();
|
|
119
119
|
table.addRows(rows);
|
|
120
|
-
return exports.renderTable(table);
|
|
120
|
+
return (0, exports.renderTable)(table);
|
|
121
121
|
};
|
|
122
122
|
exports.renderSimpleTable = renderSimpleTable;
|
|
123
123
|
const printSimpleTable = (rows) => {
|
|
124
|
-
console.log(exports.renderSimpleTable(rows));
|
|
124
|
+
console.log((0, exports.renderSimpleTable)(rows));
|
|
125
125
|
};
|
|
126
126
|
exports.printSimpleTable = printSimpleTable;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Dictionary, Row } from '../models/common';
|
|
2
2
|
import { ComplexOptions, ComputedColumn, RowFilterFunction, RowSortFunction } from '../models/external-table';
|
|
3
3
|
import { Column, TableStyleDetails } from '../models/internal-table';
|
|
4
|
+
import { ColorMap } from '../utils/colored-console-line';
|
|
4
5
|
import { RowOptions } from '../utils/table-helpers';
|
|
5
6
|
declare class TableInternal {
|
|
6
7
|
title?: string;
|
|
@@ -13,6 +14,7 @@ declare class TableInternal {
|
|
|
13
14
|
disabledColumns: string[];
|
|
14
15
|
computedColumns: any[];
|
|
15
16
|
rowSeparator: boolean;
|
|
17
|
+
colorMap: ColorMap;
|
|
16
18
|
initSimple(columns: string[]): void;
|
|
17
19
|
initDetailed(options: ComplexOptions): void;
|
|
18
20
|
constructor(options?: ComplexOptions | string[]);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const colored_console_line_1 = require("../utils/colored-console-line");
|
|
3
4
|
const table_constants_1 = require("../utils/table-constants");
|
|
4
5
|
const table_helpers_1 = require("../utils/table-helpers");
|
|
5
6
|
const input_converter_1 = require("./input-converter");
|
|
@@ -19,6 +20,7 @@ class TableInternal {
|
|
|
19
20
|
this.disabledColumns = [];
|
|
20
21
|
this.computedColumns = [];
|
|
21
22
|
this.rowSeparator = table_constants_1.DEFAULT_ROW_SEPARATOR;
|
|
23
|
+
this.colorMap = colored_console_line_1.DEFAULT_COLOR_MAP;
|
|
22
24
|
if (options instanceof Array) {
|
|
23
25
|
this.initSimple(options);
|
|
24
26
|
}
|
|
@@ -45,21 +47,27 @@ class TableInternal {
|
|
|
45
47
|
this.columns =
|
|
46
48
|
((_a = options === null || options === void 0 ? void 0 : options.columns) === null || _a === void 0 ? void 0 : _a.map(input_converter_1.rawColumnToInternalColumn)) || this.columns;
|
|
47
49
|
this.rowSeparator = (options === null || options === void 0 ? void 0 : options.rowSeparator) || this.rowSeparator;
|
|
50
|
+
if (options === null || options === void 0 ? void 0 : options.colorMap) {
|
|
51
|
+
this.colorMap = Object.assign(Object.assign({}, this.colorMap), options.colorMap);
|
|
52
|
+
}
|
|
53
|
+
if (options.rows !== undefined) {
|
|
54
|
+
this.addRows(options.rows);
|
|
55
|
+
}
|
|
48
56
|
}
|
|
49
57
|
createColumnFromRow(text) {
|
|
50
58
|
const colNames = this.columns.map((col) => col.name);
|
|
51
59
|
Object.keys(text).forEach((key) => {
|
|
52
60
|
if (!colNames.includes(key)) {
|
|
53
|
-
this.columns.push(table_helpers_1.createColumFromOnlyName(key));
|
|
61
|
+
this.columns.push((0, table_helpers_1.createColumFromOnlyName)(key));
|
|
54
62
|
}
|
|
55
63
|
});
|
|
56
64
|
}
|
|
57
65
|
addColumn(textOrObj) {
|
|
58
66
|
if (typeof textOrObj === 'string') {
|
|
59
|
-
this.columns.push(table_helpers_1.createColumFromOnlyName(textOrObj));
|
|
67
|
+
this.columns.push((0, table_helpers_1.createColumFromOnlyName)(textOrObj));
|
|
60
68
|
}
|
|
61
69
|
else {
|
|
62
|
-
this.columns.push(table_helpers_1.createColumFromComputedColumn(textOrObj));
|
|
70
|
+
this.columns.push((0, table_helpers_1.createColumFromComputedColumn)(textOrObj));
|
|
63
71
|
}
|
|
64
72
|
}
|
|
65
73
|
addColumns(toBeInsertedColumns) {
|
|
@@ -69,7 +77,7 @@ class TableInternal {
|
|
|
69
77
|
}
|
|
70
78
|
addRow(text, options) {
|
|
71
79
|
this.createColumnFromRow(text);
|
|
72
|
-
this.rows.push(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
|
|
80
|
+
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
|
|
73
81
|
? options === null || options === void 0 ? void 0 : options.separator
|
|
74
82
|
: this.rowSeparator));
|
|
75
83
|
}
|
|
@@ -79,7 +87,7 @@ class TableInternal {
|
|
|
79
87
|
});
|
|
80
88
|
}
|
|
81
89
|
renderTable() {
|
|
82
|
-
return internal_table_printer_1.renderTable(this);
|
|
90
|
+
return (0, internal_table_printer_1.renderTable)(this);
|
|
83
91
|
}
|
|
84
92
|
}
|
|
85
93
|
exports.default = TableInternal;
|
|
@@ -24,7 +24,7 @@ const enableColumnsIfNecessary = (table) => {
|
|
|
24
24
|
};
|
|
25
25
|
const findColumnWidth = (table) => {
|
|
26
26
|
table.columns.forEach((column) => {
|
|
27
|
-
column.length = table_helpers_1.findLenOfColumn(column, table.rows);
|
|
27
|
+
column.length = (0, table_helpers_1.findLenOfColumn)(column, table.rows);
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
30
|
const preProcessColumns = (table) => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ColorMap } from '../utils/colored-console-line';
|
|
2
|
+
import { ALIGNMENT, COLOR, Dictionary } from './common';
|
|
2
3
|
import { TableStyleDetails } from './internal-table';
|
|
3
4
|
export { ALIGNMENT, COLOR };
|
|
4
5
|
export interface ColumnOptionsRaw {
|
|
@@ -18,10 +19,12 @@ export interface ComplexOptions {
|
|
|
18
19
|
style?: TableStyleDetails;
|
|
19
20
|
title?: string;
|
|
20
21
|
columns?: ColumnOptionsRaw[];
|
|
22
|
+
rows?: Dictionary[];
|
|
21
23
|
sort?: RowSortFunction;
|
|
22
24
|
filter?: RowFilterFunction;
|
|
23
25
|
enabledColumns?: string[];
|
|
24
26
|
disabledColumns?: string[];
|
|
25
27
|
computedColumns?: ComputedColumn[];
|
|
26
28
|
rowSeparator?: boolean;
|
|
29
|
+
colorMap?: ColorMap;
|
|
27
30
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { COLOR } from '../models/common';
|
|
2
|
-
export declare
|
|
2
|
+
export declare type ColorMap = {
|
|
3
|
+
[key in COLOR]?: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const DEFAULT_COLOR_MAP: ColorMap;
|
|
3
6
|
export default class ColoredConsoleLine {
|
|
4
7
|
text: string;
|
|
5
|
-
|
|
8
|
+
colorMap: ColorMap;
|
|
9
|
+
constructor(colorMap?: ColorMap);
|
|
6
10
|
addCharsWithColor(color: COLOR, text: string): void;
|
|
7
11
|
renderConsole(): string;
|
|
8
12
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.DEFAULT_COLOR_MAP = void 0;
|
|
4
|
+
exports.DEFAULT_COLOR_MAP = {
|
|
5
5
|
red: '\x1b[31m',
|
|
6
6
|
green: '\x1b[32m',
|
|
7
7
|
yellow: '\x1b[33m',
|
|
@@ -13,14 +13,17 @@ const COLOR_MAP = {
|
|
|
13
13
|
white_bold: '\x1b[01m',
|
|
14
14
|
reset: '\x1b[0m',
|
|
15
15
|
};
|
|
16
|
-
const colorString = (color, text) => `${color && COLOR_MAP[color]}${text}${COLOR_MAP.reset}`;
|
|
17
|
-
exports.colorString = colorString;
|
|
18
16
|
class ColoredConsoleLine {
|
|
19
|
-
constructor() {
|
|
17
|
+
constructor(colorMap = exports.DEFAULT_COLOR_MAP) {
|
|
20
18
|
this.text = '';
|
|
19
|
+
this.colorMap = colorMap;
|
|
21
20
|
}
|
|
22
21
|
addCharsWithColor(color, text) {
|
|
23
|
-
|
|
22
|
+
const colorAnsi = this.colorMap[color];
|
|
23
|
+
this.text +=
|
|
24
|
+
colorAnsi !== undefined
|
|
25
|
+
? `${colorAnsi}${text}${this.colorMap.reset}`
|
|
26
|
+
: text;
|
|
24
27
|
}
|
|
25
28
|
renderConsole() {
|
|
26
29
|
return this.text;
|
|
@@ -4,5 +4,5 @@ const simple_wcswidth_1 = require("simple-wcswidth");
|
|
|
4
4
|
/* eslint-disable no-control-regex */
|
|
5
5
|
const colorRegex = /\x1b\[\d{1,3}m/g; // \x1b[30m \x1b[305m
|
|
6
6
|
const stripAnsi = (str) => str.replace(colorRegex, '');
|
|
7
|
-
const findWidthInConsole = (str) => simple_wcswidth_1.wcswidth(stripAnsi(str));
|
|
7
|
+
const findWidthInConsole = (str) => (0, simple_wcswidth_1.wcswidth)(stripAnsi(str));
|
|
8
8
|
exports.default = findWidthInConsole;
|
|
@@ -8,7 +8,7 @@ const console_utils_1 = __importDefault(require("./console-utils"));
|
|
|
8
8
|
// ("How are you?",center, 20) => " How are you? "
|
|
9
9
|
// ("How are you?",right, 20) => " How are you?"
|
|
10
10
|
const textWithPadding = (text, alignment, columnLen) => {
|
|
11
|
-
const curTextSize = console_utils_1.default(text);
|
|
11
|
+
const curTextSize = (0, console_utils_1.default)(text);
|
|
12
12
|
// alignments for center padding case
|
|
13
13
|
const leftPadding = Math.floor((columnLen - curTextSize) / 2);
|
|
14
14
|
const rightPadding = columnLen - leftPadding - curTextSize;
|
|
@@ -34,7 +34,7 @@ const limitWidth = (inpStr, width) => {
|
|
|
34
34
|
let now = [];
|
|
35
35
|
let cnt = 0;
|
|
36
36
|
spaceSeparatedStrings.forEach((strWithoutSpace) => {
|
|
37
|
-
const consoleWidth = console_utils_1.default(strWithoutSpace);
|
|
37
|
+
const consoleWidth = (0, console_utils_1.default)(strWithoutSpace);
|
|
38
38
|
if (cnt + consoleWidth <= width) {
|
|
39
39
|
cnt += consoleWidth + 1; // 1 for the space
|
|
40
40
|
now.push(strWithoutSpace);
|
|
@@ -50,5 +50,5 @@ const limitWidth = (inpStr, width) => {
|
|
|
50
50
|
};
|
|
51
51
|
exports.limitWidth = limitWidth;
|
|
52
52
|
// ("How are you?",10) => ["How are ", "you?"]
|
|
53
|
-
const biggestWordInSentence = (inpStr) => inpStr.split(' ').reduce((a, b) => Math.max(a, console_utils_1.default(b)), 0);
|
|
53
|
+
const biggestWordInSentence = (inpStr) => inpStr.split(' ').reduce((a, b) => Math.max(a, (0, console_utils_1.default)(b)), 0);
|
|
54
54
|
exports.biggestWordInSentence = biggestWordInSentence;
|
|
@@ -42,7 +42,7 @@ const createColumFromOnlyName = (name) => ({
|
|
|
42
42
|
title: name,
|
|
43
43
|
});
|
|
44
44
|
exports.createColumFromOnlyName = createColumFromOnlyName;
|
|
45
|
-
const createColumFromComputedColumn = (column) => (Object.assign(Object.assign(Object.assign(Object.assign({ name: column.name, title: column.title || column.name }, input_converter_1.objIfExists('color', column.color)), input_converter_1.objIfExists('maxLen', column.maxLen)), input_converter_1.objIfExists('minLen', column.minLen)), { alignment: column.alignment || table_constants_1.DEFAULT_ROW_ALIGNMENT }));
|
|
45
|
+
const createColumFromComputedColumn = (column) => (Object.assign(Object.assign(Object.assign(Object.assign({ name: column.name, title: column.title || column.name }, (0, input_converter_1.objIfExists)('color', column.color)), (0, input_converter_1.objIfExists)('maxLen', column.maxLen)), (0, input_converter_1.objIfExists)('minLen', column.minLen)), { alignment: column.alignment || table_constants_1.DEFAULT_ROW_ALIGNMENT }));
|
|
46
46
|
exports.createColumFromComputedColumn = createColumFromComputedColumn;
|
|
47
47
|
const createRow = (color, text, separator) => ({
|
|
48
48
|
color,
|
|
@@ -57,19 +57,19 @@ const findLenOfColumn = (column, rows) => {
|
|
|
57
57
|
if (column.maxLen) {
|
|
58
58
|
// if customer input is mentioned a max width, lets see if all other can fit here
|
|
59
59
|
// if others cant fit find the max word length so that at least the table can be printed
|
|
60
|
-
length = max(length, max(column.maxLen, string_utils_1.biggestWordInSentence(columnTitle)));
|
|
61
|
-
length = rows.reduce((acc, row) => max(acc, string_utils_1.biggestWordInSentence(exports.cellText(row.text[columnId]))), length);
|
|
60
|
+
length = max(length, max(column.maxLen, (0, string_utils_1.biggestWordInSentence)(columnTitle)));
|
|
61
|
+
length = rows.reduce((acc, row) => max(acc, (0, string_utils_1.biggestWordInSentence)((0, exports.cellText)(row.text[columnId]))), length);
|
|
62
62
|
return length;
|
|
63
63
|
}
|
|
64
|
-
length = max(length, console_utils_1.default(columnTitle));
|
|
64
|
+
length = max(length, (0, console_utils_1.default)(columnTitle));
|
|
65
65
|
rows.forEach((row) => {
|
|
66
|
-
length = max(length, console_utils_1.default(exports.cellText(row.text[columnId])));
|
|
66
|
+
length = max(length, (0, console_utils_1.default)((0, exports.cellText)(row.text[columnId])));
|
|
67
67
|
});
|
|
68
68
|
return length;
|
|
69
69
|
};
|
|
70
70
|
exports.findLenOfColumn = findLenOfColumn;
|
|
71
71
|
const renderTableHorizontalBorders = (style, column_lengths) => {
|
|
72
|
-
const str = exports.createTableHorizontalBorders(style, column_lengths);
|
|
72
|
+
const str = (0, exports.createTableHorizontalBorders)(style, column_lengths);
|
|
73
73
|
return str;
|
|
74
74
|
};
|
|
75
75
|
exports.renderTableHorizontalBorders = renderTableHorizontalBorders;
|
|
@@ -86,7 +86,7 @@ exports.createHeaderAsRow = createHeaderAsRow;
|
|
|
86
86
|
const getWidthLimitedColumnsArray = (columns, row) => {
|
|
87
87
|
const ret = {};
|
|
88
88
|
columns.forEach((column) => {
|
|
89
|
-
ret[column.name] = string_utils_1.limitWidth(exports.cellText(row.text[column.name]), column.length || table_constants_1.DEFAULT_COLUMN_LEN);
|
|
89
|
+
ret[column.name] = (0, string_utils_1.limitWidth)((0, exports.cellText)(row.text[column.name]), column.length || table_constants_1.DEFAULT_COLUMN_LEN);
|
|
90
90
|
});
|
|
91
91
|
return ret;
|
|
92
92
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "console-table-printer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"repository": "github:ayonious/console-table-printer",
|
|
5
5
|
"description": "Printing pretty tables on console log",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,24 +25,24 @@
|
|
|
25
25
|
"author": "Nahiyan Kamal",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@semantic-release/changelog": "^
|
|
29
|
-
"@semantic-release/git": "^
|
|
30
|
-
"@types/jest": "^
|
|
31
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
32
|
-
"@typescript-eslint/parser": "^
|
|
28
|
+
"@semantic-release/changelog": "^6.0.1",
|
|
29
|
+
"@semantic-release/git": "^10.0.1",
|
|
30
|
+
"@types/jest": "^27.0.2",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^5.2.0",
|
|
32
|
+
"@typescript-eslint/parser": "^5.2.0",
|
|
33
33
|
"chalk": "^4.1.2",
|
|
34
|
-
"eslint": "^
|
|
34
|
+
"eslint": "^8.1.0",
|
|
35
35
|
"eslint-config-airbnb-base": "^14.2.1",
|
|
36
36
|
"eslint-config-prettier": "^8.3.0",
|
|
37
|
-
"eslint-plugin-import": "^2.
|
|
38
|
-
"eslint-plugin-prettier": "^
|
|
39
|
-
"husky": "^7.0.
|
|
40
|
-
"jest": "^27.
|
|
41
|
-
"prettier": "^2.
|
|
37
|
+
"eslint-plugin-import": "^2.25.2",
|
|
38
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
39
|
+
"husky": "^7.0.4",
|
|
40
|
+
"jest": "^27.3.1",
|
|
41
|
+
"prettier": "^2.4.1",
|
|
42
42
|
"pretty-quick": "^3.1.1",
|
|
43
|
-
"semantic-release": "^
|
|
44
|
-
"ts-jest": "^27.0.
|
|
45
|
-
"typescript": "^4.
|
|
43
|
+
"semantic-release": "^18.0.0",
|
|
44
|
+
"ts-jest": "^27.0.7",
|
|
45
|
+
"typescript": "^4.4.4"
|
|
46
46
|
},
|
|
47
47
|
"homepage": "https://console-table.netlify.app",
|
|
48
48
|
"dependencies": {
|
package/CHANGELOG.md
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# [2.10.0](https://github.com/ayonious/console-table-printer/compare/v2.9.0...v2.10.0) (2021-08-04)
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
### Bug Fixes
|
|
5
|
-
|
|
6
|
-
* **row-separator:** make row separator optional ([#373](https://github.com/ayonious/console-table-printer/issues/373)) ([325db51](https://github.com/ayonious/console-table-printer/commit/325db51118e2027877205c973747b32e043d0a06))
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
### Features
|
|
10
|
-
|
|
11
|
-
* **row separator:** Added row separator option ([#372](https://github.com/ayonious/console-table-printer/issues/372)) ([63855ae](https://github.com/ayonious/console-table-printer/commit/63855aee0da731063cc6b5e2034ecdbe252d5935))
|
|
12
|
-
|
|
13
|
-
# [2.9.0](https://github.com/ayonious/console-table-printer/compare/v2.8.2...v2.9.0) (2021-05-12)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
### Bug Fixes
|
|
17
|
-
|
|
18
|
-
* **technical:** fixing types error for compilation ([68a8bf7](https://github.com/ayonious/console-table-printer/commit/68a8bf7fdd6234702adbf7209e63e4d1b3bdcd4a))
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
### Features
|
|
22
|
-
|
|
23
|
-
* min width ([#363](https://github.com/ayonious/console-table-printer/issues/363)) ([3a1b4e8](https://github.com/ayonious/console-table-printer/commit/3a1b4e8fff70033d2391fc58bd0c4258f18efffa))
|
|
24
|
-
|
|
25
|
-
## [2.8.2](https://github.com/ayonious/console-table-printer/compare/v2.8.1...v2.8.2) (2021-03-19)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
### Bug Fixes
|
|
29
|
-
|
|
30
|
-
* added circle ci ([79e72eb](https://github.com/ayonious/console-table-printer/commit/79e72eba75763d9c5e964a3aafc1a83a36f75b5a))
|
|
31
|
-
* Calculated Columns Title is shown ([#349](https://github.com/ayonious/console-table-printer/issues/349)) ([88ae550](https://github.com/ayonious/console-table-printer/commit/88ae55070818e7cc06d8a0872aeb45ffd3ed0299))
|
|
32
|
-
|
|
33
|
-
## [2.8.1](https://github.com/ayonious/console-table-printer/compare/v2.8.0...v2.8.1) (2021-03-06)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
### Bug Fixes
|
|
37
|
-
|
|
38
|
-
* fixing deployment ([981d819](https://github.com/ayonious/console-table-printer/commit/981d819e552c60f7d1a4f9f24a83e33a97eb582c))
|
|
39
|
-
|
|
40
|
-
# [2.8.0](https://github.com/ayonious/console-table-printer/compare/v2.7.5...v2.8.0) (2021-03-06)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
### Features
|
|
44
|
-
|
|
45
|
-
* Width Limit ([#343](https://github.com/ayonious/console-table-printer/issues/343)) ([f5a541b](https://github.com/ayonious/console-table-printer/commit/f5a541ba39d22cbe37cbbd8100b3b740b4247ba3))
|
|
46
|
-
|
|
47
|
-
## [2.7.5](https://github.com/ayonious/console-table-printer/compare/v2.7.4...v2.7.5) (2020-12-08)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
### Bug Fixes
|
|
51
|
-
|
|
52
|
-
* **technical:** migrate to yarn and fix deployment ([0a1babb](https://github.com/ayonious/console-table-printer/commit/0a1babb87ec404da68471517dcca9a5595a03e81))
|
|
53
|
-
|
|
54
|
-
## [2.7.4](https://github.com/ayonious/console-table-printer/compare/v2.7.3...v2.7.4) (2020-12-08)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
### Bug Fixes
|
|
58
|
-
|
|
59
|
-
* Asian Languages width fixing with simple-wcswidth ([a14272f](https://github.com/ayonious/console-table-printer/commit/a14272f6738310cc21492c38adf71fac06b2a9dd))
|
|
60
|
-
|
|
61
|
-
## [2.7.3](https://github.com/ayonious/console-table-printer/compare/v2.7.2...v2.7.3) (2020-12-06)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
### Bug Fixes
|
|
65
|
-
|
|
66
|
-
* revert wcwidth and special character support ([#329](https://github.com/ayonious/console-table-printer/issues/329)) ([d6e7847](https://github.com/ayonious/console-table-printer/commit/d6e78475f10fac718c2848483ac88611bd804b01))
|
|
67
|
-
|
|
68
|
-
## [2.7.2](https://github.com/ayonious/console-table-printer/compare/v2.7.1...v2.7.2) (2020-12-06)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
### Bug Fixes
|
|
72
|
-
|
|
73
|
-
* column width calculation with special characters ([#303](https://github.com/ayonious/console-table-printer/issues/303)) ([5a288e7](https://github.com/ayonious/console-table-printer/commit/5a288e7e4e5ee3daa9a3da7befc450fea3adbea1))
|
|
74
|
-
|
|
75
|
-
## [2.7.1](https://github.com/ayonious/console-table-printer/compare/v2.7.0...v2.7.1) (2020-12-05)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
### Bug Fixes
|
|
79
|
-
|
|
80
|
-
* **docs:** readme update for Header title ([#321](https://github.com/ayonious/console-table-printer/issues/321)) ([572979f](https://github.com/ayonious/console-table-printer/commit/572979f7d5d8b9f83a69bc51020cbaebd83a3f93))
|
|
81
|
-
|
|
82
|
-
# [2.7.0](https://github.com/ayonious/console-table-printer/compare/v2.6.0...v2.7.0) (2020-12-05)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
### Features
|
|
86
|
-
|
|
87
|
-
* Header title - View Header Title in console instead of ugly header name ([#319](https://github.com/ayonious/console-table-printer/issues/319)) ([78bb5aa](https://github.com/ayonious/console-table-printer/commit/78bb5aa6a6cb76d09c63f115f37cb9f4ad02e315))
|
|
88
|
-
|
|
89
|
-
# [2.6.0](https://github.com/ayonious/console-table-printer/compare/v2.5.1...v2.6.0) (2020-12-04)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
### Features
|
|
93
|
-
|
|
94
|
-
* Allow cell coloring ([#317](https://github.com/ayonious/console-table-printer/issues/317)) ([1026d51](https://github.com/ayonious/console-table-printer/commit/1026d5136240228b6e44d29afee45f1a6350ad07))
|
|
95
|
-
|
|
96
|
-
## [2.5.1](https://github.com/ayonious/console-table-printer/compare/v2.5.0...v2.5.1) (2020-11-07)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
### Bug Fixes
|
|
100
|
-
|
|
101
|
-
* **technical:** update dependency eslint to ^7.13.0 and remove package-lock deps updates ([#290](https://github.com/ayonious/console-table-printer/issues/290)) ([adc9c05](https://github.com/ayonious/console-table-printer/commit/adc9c052311e4b1508d17edfb2c0a92c65577e99))
|
|
102
|
-
|
|
103
|
-
# [2.5.0](https://github.com/ayonious/console-table-printer/compare/v2.4.36...v2.5.0) (2020-11-04)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
### Features
|
|
107
|
-
|
|
108
|
-
* **technical:** semantic release ([#288](https://github.com/ayonious/console-table-printer/issues/288)) ([3121382](https://github.com/ayonious/console-table-printer/commit/31213829a2b8e1e6f6aa9ee0b34e6a0450816952))
|