console-table-printer 2.11.2 → 2.12.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
CHANGED
|
@@ -37,15 +37,15 @@ const { printTable } = require('console-table-printer');
|
|
|
37
37
|
|
|
38
38
|
//Create a table
|
|
39
39
|
const testCases = [
|
|
40
|
-
{
|
|
41
|
-
{
|
|
40
|
+
{ Rank: 3, text: 'I would like some Yellow', value: 100 },
|
|
41
|
+
{ Rank: 4, text: 'I hope batch update is working', value: 300 },
|
|
42
42
|
];
|
|
43
43
|
|
|
44
44
|
//print
|
|
45
45
|
printTable(testCases);
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-

|
|
49
49
|
|
|
50
50
|
## 🚨🚨Announcement🚨🚨 Official Documentation is moved [Here](https://console-table.netlify.app/docs)
|
|
51
51
|
|
|
@@ -57,39 +57,39 @@ const { Table } = require('console-table-printer');
|
|
|
57
57
|
//Create a table
|
|
58
58
|
const p = new Table();
|
|
59
59
|
|
|
60
|
-
//add rows with color
|
|
61
|
-
p.addRow({
|
|
62
|
-
p.addRow({
|
|
60
|
+
// add rows with color
|
|
61
|
+
p.addRow({ Record: 'a', text: 'red wine please', value: 10.212 });
|
|
62
|
+
p.addRow({ Record: 'b', text: 'green gemuse please', value: 20.0 });
|
|
63
63
|
p.addRows([
|
|
64
|
-
//adding multiple rows are possible
|
|
65
|
-
{
|
|
66
|
-
{
|
|
64
|
+
// adding multiple rows are possible
|
|
65
|
+
{ Record: 'c', text: 'gelb bananen bitte', value: 100 },
|
|
66
|
+
{ Record: 'd', text: 'update is working', value: 300 },
|
|
67
67
|
]);
|
|
68
68
|
|
|
69
69
|
//print
|
|
70
70
|
p.printTable();
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-

|
|
74
74
|
|
|
75
75
|
You can also put some color to your table like this:
|
|
76
76
|
|
|
77
77
|
```javascript
|
|
78
78
|
const p = new Table();
|
|
79
|
-
p.addRow({
|
|
80
|
-
p.addRow({
|
|
81
|
-
p.addRow({
|
|
79
|
+
p.addRow({ description: 'red wine', value: 10.212 }, { color: 'red' });
|
|
80
|
+
p.addRow({ description: 'green gemuse', value: 20.0 }, { color: 'green' });
|
|
81
|
+
p.addRow({ description: 'gelb bananen', value: 100 }, { color: 'yellow' });
|
|
82
82
|
p.printTable();
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-

|
|
86
86
|
|
|
87
87
|
You can also put properties based on columns (color/alignment/title)
|
|
88
88
|
|
|
89
89
|
```javascript
|
|
90
90
|
const p = new Table({
|
|
91
91
|
columns: [
|
|
92
|
-
{ name: '
|
|
92
|
+
{ name: 'id', 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
|
],
|
|
@@ -98,23 +98,21 @@ const p = new Table({
|
|
|
98
98
|
},
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
-
p.addRow({
|
|
101
|
+
p.addRow({ id: 1, text: 'red wine', value: 10.212 }, { color: 'green' });
|
|
102
102
|
p.addRow(
|
|
103
|
-
{
|
|
103
|
+
{ id: 2, text: 'green gemuse', value: 20.0 },
|
|
104
104
|
{ color: 'custom_green' } // your green
|
|
105
105
|
);
|
|
106
106
|
p.addRow(
|
|
107
|
-
{
|
|
107
|
+
{ id: 3, text: 'gelb bananen', value: 100, is_priority_today: 'Y' },
|
|
108
108
|
{ color: 'yellow' }
|
|
109
109
|
);
|
|
110
|
-
p.addRow(
|
|
111
|
-
|
|
112
|
-
{ color: 'cyan' }
|
|
113
|
-
);
|
|
110
|
+
p.addRow({ id: 3, text: 'rosa hemd wie immer', value: 100 }, { color: 'cyan' });
|
|
111
|
+
|
|
114
112
|
p.printTable();
|
|
115
113
|
```
|
|
116
114
|
|
|
117
|
-

|
|
118
116
|
|
|
119
117
|
## CLI
|
|
120
118
|
|
|
@@ -28,7 +28,10 @@ class TableInternal {
|
|
|
28
28
|
((_a = options === null || options === void 0 ? void 0 : options.columns) === null || _a === void 0 ? void 0 : _a.map(input_converter_1.rawColumnToInternalColumn)) || 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
|
-
if (options === null || options === void 0 ? void 0 : options.
|
|
31
|
+
if (options === null || options === void 0 ? void 0 : options.shouldDisableColors) {
|
|
32
|
+
this.colorMap = {};
|
|
33
|
+
}
|
|
34
|
+
else if (options === null || options === void 0 ? void 0 : options.colorMap) {
|
|
32
35
|
this.colorMap = Object.assign(Object.assign({}, this.colorMap), options.colorMap);
|
|
33
36
|
}
|
|
34
37
|
if (options.rows !== undefined) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ALIGNMENT, CharLengthDict } from '../models/common';
|
|
2
|
+
export declare const splitTextIntoTextsOfMinLen: (inpStr: string, width: number, charLength?: CharLengthDict) => string[];
|
|
2
3
|
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
4
|
export declare const biggestWordInSentence: (inpStr: string, charLength?: CharLengthDict) => number;
|
|
@@ -1,9 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.biggestWordInSentence = exports.
|
|
3
|
+
exports.biggestWordInSentence = exports.textWithPadding = exports.splitTextIntoTextsOfMinLen = void 0;
|
|
4
4
|
const console_utils_1 = require("./console-utils");
|
|
5
|
+
// ("How are you?",10) => ["How are ", "you?"]
|
|
6
|
+
const splitTextIntoTextsOfMinLen = (inpStr, width, charLength) => {
|
|
7
|
+
const ret = [];
|
|
8
|
+
const lines = inpStr.split(/[\n\r]/);
|
|
9
|
+
lines.forEach((line) => {
|
|
10
|
+
const spaceSeparatedStrings = line.split(' ');
|
|
11
|
+
let now = [];
|
|
12
|
+
let cnt = 0;
|
|
13
|
+
spaceSeparatedStrings.forEach((strWithoutSpace) => {
|
|
14
|
+
const consoleWidth = (0, console_utils_1.findWidthInConsole)(strWithoutSpace, charLength);
|
|
15
|
+
if (cnt + consoleWidth <= width) {
|
|
16
|
+
cnt += consoleWidth + 1; // 1 for the space
|
|
17
|
+
now.push(strWithoutSpace);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
if (now.length > 0)
|
|
21
|
+
ret.push(now.join(' '));
|
|
22
|
+
now = [strWithoutSpace];
|
|
23
|
+
cnt = consoleWidth + 1;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
ret.push(now.join(' '));
|
|
27
|
+
});
|
|
28
|
+
return ret;
|
|
29
|
+
};
|
|
30
|
+
exports.splitTextIntoTextsOfMinLen = splitTextIntoTextsOfMinLen;
|
|
5
31
|
// ("How are you?",center, 20) => " How are you? "
|
|
6
32
|
// ("How are you?",right, 20) => " How are you?"
|
|
33
|
+
// ("How are you?",center, 4) => "How\nare\nyou?"
|
|
7
34
|
const textWithPadding = (text, alignment, columnLen, charLength) => {
|
|
8
35
|
const curTextSize = (0, console_utils_1.findWidthInConsole)(text, charLength);
|
|
9
36
|
// alignments for center padding case
|
|
@@ -11,7 +38,13 @@ const textWithPadding = (text, alignment, columnLen, charLength) => {
|
|
|
11
38
|
const rightPadding = columnLen - leftPadding - curTextSize;
|
|
12
39
|
// handle edge cases where the text size is larger than the column length
|
|
13
40
|
if (columnLen < curTextSize) {
|
|
14
|
-
|
|
41
|
+
const splittedLines = (0, exports.splitTextIntoTextsOfMinLen)(text, columnLen);
|
|
42
|
+
if (splittedLines.length === 1) {
|
|
43
|
+
return text;
|
|
44
|
+
}
|
|
45
|
+
return splittedLines
|
|
46
|
+
.map((singleLine) => (0, exports.textWithPadding)(singleLine, alignment, columnLen, charLength))
|
|
47
|
+
.join('\n');
|
|
15
48
|
}
|
|
16
49
|
// console.log(text, columnLen, curTextSize);
|
|
17
50
|
switch (alignment) {
|
|
@@ -29,28 +62,6 @@ const textWithPadding = (text, alignment, columnLen, charLength) => {
|
|
|
29
62
|
};
|
|
30
63
|
exports.textWithPadding = textWithPadding;
|
|
31
64
|
// ("How are you?",10) => ["How are ", "you?"]
|
|
32
|
-
const limitWidth = (inpStr, width, charLength) => {
|
|
33
|
-
const ret = [];
|
|
34
|
-
const spaceSeparatedStrings = inpStr.split(' ');
|
|
35
|
-
let now = [];
|
|
36
|
-
let cnt = 0;
|
|
37
|
-
spaceSeparatedStrings.forEach((strWithoutSpace) => {
|
|
38
|
-
const consoleWidth = (0, console_utils_1.findWidthInConsole)(strWithoutSpace, charLength);
|
|
39
|
-
if (cnt + consoleWidth <= width) {
|
|
40
|
-
cnt += consoleWidth + 1; // 1 for the space
|
|
41
|
-
now.push(strWithoutSpace);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
ret.push(now.join(' '));
|
|
45
|
-
now = [strWithoutSpace];
|
|
46
|
-
cnt = consoleWidth + 1;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
ret.push(now.join(' '));
|
|
50
|
-
return ret;
|
|
51
|
-
};
|
|
52
|
-
exports.limitWidth = limitWidth;
|
|
53
|
-
// ("How are you?",10) => ["How are ", "you?"]
|
|
54
65
|
const biggestWordInSentence = (inpStr, charLength) => inpStr
|
|
55
66
|
.split(' ')
|
|
56
67
|
.reduce((a, b) => Math.max(a, (0, console_utils_1.findWidthInConsole)(b, charLength)), 0);
|
|
@@ -86,7 +86,7 @@ exports.createHeaderAsRow = createHeaderAsRow;
|
|
|
86
86
|
const getWidthLimitedColumnsArray = (columns, row, charLength) => {
|
|
87
87
|
const ret = {};
|
|
88
88
|
columns.forEach((column) => {
|
|
89
|
-
ret[column.name] = (0, string_utils_1.
|
|
89
|
+
ret[column.name] = (0, string_utils_1.splitTextIntoTextsOfMinLen)((0, exports.cellText)(row.text[column.name]), column.length || table_constants_1.DEFAULT_COLUMN_LEN, charLength);
|
|
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.12.1",
|
|
4
4
|
"repository": "github:ayonious/console-table-printer",
|
|
5
5
|
"description": "Printing pretty tables on console log",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,22 +27,21 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@semantic-release/changelog": "^6.0.3",
|
|
29
29
|
"@semantic-release/git": "^10.0.1",
|
|
30
|
-
"@types/jest": "^29.5.
|
|
31
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
32
|
-
"@typescript-eslint/parser": "^
|
|
33
|
-
"
|
|
34
|
-
"eslint": "^8.44.0",
|
|
30
|
+
"@types/jest": "^29.5.12",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^7.13.1",
|
|
32
|
+
"@typescript-eslint/parser": "^7.13.1",
|
|
33
|
+
"eslint": "^9.5.0",
|
|
35
34
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
36
|
-
"eslint-config-prettier": "^
|
|
37
|
-
"eslint-plugin-import": "^2.
|
|
38
|
-
"eslint-plugin-prettier": "^
|
|
39
|
-
"husky": "^
|
|
40
|
-
"jest": "^29.
|
|
41
|
-
"prettier": "^
|
|
42
|
-
"pretty-quick": "^
|
|
43
|
-
"semantic-release": "^
|
|
44
|
-
"ts-jest": "^29.1.
|
|
45
|
-
"typescript": "^5.
|
|
35
|
+
"eslint-config-prettier": "^9.1.0",
|
|
36
|
+
"eslint-plugin-import": "^2.29.1",
|
|
37
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
38
|
+
"husky": "^9.0.11",
|
|
39
|
+
"jest": "^29.7.0",
|
|
40
|
+
"prettier": "^3.3.2",
|
|
41
|
+
"pretty-quick": "^4.0.0",
|
|
42
|
+
"semantic-release": "^24.0.0",
|
|
43
|
+
"ts-jest": "^29.1.5",
|
|
44
|
+
"typescript": "^5.4.5"
|
|
46
45
|
},
|
|
47
46
|
"homepage": "https://console-table.netlify.app",
|
|
48
47
|
"dependencies": {
|