console-table-printer 2.9.0 → 2.11.1
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 +20 -6
- 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 +32 -21
- package/dist/src/internalTable/internal-table.d.ts +5 -1
- package/dist/src/internalTable/internal-table.js +28 -13
- package/dist/src/internalTable/table-pre-processors.js +1 -1
- package/dist/src/models/common.d.ts +4 -0
- package/dist/src/models/external-table.d.ts +6 -1
- package/dist/src/models/internal-table.d.ts +1 -0
- 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.d.ts +2 -1
- package/dist/src/utils/console-utils.js +17 -2
- package/dist/src/utils/string-utils.d.ts +4 -4
- package/dist/src/utils/string-utils.js +11 -5
- package/dist/src/utils/table-constants.d.ts +1 -0
- package/dist/src/utils/table-constants.js +8 -1
- package/dist/src/utils/table-helpers.d.ts +8 -6
- package/dist/src/utils/table-helpers.js +14 -12
- package/package.json +19 -19
- package/CHANGELOG.md +0 -96
package/README.md
CHANGED
|
@@ -45,10 +45,10 @@ const testCases = [
|
|
|
45
45
|
printTable(testCases);
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
Output:
|
|
49
|
-
|
|
50
48
|

|
|
51
49
|
|
|
50
|
+
## 🚨🚨Announcement🚨🚨 Official Documentation is moved [Here](https://console-table.netlify.app/docs)
|
|
51
|
+
|
|
52
52
|
You can also create a Table instance and print it:
|
|
53
53
|
|
|
54
54
|
```javascript
|
|
@@ -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,16 +142,24 @@ 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)
|
|
142
149
|
disabledColumns: ['column2'], // array of columns that you DONT want to see, these will always be hidden
|
|
150
|
+
colorMap: {
|
|
151
|
+
custom_green: '\x1b[32m', // define customized color
|
|
152
|
+
},
|
|
153
|
+
charLength: {
|
|
154
|
+
'👋': 2,
|
|
155
|
+
'😅': 2,
|
|
156
|
+
}, // custom len of chars in console
|
|
143
157
|
});
|
|
144
158
|
```
|
|
145
159
|
|
|
146
160
|
### Functions
|
|
147
161
|
|
|
148
|
-
- `addRow(rowObjet, options)` adding single row.
|
|
162
|
+
- `addRow(rowObjet, options)` adding single row. This can be chained
|
|
149
163
|
- `addRows(rowObjects, options)` adding multiple rows. array of row object. This case options will be applied to all the objects in row
|
|
150
164
|
- `addColumn(columnObject)` adding single column
|
|
151
165
|
- `addColumns(columnObjects)` adding multiple columns
|
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();
|
|
16
|
-
line.addCharsWithColor(
|
|
14
|
+
const renderOneLine = (tableStyle, columns, currentLineIndex, widthLimitedColumnsArray, isHeader, row, colorMap, charLength) => {
|
|
15
|
+
const line = new colored_console_line_1.default(colorMap);
|
|
16
|
+
line.addCharsWithColor('', tableStyle.vertical); // dont Color the Column borders
|
|
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));
|
|
24
|
-
line.addCharsWithColor(
|
|
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, charLength));
|
|
24
|
+
line.addCharsWithColor('', ` ${tableStyle.vertical}`); // dont Color the Column borders
|
|
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, charLength) => {
|
|
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, charLength);
|
|
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, charLength);
|
|
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, undefined, table.charLength));
|
|
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,28 +76,39 @@ 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
|
+
return ret;
|
|
92
|
+
};
|
|
93
|
+
const renderRowSeparator = (table, row) => {
|
|
94
|
+
const ret = [];
|
|
95
|
+
const lastRowIndex = table.rows.length - 1;
|
|
96
|
+
const currentRowIndex = table.rows.indexOf(row);
|
|
97
|
+
if (currentRowIndex !== lastRowIndex && row.separator) {
|
|
98
|
+
// ╟═══════╬═══════════════════════════════════════╬════════╢
|
|
99
|
+
ret.push((0, table_helpers_1.renderTableHorizontalBorders)(table.tableStyle.rowSeparator, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN)));
|
|
100
|
+
}
|
|
91
101
|
return ret;
|
|
92
102
|
};
|
|
93
103
|
const renderTable = (table) => {
|
|
94
|
-
table_pre_processors_1.preProcessColumns(table); // enable / disable cols, find maxLn of each col/ computed Columns
|
|
95
|
-
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
|
|
96
106
|
const ret = [];
|
|
97
107
|
renderTableTitle(table).forEach((row) => ret.push(row));
|
|
98
108
|
renderTableHeaders(table).forEach((row) => ret.push(row));
|
|
99
109
|
table.rows.forEach((row) => {
|
|
100
110
|
renderRow(table, row).forEach((row_) => ret.push(row_));
|
|
111
|
+
renderRowSeparator(table, row).forEach((row_) => ret.push(row_));
|
|
101
112
|
});
|
|
102
113
|
renderTableEnding(table).forEach((row) => ret.push(row));
|
|
103
114
|
return ret.join('\n');
|
|
@@ -106,10 +117,10 @@ exports.renderTable = renderTable;
|
|
|
106
117
|
const renderSimpleTable = (rows) => {
|
|
107
118
|
const table = new internal_table_1.default();
|
|
108
119
|
table.addRows(rows);
|
|
109
|
-
return exports.renderTable(table);
|
|
120
|
+
return (0, exports.renderTable)(table);
|
|
110
121
|
};
|
|
111
122
|
exports.renderSimpleTable = renderSimpleTable;
|
|
112
123
|
const printSimpleTable = (rows) => {
|
|
113
|
-
console.log(exports.renderSimpleTable(rows));
|
|
124
|
+
console.log((0, exports.renderSimpleTable)(rows));
|
|
114
125
|
};
|
|
115
126
|
exports.printSimpleTable = printSimpleTable;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Dictionary, Row } from '../models/common';
|
|
1
|
+
import { CharLengthDict, 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;
|
|
@@ -12,6 +13,9 @@ declare class TableInternal {
|
|
|
12
13
|
enabledColumns: string[];
|
|
13
14
|
disabledColumns: string[];
|
|
14
15
|
computedColumns: any[];
|
|
16
|
+
rowSeparator: boolean;
|
|
17
|
+
colorMap: ColorMap;
|
|
18
|
+
charLength: CharLengthDict;
|
|
15
19
|
initSimple(columns: string[]): void;
|
|
16
20
|
initDetailed(options: ComplexOptions): void;
|
|
17
21
|
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");
|
|
@@ -18,6 +19,9 @@ class TableInternal {
|
|
|
18
19
|
this.enabledColumns = [];
|
|
19
20
|
this.disabledColumns = [];
|
|
20
21
|
this.computedColumns = [];
|
|
22
|
+
this.rowSeparator = table_constants_1.DEFAULT_ROW_SEPARATOR;
|
|
23
|
+
this.colorMap = colored_console_line_1.DEFAULT_COLOR_MAP;
|
|
24
|
+
this.charLength = {};
|
|
21
25
|
if (options instanceof Array) {
|
|
22
26
|
this.initSimple(options);
|
|
23
27
|
}
|
|
@@ -34,29 +38,38 @@ class TableInternal {
|
|
|
34
38
|
}
|
|
35
39
|
initDetailed(options) {
|
|
36
40
|
var _a;
|
|
37
|
-
this.title = options.title ||
|
|
38
|
-
this.tableStyle = (options === null || options === void 0 ? void 0 : options.style) ||
|
|
39
|
-
this.sortFunction = (options === null || options === void 0 ? void 0 : options.sort) ||
|
|
40
|
-
this.filterFunction = (options === null || options === void 0 ? void 0 : options.filter) ||
|
|
41
|
-
this.enabledColumns = (options === null || options === void 0 ? void 0 : options.enabledColumns) ||
|
|
42
|
-
this.disabledColumns = (options === null || options === void 0 ? void 0 : options.disabledColumns) ||
|
|
43
|
-
this.computedColumns = (options === null || options === void 0 ? void 0 : options.computedColumns) ||
|
|
44
|
-
this.columns =
|
|
41
|
+
this.title = (options === null || options === void 0 ? void 0 : options.title) || this.title;
|
|
42
|
+
this.tableStyle = (options === null || options === void 0 ? void 0 : options.style) || this.tableStyle;
|
|
43
|
+
this.sortFunction = (options === null || options === void 0 ? void 0 : options.sort) || this.sortFunction;
|
|
44
|
+
this.filterFunction = (options === null || options === void 0 ? void 0 : options.filter) || this.filterFunction;
|
|
45
|
+
this.enabledColumns = (options === null || options === void 0 ? void 0 : options.enabledColumns) || this.enabledColumns;
|
|
46
|
+
this.disabledColumns = (options === null || options === void 0 ? void 0 : options.disabledColumns) || this.disabledColumns;
|
|
47
|
+
this.computedColumns = (options === null || options === void 0 ? void 0 : options.computedColumns) || this.computedColumns;
|
|
48
|
+
this.columns =
|
|
49
|
+
((_a = options === null || options === void 0 ? void 0 : options.columns) === null || _a === void 0 ? void 0 : _a.map(input_converter_1.rawColumnToInternalColumn)) || this.columns;
|
|
50
|
+
this.rowSeparator = (options === null || options === void 0 ? void 0 : options.rowSeparator) || this.rowSeparator;
|
|
51
|
+
this.charLength = (options === null || options === void 0 ? void 0 : options.charLength) || this.charLength;
|
|
52
|
+
if (options === null || options === void 0 ? void 0 : options.colorMap) {
|
|
53
|
+
this.colorMap = Object.assign(Object.assign({}, this.colorMap), options.colorMap);
|
|
54
|
+
}
|
|
55
|
+
if (options.rows !== undefined) {
|
|
56
|
+
this.addRows(options.rows);
|
|
57
|
+
}
|
|
45
58
|
}
|
|
46
59
|
createColumnFromRow(text) {
|
|
47
60
|
const colNames = this.columns.map((col) => col.name);
|
|
48
61
|
Object.keys(text).forEach((key) => {
|
|
49
62
|
if (!colNames.includes(key)) {
|
|
50
|
-
this.columns.push(table_helpers_1.createColumFromOnlyName(key));
|
|
63
|
+
this.columns.push((0, table_helpers_1.createColumFromOnlyName)(key));
|
|
51
64
|
}
|
|
52
65
|
});
|
|
53
66
|
}
|
|
54
67
|
addColumn(textOrObj) {
|
|
55
68
|
if (typeof textOrObj === 'string') {
|
|
56
|
-
this.columns.push(table_helpers_1.createColumFromOnlyName(textOrObj));
|
|
69
|
+
this.columns.push((0, table_helpers_1.createColumFromOnlyName)(textOrObj));
|
|
57
70
|
}
|
|
58
71
|
else {
|
|
59
|
-
this.columns.push(table_helpers_1.createColumFromComputedColumn(textOrObj));
|
|
72
|
+
this.columns.push((0, table_helpers_1.createColumFromComputedColumn)(textOrObj));
|
|
60
73
|
}
|
|
61
74
|
}
|
|
62
75
|
addColumns(toBeInsertedColumns) {
|
|
@@ -66,7 +79,9 @@ class TableInternal {
|
|
|
66
79
|
}
|
|
67
80
|
addRow(text, options) {
|
|
68
81
|
this.createColumnFromRow(text);
|
|
69
|
-
this.rows.push(table_helpers_1.createRow((options === null || options === void 0 ? void 0 : options.color) || table_constants_1.DEFAULT_ROW_FONT_COLOR, text)
|
|
82
|
+
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
|
|
83
|
+
? options === null || options === void 0 ? void 0 : options.separator
|
|
84
|
+
: this.rowSeparator));
|
|
70
85
|
}
|
|
71
86
|
addRows(toBeInsertedRows, options) {
|
|
72
87
|
toBeInsertedRows.forEach((toBeInsertedRow) => {
|
|
@@ -74,7 +89,7 @@ class TableInternal {
|
|
|
74
89
|
});
|
|
75
90
|
}
|
|
76
91
|
renderTable() {
|
|
77
|
-
return internal_table_printer_1.renderTable(this);
|
|
92
|
+
return (0, internal_table_printer_1.renderTable)(this);
|
|
78
93
|
}
|
|
79
94
|
}
|
|
80
95
|
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, table.charLength);
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
30
|
const preProcessColumns = (table) => {
|
|
@@ -4,7 +4,11 @@ export declare type COLOR = typeof COLORS[number];
|
|
|
4
4
|
export interface Dictionary {
|
|
5
5
|
[key: string]: any;
|
|
6
6
|
}
|
|
7
|
+
export interface CharLengthDict {
|
|
8
|
+
[key: string]: number;
|
|
9
|
+
}
|
|
7
10
|
export interface Row {
|
|
8
11
|
color: COLOR;
|
|
12
|
+
separator: boolean;
|
|
9
13
|
text: Dictionary;
|
|
10
14
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ColorMap } from '../utils/colored-console-line';
|
|
2
|
+
import { ALIGNMENT, CharLengthDict, COLOR, Dictionary } from './common';
|
|
2
3
|
import { TableStyleDetails } from './internal-table';
|
|
3
4
|
export { ALIGNMENT, COLOR };
|
|
4
5
|
export interface ColumnOptionsRaw {
|
|
@@ -18,9 +19,13 @@ 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[];
|
|
28
|
+
rowSeparator?: boolean;
|
|
29
|
+
colorMap?: ColorMap;
|
|
30
|
+
charLength?: CharLengthDict;
|
|
26
31
|
}
|
|
@@ -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;
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findWidthInConsole = void 0;
|
|
3
4
|
const simple_wcswidth_1 = require("simple-wcswidth");
|
|
4
5
|
/* eslint-disable no-control-regex */
|
|
5
6
|
const colorRegex = /\x1b\[\d{1,3}m/g; // \x1b[30m \x1b[305m
|
|
6
7
|
const stripAnsi = (str) => str.replace(colorRegex, '');
|
|
7
|
-
const findWidthInConsole = (str) =>
|
|
8
|
-
|
|
8
|
+
const findWidthInConsole = (str, charLength) => {
|
|
9
|
+
let strLen = 0;
|
|
10
|
+
str = stripAnsi(str);
|
|
11
|
+
if (charLength) {
|
|
12
|
+
Object.entries(charLength).forEach(([key, value]) => {
|
|
13
|
+
// count appearance of the key in the string and remove from original string
|
|
14
|
+
let regex = new RegExp(key, 'g');
|
|
15
|
+
strLen += (str.match(regex) || []).length * value;
|
|
16
|
+
str = str.replace(key, '');
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
strLen += (0, simple_wcswidth_1.wcswidth)(str);
|
|
20
|
+
return strLen;
|
|
21
|
+
};
|
|
22
|
+
exports.findWidthInConsole = findWidthInConsole;
|
|
23
|
+
exports.default = exports.findWidthInConsole;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ALIGNMENT } from '../models/common';
|
|
2
|
-
export declare const textWithPadding: (text: string, alignment: ALIGNMENT, columnLen: number) => string;
|
|
3
|
-
export declare const limitWidth: (inpStr: string, width: number) => string[];
|
|
4
|
-
export declare const biggestWordInSentence: (inpStr: string) => number;
|
|
1
|
+
import { ALIGNMENT, CharLengthDict } from '../models/common';
|
|
2
|
+
export declare const textWithPadding: (text: string, alignment: ALIGNMENT, columnLen: number, charLength?: CharLengthDict) => string;
|
|
3
|
+
export declare const limitWidth: (inpStr: string, width: number, charLength?: CharLengthDict) => string[];
|
|
4
|
+
export declare const biggestWordInSentence: (inpStr: string, charLength?: CharLengthDict) => number;
|
|
@@ -7,11 +7,15 @@ exports.biggestWordInSentence = exports.limitWidth = exports.textWithPadding = v
|
|
|
7
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
|
-
const textWithPadding = (text, alignment, columnLen) => {
|
|
11
|
-
const curTextSize = console_utils_1.default(text);
|
|
10
|
+
const textWithPadding = (text, alignment, columnLen, charLength) => {
|
|
11
|
+
const curTextSize = (0, console_utils_1.default)(text, charLength);
|
|
12
12
|
// alignments for center padding case
|
|
13
13
|
const leftPadding = Math.floor((columnLen - curTextSize) / 2);
|
|
14
14
|
const rightPadding = columnLen - leftPadding - curTextSize;
|
|
15
|
+
// handle edge cases where the text size is larger than the column length
|
|
16
|
+
if (columnLen < curTextSize) {
|
|
17
|
+
return text;
|
|
18
|
+
}
|
|
15
19
|
// console.log(text, columnLen, curTextSize);
|
|
16
20
|
switch (alignment) {
|
|
17
21
|
case 'left':
|
|
@@ -28,13 +32,13 @@ const textWithPadding = (text, alignment, columnLen) => {
|
|
|
28
32
|
};
|
|
29
33
|
exports.textWithPadding = textWithPadding;
|
|
30
34
|
// ("How are you?",10) => ["How are ", "you?"]
|
|
31
|
-
const limitWidth = (inpStr, width) => {
|
|
35
|
+
const limitWidth = (inpStr, width, charLength) => {
|
|
32
36
|
const ret = [];
|
|
33
37
|
const spaceSeparatedStrings = inpStr.split(' ');
|
|
34
38
|
let now = [];
|
|
35
39
|
let cnt = 0;
|
|
36
40
|
spaceSeparatedStrings.forEach((strWithoutSpace) => {
|
|
37
|
-
const consoleWidth = console_utils_1.default(strWithoutSpace);
|
|
41
|
+
const consoleWidth = (0, console_utils_1.default)(strWithoutSpace, charLength);
|
|
38
42
|
if (cnt + consoleWidth <= width) {
|
|
39
43
|
cnt += consoleWidth + 1; // 1 for the space
|
|
40
44
|
now.push(strWithoutSpace);
|
|
@@ -50,5 +54,7 @@ const limitWidth = (inpStr, width) => {
|
|
|
50
54
|
};
|
|
51
55
|
exports.limitWidth = limitWidth;
|
|
52
56
|
// ("How are you?",10) => ["How are ", "you?"]
|
|
53
|
-
const biggestWordInSentence = (inpStr
|
|
57
|
+
const biggestWordInSentence = (inpStr, charLength) => inpStr
|
|
58
|
+
.split(' ')
|
|
59
|
+
.reduce((a, b) => Math.max(a, (0, console_utils_1.default)(b, charLength)), 0);
|
|
54
60
|
exports.biggestWordInSentence = biggestWordInSentence;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ALIGNMENT, COLOR } from '../models/common';
|
|
2
2
|
import { TableStyleDetails } from '../models/internal-table';
|
|
3
3
|
export declare const DEFAULT_COLUMN_LEN = 20;
|
|
4
|
+
export declare const DEFAULT_ROW_SEPARATOR = false;
|
|
4
5
|
export declare const DEFAULT_TABLE_STYLE: TableStyleDetails;
|
|
5
6
|
export declare const ALIGNMENTS: string[];
|
|
6
7
|
export declare const COLORS: string[];
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_HEADER_ALIGNMENT = exports.DEFAULT_ROW_ALIGNMENT = exports.DEFAULT_HEADER_FONT_COLOR = exports.DEFAULT_ROW_FONT_COLOR = exports.COLORS = exports.ALIGNMENTS = exports.DEFAULT_TABLE_STYLE = exports.DEFAULT_COLUMN_LEN = void 0;
|
|
3
|
+
exports.DEFAULT_HEADER_ALIGNMENT = exports.DEFAULT_ROW_ALIGNMENT = exports.DEFAULT_HEADER_FONT_COLOR = exports.DEFAULT_ROW_FONT_COLOR = exports.COLORS = exports.ALIGNMENTS = exports.DEFAULT_TABLE_STYLE = exports.DEFAULT_ROW_SEPARATOR = exports.DEFAULT_COLUMN_LEN = void 0;
|
|
4
4
|
exports.DEFAULT_COLUMN_LEN = 20;
|
|
5
|
+
exports.DEFAULT_ROW_SEPARATOR = false;
|
|
5
6
|
exports.DEFAULT_TABLE_STYLE = {
|
|
6
7
|
/*
|
|
7
8
|
Default Style
|
|
@@ -29,6 +30,12 @@ exports.DEFAULT_TABLE_STYLE = {
|
|
|
29
30
|
other: '─',
|
|
30
31
|
},
|
|
31
32
|
vertical: '│',
|
|
33
|
+
rowSeparator: {
|
|
34
|
+
left: '├',
|
|
35
|
+
mid: '┼',
|
|
36
|
+
right: '┤',
|
|
37
|
+
other: '─',
|
|
38
|
+
},
|
|
32
39
|
};
|
|
33
40
|
exports.ALIGNMENTS = ['right', 'left', 'center'];
|
|
34
41
|
exports.COLORS = [
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { COLOR, Dictionary, Row } from '../models/common';
|
|
1
|
+
import { CharLengthDict, COLOR, Dictionary, Row } from '../models/common';
|
|
2
2
|
import { ComputedColumn } from '../models/external-table';
|
|
3
3
|
import { Column } from '../models/internal-table';
|
|
4
4
|
export declare const cellText: (text: string | number) => string;
|
|
5
5
|
export interface RowOptionsRaw {
|
|
6
|
-
color
|
|
6
|
+
color?: string;
|
|
7
|
+
separator?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export interface RowOptions {
|
|
9
10
|
color: COLOR;
|
|
11
|
+
separator: boolean;
|
|
10
12
|
}
|
|
11
|
-
export declare const convertRawRowOptionsToStandard: (options?: RowOptionsRaw
|
|
13
|
+
export declare const convertRawRowOptionsToStandard: (options?: RowOptionsRaw) => RowOptions | undefined;
|
|
12
14
|
export declare const createTableHorizontalBorders: ({ left, mid, right, other, }: {
|
|
13
15
|
left: string;
|
|
14
16
|
mid: string;
|
|
@@ -17,10 +19,10 @@ export declare const createTableHorizontalBorders: ({ left, mid, right, other, }
|
|
|
17
19
|
}, column_lengths: number[]) => string;
|
|
18
20
|
export declare const createColumFromOnlyName: (name: string) => Column;
|
|
19
21
|
export declare const createColumFromComputedColumn: (column: ComputedColumn) => Column;
|
|
20
|
-
export declare const createRow: (color: COLOR, text: Dictionary) => Row;
|
|
21
|
-
export declare const findLenOfColumn: (column: Column, rows: Row[]) => number;
|
|
22
|
+
export declare const createRow: (color: COLOR, text: Dictionary, separator: boolean) => Row;
|
|
23
|
+
export declare const findLenOfColumn: (column: Column, rows: Row[], charLength?: CharLengthDict) => number;
|
|
22
24
|
export declare const renderTableHorizontalBorders: (style: any, column_lengths: number[]) => string;
|
|
23
25
|
export declare const createHeaderAsRow: (createRowFn: any, columns: Column[]) => Row;
|
|
24
|
-
export declare const getWidthLimitedColumnsArray: (columns: Column[], row: Row) => {
|
|
26
|
+
export declare const getWidthLimitedColumnsArray: (columns: Column[], row: Row, charLength?: CharLengthDict) => {
|
|
25
27
|
[key: string]: string[];
|
|
26
28
|
};
|
|
@@ -16,6 +16,7 @@ const convertRawRowOptionsToStandard = (options) => {
|
|
|
16
16
|
if (options) {
|
|
17
17
|
return {
|
|
18
18
|
color: options.color,
|
|
19
|
+
separator: options.separator || table_constants_1.DEFAULT_ROW_SEPARATOR,
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
22
|
return undefined;
|
|
@@ -41,39 +42,40 @@ const createColumFromOnlyName = (name) => ({
|
|
|
41
42
|
title: name,
|
|
42
43
|
});
|
|
43
44
|
exports.createColumFromOnlyName = createColumFromOnlyName;
|
|
44
|
-
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 }));
|
|
45
46
|
exports.createColumFromComputedColumn = createColumFromComputedColumn;
|
|
46
|
-
const createRow = (color, text) => ({
|
|
47
|
+
const createRow = (color, text, separator) => ({
|
|
47
48
|
color,
|
|
49
|
+
separator,
|
|
48
50
|
text,
|
|
49
51
|
});
|
|
50
52
|
exports.createRow = createRow;
|
|
51
|
-
const findLenOfColumn = (column, rows) => {
|
|
53
|
+
const findLenOfColumn = (column, rows, charLength) => {
|
|
52
54
|
const columnId = column.name;
|
|
53
55
|
const columnTitle = column.title;
|
|
54
56
|
let length = max(0, (column === null || column === void 0 ? void 0 : column.minLen) || 0);
|
|
55
57
|
if (column.maxLen) {
|
|
56
58
|
// if customer input is mentioned a max width, lets see if all other can fit here
|
|
57
59
|
// if others cant fit find the max word length so that at least the table can be printed
|
|
58
|
-
length = max(length, max(column.maxLen, string_utils_1.biggestWordInSentence(columnTitle)));
|
|
59
|
-
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, charLength)));
|
|
61
|
+
length = rows.reduce((acc, row) => max(acc, (0, string_utils_1.biggestWordInSentence)((0, exports.cellText)(row.text[columnId]), charLength)), length);
|
|
60
62
|
return length;
|
|
61
63
|
}
|
|
62
|
-
length = max(length, console_utils_1.default(columnTitle));
|
|
64
|
+
length = max(length, (0, console_utils_1.default)(columnTitle, charLength));
|
|
63
65
|
rows.forEach((row) => {
|
|
64
|
-
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]), charLength));
|
|
65
67
|
});
|
|
66
68
|
return length;
|
|
67
69
|
};
|
|
68
70
|
exports.findLenOfColumn = findLenOfColumn;
|
|
69
71
|
const renderTableHorizontalBorders = (style, column_lengths) => {
|
|
70
|
-
const str = exports.createTableHorizontalBorders(style, column_lengths);
|
|
72
|
+
const str = (0, exports.createTableHorizontalBorders)(style, column_lengths);
|
|
71
73
|
return str;
|
|
72
74
|
};
|
|
73
75
|
exports.renderTableHorizontalBorders = renderTableHorizontalBorders;
|
|
74
76
|
const createHeaderAsRow = (createRowFn, columns) => {
|
|
75
|
-
const headerColor =
|
|
76
|
-
const row = createRowFn(headerColor, {});
|
|
77
|
+
const headerColor = table_constants_1.DEFAULT_HEADER_FONT_COLOR;
|
|
78
|
+
const row = createRowFn(headerColor, {}, false);
|
|
77
79
|
columns.forEach((column) => {
|
|
78
80
|
row.text[column.name] = column.title;
|
|
79
81
|
});
|
|
@@ -81,10 +83,10 @@ const createHeaderAsRow = (createRowFn, columns) => {
|
|
|
81
83
|
};
|
|
82
84
|
exports.createHeaderAsRow = createHeaderAsRow;
|
|
83
85
|
// { col1: ['How', 'Is', 'Going'], col2: ['I am', 'Tom'], }
|
|
84
|
-
const getWidthLimitedColumnsArray = (columns, row) => {
|
|
86
|
+
const getWidthLimitedColumnsArray = (columns, row, charLength) => {
|
|
85
87
|
const ret = {};
|
|
86
88
|
columns.forEach((column) => {
|
|
87
|
-
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, charLength);
|
|
88
90
|
});
|
|
89
91
|
return ret;
|
|
90
92
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "console-table-printer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.1",
|
|
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": "^
|
|
33
|
-
"chalk": "^4.1.
|
|
34
|
-
"eslint": "^
|
|
35
|
-
"eslint-config-airbnb-base": "^
|
|
36
|
-
"eslint-config-prettier": "^8.
|
|
37
|
-
"eslint-plugin-import": "^2.
|
|
38
|
-
"eslint-plugin-prettier": "^
|
|
39
|
-
"husky": "^
|
|
40
|
-
"jest": "^
|
|
41
|
-
"prettier": "^2.
|
|
42
|
-
"pretty-quick": "^3.1.
|
|
43
|
-
"semantic-release": "^
|
|
44
|
-
"ts-jest": "^
|
|
45
|
-
"typescript": "^4.
|
|
28
|
+
"@semantic-release/changelog": "^6.0.1",
|
|
29
|
+
"@semantic-release/git": "^10.0.1",
|
|
30
|
+
"@types/jest": "^28.1.8",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^5.34.0",
|
|
32
|
+
"@typescript-eslint/parser": "^5.34.0",
|
|
33
|
+
"chalk": "^4.1.2",
|
|
34
|
+
"eslint": "^8.22.0",
|
|
35
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
36
|
+
"eslint-config-prettier": "^8.5.0",
|
|
37
|
+
"eslint-plugin-import": "^2.26.0",
|
|
38
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
39
|
+
"husky": "^8.0.1",
|
|
40
|
+
"jest": "^28.1.3",
|
|
41
|
+
"prettier": "^2.7.1",
|
|
42
|
+
"pretty-quick": "^3.1.3",
|
|
43
|
+
"semantic-release": "^19.0.5",
|
|
44
|
+
"ts-jest": "^28.0.8",
|
|
45
|
+
"typescript": "^4.7.4"
|
|
46
46
|
},
|
|
47
47
|
"homepage": "https://console-table.netlify.app",
|
|
48
48
|
"dependencies": {
|
package/CHANGELOG.md
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
# [2.9.0](https://github.com/ayonious/console-table-printer/compare/v2.8.2...v2.9.0) (2021-05-12)
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
### Bug Fixes
|
|
5
|
-
|
|
6
|
-
* **technical:** fixing types error for compilation ([68a8bf7](https://github.com/ayonious/console-table-printer/commit/68a8bf7fdd6234702adbf7209e63e4d1b3bdcd4a))
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
### Features
|
|
10
|
-
|
|
11
|
-
* min width ([#363](https://github.com/ayonious/console-table-printer/issues/363)) ([3a1b4e8](https://github.com/ayonious/console-table-printer/commit/3a1b4e8fff70033d2391fc58bd0c4258f18efffa))
|
|
12
|
-
|
|
13
|
-
## [2.8.2](https://github.com/ayonious/console-table-printer/compare/v2.8.1...v2.8.2) (2021-03-19)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
### Bug Fixes
|
|
17
|
-
|
|
18
|
-
* added circle ci ([79e72eb](https://github.com/ayonious/console-table-printer/commit/79e72eba75763d9c5e964a3aafc1a83a36f75b5a))
|
|
19
|
-
* 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))
|
|
20
|
-
|
|
21
|
-
## [2.8.1](https://github.com/ayonious/console-table-printer/compare/v2.8.0...v2.8.1) (2021-03-06)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
### Bug Fixes
|
|
25
|
-
|
|
26
|
-
* fixing deployment ([981d819](https://github.com/ayonious/console-table-printer/commit/981d819e552c60f7d1a4f9f24a83e33a97eb582c))
|
|
27
|
-
|
|
28
|
-
# [2.8.0](https://github.com/ayonious/console-table-printer/compare/v2.7.5...v2.8.0) (2021-03-06)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
### Features
|
|
32
|
-
|
|
33
|
-
* Width Limit ([#343](https://github.com/ayonious/console-table-printer/issues/343)) ([f5a541b](https://github.com/ayonious/console-table-printer/commit/f5a541ba39d22cbe37cbbd8100b3b740b4247ba3))
|
|
34
|
-
|
|
35
|
-
## [2.7.5](https://github.com/ayonious/console-table-printer/compare/v2.7.4...v2.7.5) (2020-12-08)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
### Bug Fixes
|
|
39
|
-
|
|
40
|
-
* **technical:** migrate to yarn and fix deployment ([0a1babb](https://github.com/ayonious/console-table-printer/commit/0a1babb87ec404da68471517dcca9a5595a03e81))
|
|
41
|
-
|
|
42
|
-
## [2.7.4](https://github.com/ayonious/console-table-printer/compare/v2.7.3...v2.7.4) (2020-12-08)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
### Bug Fixes
|
|
46
|
-
|
|
47
|
-
* Asian Languages width fixing with simple-wcswidth ([a14272f](https://github.com/ayonious/console-table-printer/commit/a14272f6738310cc21492c38adf71fac06b2a9dd))
|
|
48
|
-
|
|
49
|
-
## [2.7.3](https://github.com/ayonious/console-table-printer/compare/v2.7.2...v2.7.3) (2020-12-06)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
### Bug Fixes
|
|
53
|
-
|
|
54
|
-
* 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))
|
|
55
|
-
|
|
56
|
-
## [2.7.2](https://github.com/ayonious/console-table-printer/compare/v2.7.1...v2.7.2) (2020-12-06)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
### Bug Fixes
|
|
60
|
-
|
|
61
|
-
* 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))
|
|
62
|
-
|
|
63
|
-
## [2.7.1](https://github.com/ayonious/console-table-printer/compare/v2.7.0...v2.7.1) (2020-12-05)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
### Bug Fixes
|
|
67
|
-
|
|
68
|
-
* **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))
|
|
69
|
-
|
|
70
|
-
# [2.7.0](https://github.com/ayonious/console-table-printer/compare/v2.6.0...v2.7.0) (2020-12-05)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
### Features
|
|
74
|
-
|
|
75
|
-
* 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))
|
|
76
|
-
|
|
77
|
-
# [2.6.0](https://github.com/ayonious/console-table-printer/compare/v2.5.1...v2.6.0) (2020-12-04)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
### Features
|
|
81
|
-
|
|
82
|
-
* Allow cell coloring ([#317](https://github.com/ayonious/console-table-printer/issues/317)) ([1026d51](https://github.com/ayonious/console-table-printer/commit/1026d5136240228b6e44d29afee45f1a6350ad07))
|
|
83
|
-
|
|
84
|
-
## [2.5.1](https://github.com/ayonious/console-table-printer/compare/v2.5.0...v2.5.1) (2020-11-07)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
### Bug Fixes
|
|
88
|
-
|
|
89
|
-
* **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))
|
|
90
|
-
|
|
91
|
-
# [2.5.0](https://github.com/ayonious/console-table-printer/compare/v2.4.36...v2.5.0) (2020-11-04)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
### Features
|
|
95
|
-
|
|
96
|
-
* **technical:** semantic release ([#288](https://github.com/ayonious/console-table-printer/issues/288)) ([3121382](https://github.com/ayonious/console-table-printer/commit/31213829a2b8e1e6f6aa9ee0b34e6a0450816952))
|