console-table-printer 2.13.0 → 2.14.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 +12 -25
- package/dist/src/internalTable/input-converter.d.ts +2 -8
- package/dist/src/internalTable/internal-table-printer.d.ts +3 -2
- package/dist/src/internalTable/internal-table-printer.js +4 -4
- package/dist/src/internalTable/internal-table.d.ts +2 -1
- package/dist/src/internalTable/internal-table.js +2 -3
- package/dist/src/internalTable/table-pre-processors.js +9 -3
- package/dist/src/models/external-table.d.ts +8 -7
- package/dist/src/utils/table-helpers.d.ts +0 -2
- package/dist/src/utils/table-helpers.js +1 -7
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,24 +1,11 @@
|
|
|
1
1
|
<h1 align="center">console-table-printer</h1>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
</a>
|
|
10
|
-
<a href="https://packagephobia.now.sh/result?p=console-table-printer">
|
|
11
|
-
<img alt="install size" src="https://packagephobia.now.sh/badge?p=console-table-printer@latest">
|
|
12
|
-
</a>
|
|
13
|
-
</p>
|
|
14
|
-
<p align="center">
|
|
15
|
-
<a href="https://github.com/prettier/prettier">
|
|
16
|
-
<img alt="code style: prettier" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=plastic">
|
|
17
|
-
</a>
|
|
18
|
-
<a href="https://github.com/semantic-release/semantic-release">
|
|
19
|
-
<img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
|
|
20
|
-
</a>
|
|
21
|
-
</p>
|
|
2
|
+
|
|
3
|
+
> 🖥️🍭Printing Pretty Tables on your console</h3>
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
[](https://packagephobia.com/result?p=console-table-printer)
|
|
7
|
+
[](https://badge.fury.io/js/console-table-printer)
|
|
8
|
+
[](https://codecov.io/gh/console-table-printer/console-table-printer)
|
|
22
9
|
|
|
23
10
|
## Synopsis
|
|
24
11
|
|
|
@@ -45,7 +32,7 @@ const testCases = [
|
|
|
45
32
|
printTable(testCases);
|
|
46
33
|
```
|
|
47
34
|
|
|
48
|
-

|
|
49
36
|
|
|
50
37
|
## 🚨🚨Announcement🚨🚨 Official Documentation is moved [Here](https://console-table.netlify.app/docs)
|
|
51
38
|
|
|
@@ -70,7 +57,7 @@ p.addRows([
|
|
|
70
57
|
p.printTable();
|
|
71
58
|
```
|
|
72
59
|
|
|
73
|
-

|
|
74
61
|
|
|
75
62
|
You can also put some color to your table like this:
|
|
76
63
|
|
|
@@ -82,7 +69,7 @@ p.addRow({ description: 'gelb bananen', value: 100 }, { color: 'yellow' });
|
|
|
82
69
|
p.printTable();
|
|
83
70
|
```
|
|
84
71
|
|
|
85
|
-

|
|
86
73
|
|
|
87
74
|
You can also put properties based on columns (color/alignment/title)
|
|
88
75
|
|
|
@@ -112,7 +99,7 @@ p.addRow({ id: 3, text: 'rosa hemd wie immer', value: 100 }, { color: 'cyan' });
|
|
|
112
99
|
p.printTable();
|
|
113
100
|
```
|
|
114
101
|
|
|
115
|
-

|
|
116
103
|
|
|
117
104
|
## CLI
|
|
118
105
|
|
|
@@ -195,4 +182,4 @@ You can get color / alignment as types. Check Docs: [types-docs](https://console
|
|
|
195
182
|
|
|
196
183
|
## License
|
|
197
184
|
|
|
198
|
-
[MIT](https://github.com/
|
|
185
|
+
[MIT](https://github.com/console-table-printer/console-table-printer/blob/master/LICENSE)
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ColumnOptionsRaw } from '../models/external-table';
|
|
1
|
+
import { ColumnOptionsRaw, ComputedColumn, DefaultColumnOptions } from '../models/external-table';
|
|
3
2
|
import { Column } from '../models/internal-table';
|
|
4
3
|
export declare const objIfExists: (key: string, val: any) => {
|
|
5
4
|
[x: string]: any;
|
|
6
5
|
};
|
|
7
|
-
export declare const rawColumnToInternalColumn: (column: ColumnOptionsRaw, defaultColumnStyles?:
|
|
8
|
-
alignment?: ALIGNMENT;
|
|
9
|
-
color?: COLOR;
|
|
10
|
-
maxLen?: number;
|
|
11
|
-
minLen?: number;
|
|
12
|
-
}) => Column;
|
|
6
|
+
export declare const rawColumnToInternalColumn: (column: ColumnOptionsRaw | ComputedColumn, defaultColumnStyles?: DefaultColumnOptions) => Column;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { ComplexOptions } from '../models/external-table';
|
|
1
2
|
import TableInternal from './internal-table';
|
|
2
3
|
export declare const renderTable: (table: TableInternal) => string;
|
|
3
|
-
export declare const renderSimpleTable: (rows: any[]) => string;
|
|
4
|
-
export declare const printSimpleTable: (rows: any[]) => void;
|
|
4
|
+
export declare const renderSimpleTable: (rows: any[], tableOptions?: ComplexOptions) => string;
|
|
5
|
+
export declare const printSimpleTable: (rows: any[], tableOptions?: ComplexOptions) => void;
|
|
@@ -114,13 +114,13 @@ const renderTable = (table) => {
|
|
|
114
114
|
return ret.join('\n');
|
|
115
115
|
};
|
|
116
116
|
exports.renderTable = renderTable;
|
|
117
|
-
const renderSimpleTable = (rows) => {
|
|
118
|
-
const table = new internal_table_1.default();
|
|
117
|
+
const renderSimpleTable = (rows, tableOptions) => {
|
|
118
|
+
const table = new internal_table_1.default(tableOptions);
|
|
119
119
|
table.addRows(rows);
|
|
120
120
|
return (0, exports.renderTable)(table);
|
|
121
121
|
};
|
|
122
122
|
exports.renderSimpleTable = renderSimpleTable;
|
|
123
|
-
const printSimpleTable = (rows) => {
|
|
124
|
-
console.log((0, exports.renderSimpleTable)(rows));
|
|
123
|
+
const printSimpleTable = (rows, tableOptions) => {
|
|
124
|
+
console.log((0, exports.renderSimpleTable)(rows, tableOptions));
|
|
125
125
|
};
|
|
126
126
|
exports.printSimpleTable = printSimpleTable;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CharLengthDict, Dictionary, Row } from '../models/common';
|
|
2
|
-
import { ColumnOptionsRaw, ComplexOptions, ComputedColumn, RowFilterFunction, RowSortFunction } from '../models/external-table';
|
|
2
|
+
import { ColumnOptionsRaw, ComplexOptions, ComputedColumn, DefaultColumnOptions, RowFilterFunction, RowSortFunction } from '../models/external-table';
|
|
3
3
|
import { Column, TableStyleDetails } from '../models/internal-table';
|
|
4
4
|
import { ColorMap } from '../utils/colored-console-line';
|
|
5
5
|
import { RowOptions } from '../utils/table-helpers';
|
|
@@ -16,6 +16,7 @@ declare class TableInternal {
|
|
|
16
16
|
rowSeparator: boolean;
|
|
17
17
|
colorMap: ColorMap;
|
|
18
18
|
charLength: CharLengthDict;
|
|
19
|
+
defaultColumnOptions?: DefaultColumnOptions;
|
|
19
20
|
initSimple(columns: string[]): void;
|
|
20
21
|
initDetailed(options: ComplexOptions): void;
|
|
21
22
|
constructor(options?: ComplexOptions | string[]);
|
|
@@ -28,6 +28,7 @@ class TableInternal {
|
|
|
28
28
|
((_a = options === null || options === void 0 ? void 0 : options.columns) === null || _a === void 0 ? void 0 : _a.map((column) => (0, input_converter_1.rawColumnToInternalColumn)(column, options === null || options === void 0 ? void 0 : options.defaultColumnOptions))) || this.columns;
|
|
29
29
|
this.rowSeparator = (options === null || options === void 0 ? void 0 : options.rowSeparator) || this.rowSeparator;
|
|
30
30
|
this.charLength = (options === null || options === void 0 ? void 0 : options.charLength) || this.charLength;
|
|
31
|
+
this.defaultColumnOptions = (options === null || options === void 0 ? void 0 : options.defaultColumnOptions) || this.defaultColumnOptions;
|
|
31
32
|
if (options === null || options === void 0 ? void 0 : options.shouldDisableColors) {
|
|
32
33
|
this.colorMap = {};
|
|
33
34
|
}
|
|
@@ -52,6 +53,7 @@ class TableInternal {
|
|
|
52
53
|
this.rowSeparator = table_constants_1.DEFAULT_ROW_SEPARATOR;
|
|
53
54
|
this.colorMap = colored_console_line_1.DEFAULT_COLOR_MAP;
|
|
54
55
|
this.charLength = {};
|
|
56
|
+
this.defaultColumnOptions = undefined;
|
|
55
57
|
if (options instanceof Array) {
|
|
56
58
|
this.initSimple(options);
|
|
57
59
|
}
|
|
@@ -71,9 +73,6 @@ class TableInternal {
|
|
|
71
73
|
if (typeof textOrObj === 'string') {
|
|
72
74
|
this.columns.push((0, table_helpers_1.createColumFromOnlyName)(textOrObj));
|
|
73
75
|
}
|
|
74
|
-
else if ('function' in textOrObj) { // Only way to know if this is a computed column
|
|
75
|
-
this.columns.push((0, table_helpers_1.createColumFromComputedColumn)(textOrObj));
|
|
76
|
-
}
|
|
77
76
|
else {
|
|
78
77
|
this.columns.push((0, input_converter_1.rawColumnToInternalColumn)(textOrObj));
|
|
79
78
|
}
|
|
@@ -2,12 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.preProcessRows = exports.preProcessColumns = void 0;
|
|
4
4
|
const table_helpers_1 = require("../utils/table-helpers");
|
|
5
|
+
// All these functions are ran when renderTable/printTable is called
|
|
5
6
|
const createComputedColumnsIfNecessary = (table) => {
|
|
6
7
|
if (table.computedColumns.length) {
|
|
7
8
|
table.computedColumns.forEach((computedColumn) => {
|
|
8
|
-
|
|
9
|
-
table.
|
|
10
|
-
|
|
9
|
+
// This can happen if renderTable/printTable is called multiple times
|
|
10
|
+
const isColumnAlreadyExists = table.columns.some((col) => col.name === computedColumn.name);
|
|
11
|
+
if (isColumnAlreadyExists) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
table.addColumn(Object.assign(Object.assign({}, computedColumn), table.defaultColumnOptions));
|
|
15
|
+
table.rows.forEach((row, index, rowsArray) => {
|
|
16
|
+
const arrayRowText = rowsArray.map((elemInRowsArray) => elemInRowsArray.text);
|
|
11
17
|
row.text[computedColumn.name] = computedColumn.function(row.text, index, arrayRowText);
|
|
12
18
|
});
|
|
13
19
|
});
|
|
@@ -15,6 +15,13 @@ export interface ComputedColumn extends ColumnOptionsRaw {
|
|
|
15
15
|
}
|
|
16
16
|
export type RowSortFunction = (row1: any, row2: any) => number;
|
|
17
17
|
export type RowFilterFunction = (row: any) => Boolean;
|
|
18
|
+
export interface DefaultColumnOptions {
|
|
19
|
+
alignment?: ALIGNMENT;
|
|
20
|
+
color?: COLOR;
|
|
21
|
+
title?: string;
|
|
22
|
+
maxLen?: number;
|
|
23
|
+
minLen?: number;
|
|
24
|
+
}
|
|
18
25
|
export interface ComplexOptions {
|
|
19
26
|
style?: TableStyleDetails;
|
|
20
27
|
title?: string;
|
|
@@ -29,11 +36,5 @@ export interface ComplexOptions {
|
|
|
29
36
|
shouldDisableColors?: boolean;
|
|
30
37
|
colorMap?: ColorMap;
|
|
31
38
|
charLength?: CharLengthDict;
|
|
32
|
-
defaultColumnOptions?:
|
|
33
|
-
alignment?: ALIGNMENT;
|
|
34
|
-
color?: COLOR;
|
|
35
|
-
title?: string;
|
|
36
|
-
maxLen?: number;
|
|
37
|
-
minLen?: number;
|
|
38
|
-
};
|
|
39
|
+
defaultColumnOptions?: DefaultColumnOptions;
|
|
39
40
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CharLengthDict, COLOR, Dictionary, Row } from '../models/common';
|
|
2
|
-
import { ComputedColumn } from '../models/external-table';
|
|
3
2
|
import { Column } from '../models/internal-table';
|
|
4
3
|
export declare const cellText: (text: string | number) => string;
|
|
5
4
|
export interface RowOptionsRaw {
|
|
@@ -18,7 +17,6 @@ export declare const createTableHorizontalBorders: ({ left, mid, right, other, }
|
|
|
18
17
|
other: string;
|
|
19
18
|
}, column_lengths: number[]) => string;
|
|
20
19
|
export declare const createColumFromOnlyName: (name: string) => Column;
|
|
21
|
-
export declare const createColumFromComputedColumn: (column: ComputedColumn) => Column;
|
|
22
20
|
export declare const createRow: (color: COLOR, text: Dictionary, separator: boolean) => Row;
|
|
23
21
|
export declare const findLenOfColumn: (column: Column, rows: Row[], charLength?: CharLengthDict) => number;
|
|
24
22
|
export declare const renderTableHorizontalBorders: (style: any, column_lengths: number[]) => string;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getWidthLimitedColumnsArray = exports.createHeaderAsRow = exports.renderTableHorizontalBorders = exports.findLenOfColumn = exports.createRow = exports.
|
|
4
|
-
const input_converter_1 = require("../internalTable/input-converter");
|
|
3
|
+
exports.getWidthLimitedColumnsArray = exports.createHeaderAsRow = exports.renderTableHorizontalBorders = exports.findLenOfColumn = exports.createRow = exports.createColumFromOnlyName = exports.createTableHorizontalBorders = exports.convertRawRowOptionsToStandard = exports.cellText = void 0;
|
|
5
4
|
const console_utils_1 = require("./console-utils");
|
|
6
5
|
const string_utils_1 = require("./string-utils");
|
|
7
6
|
const table_constants_1 = require("./table-constants");
|
|
@@ -39,11 +38,6 @@ const createColumFromOnlyName = (name) => ({
|
|
|
39
38
|
title: name,
|
|
40
39
|
});
|
|
41
40
|
exports.createColumFromOnlyName = createColumFromOnlyName;
|
|
42
|
-
const createColumFromComputedColumn = (column) => {
|
|
43
|
-
var _a;
|
|
44
|
-
return (Object.assign(Object.assign(Object.assign(Object.assign({ name: column.name, title: (_a = column.title) !== null && _a !== void 0 ? _a : 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;
|
|
47
41
|
const createRow = (color, text, separator) => ({
|
|
48
42
|
color,
|
|
49
43
|
separator,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "console-table-printer",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"repository": "github:
|
|
3
|
+
"version": "2.14.1",
|
|
4
|
+
"repository": "github:console-table-printer/console-table-printer",
|
|
5
5
|
"description": "Printing pretty tables on console log",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"build": "tsc",
|
|
11
11
|
"format": "prettier --write \"**/*.{json,md,ts,tsx,yml,js,jsx}\"",
|
|
12
12
|
"test": "jest --config jestconfig.json",
|
|
13
|
+
"test:coverage": "jest --config jestconfig.json --coverage",
|
|
13
14
|
"lint": "eslint --ext=js,ts .",
|
|
14
15
|
"semantic-release": "semantic-release"
|
|
15
16
|
},
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
"jest": "^29.7.0",
|
|
40
41
|
"prettier": "^3.5.3",
|
|
41
42
|
"pretty-quick": "^4.1.1",
|
|
42
|
-
"semantic-release": "^24.2.
|
|
43
|
+
"semantic-release": "^24.2.5",
|
|
43
44
|
"ts-jest": "^29.3.4",
|
|
44
45
|
"typescript": "^5.8.3"
|
|
45
46
|
},
|