console-table-printer 2.11.2 → 2.12.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 CHANGED
@@ -37,15 +37,15 @@ const { printTable } = require('console-table-printer');
37
37
 
38
38
  //Create a table
39
39
  const testCases = [
40
- { index: 3, text: 'I would like some gelb bananen bitte', value: 100 },
41
- { index: 4, text: 'I hope batch update is working', value: 300 },
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
- ![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/quick-print.png)
48
+ ![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/readme-quick-1.png)
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({ index: 1, text: 'red wine please', value: 10.212 });
62
- p.addRow({ index: 2, text: 'green gemuse please', value: 20.0 });
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
- { index: 3, text: 'gelb bananen bitte', value: 100 },
66
- { index: 4, text: 'update is working', value: 300 },
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
- ![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/screenshot-simple.png)
73
+ ![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/readme-instance-1.png)
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({ index: 1, text: 'red wine', value: 10.212 }, { color: 'red' });
80
- p.addRow({ index: 2, text: 'green gemuse', value: 20.0 }, { color: 'green' });
81
- p.addRow({ index: 3, text: 'gelb bananen', value: 100 }, { color: 'yellow' });
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
- ![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/screenshot-colored.png)
85
+ ![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/readme-color-1.png)
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: 'index', alignment: 'left', color: 'blue' }, // with alignment and color
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({ index: 1, text: 'red wine', value: 10.212 }, { color: 'green' });
101
+ p.addRow({ id: 1, text: 'red wine', value: 10.212 }, { color: 'green' });
102
102
  p.addRow(
103
- { index: 2, text: 'green gemuse', value: 20.0 },
103
+ { id: 2, text: 'green gemuse', value: 20.0 },
104
104
  { color: 'custom_green' } // your green
105
105
  );
106
106
  p.addRow(
107
- { index: 3, text: 'gelb bananen', value: 100, is_priority_today: 'Y' },
107
+ { id: 3, text: 'gelb bananen', value: 100, is_priority_today: 'Y' },
108
108
  { color: 'yellow' }
109
109
  );
110
- p.addRow(
111
- { index: 3, text: 'rosa hemd wie immer', value: 100 },
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
- ![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/screenshot-column-props-2.png)
115
+ ![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/readme-columns-1.png)
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.colorMap) {
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) {
@@ -26,6 +26,7 @@ export interface ComplexOptions {
26
26
  disabledColumns?: string[];
27
27
  computedColumns?: ComputedColumn[];
28
28
  rowSeparator?: boolean;
29
+ shouldDisableColors?: boolean;
29
30
  colorMap?: ColorMap;
30
31
  charLength?: CharLengthDict;
31
32
  }
@@ -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,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.biggestWordInSentence = exports.limitWidth = exports.textWithPadding = void 0;
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 spaceSeparatedStrings = inpStr.split(' ');
9
+ let now = [];
10
+ let cnt = 0;
11
+ spaceSeparatedStrings.forEach((strWithoutSpace) => {
12
+ const consoleWidth = (0, console_utils_1.findWidthInConsole)(strWithoutSpace, charLength);
13
+ if (cnt + consoleWidth <= width) {
14
+ cnt += consoleWidth + 1; // 1 for the space
15
+ now.push(strWithoutSpace);
16
+ }
17
+ else {
18
+ ret.push(now.join(' '));
19
+ now = [strWithoutSpace];
20
+ cnt = consoleWidth + 1;
21
+ }
22
+ });
23
+ ret.push(now.join(' '));
24
+ return ret;
25
+ };
26
+ exports.splitTextIntoTextsOfMinLen = splitTextIntoTextsOfMinLen;
5
27
  // ("How are you?",center, 20) => " How are you? "
6
28
  // ("How are you?",right, 20) => " How are you?"
29
+ // ("How are you?",center, 4) => "How\nare\nyou?"
7
30
  const textWithPadding = (text, alignment, columnLen, charLength) => {
8
31
  const curTextSize = (0, console_utils_1.findWidthInConsole)(text, charLength);
9
32
  // alignments for center padding case
@@ -11,7 +34,13 @@ const textWithPadding = (text, alignment, columnLen, charLength) => {
11
34
  const rightPadding = columnLen - leftPadding - curTextSize;
12
35
  // handle edge cases where the text size is larger than the column length
13
36
  if (columnLen < curTextSize) {
14
- return text;
37
+ const splittedLines = (0, exports.splitTextIntoTextsOfMinLen)(text, columnLen);
38
+ if (splittedLines.length === 1) {
39
+ return text;
40
+ }
41
+ return splittedLines
42
+ .map((singleLine) => (0, exports.textWithPadding)(singleLine, alignment, columnLen, charLength))
43
+ .join('\n');
15
44
  }
16
45
  // console.log(text, columnLen, curTextSize);
17
46
  switch (alignment) {
@@ -29,28 +58,6 @@ const textWithPadding = (text, alignment, columnLen, charLength) => {
29
58
  };
30
59
  exports.textWithPadding = textWithPadding;
31
60
  // ("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
61
  const biggestWordInSentence = (inpStr, charLength) => inpStr
55
62
  .split(' ')
56
63
  .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.limitWidth)((0, exports.cellText)(row.text[column.name]), column.length || table_constants_1.DEFAULT_COLUMN_LEN, charLength);
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.11.2",
3
+ "version": "2.12.0",
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.2",
31
- "@typescript-eslint/eslint-plugin": "^5.60.1",
32
- "@typescript-eslint/parser": "^5.60.1",
33
- "chalk": "^4.1.2",
34
- "eslint": "^8.44.0",
30
+ "@types/jest": "^29.5.11",
31
+ "@typescript-eslint/eslint-plugin": "^6.15.0",
32
+ "@typescript-eslint/parser": "^6.15.0",
33
+ "eslint": "^8.56.0",
35
34
  "eslint-config-airbnb-base": "^15.0.0",
36
- "eslint-config-prettier": "^8.8.0",
37
- "eslint-plugin-import": "^2.27.5",
38
- "eslint-plugin-prettier": "^4.2.1",
35
+ "eslint-config-prettier": "^9.1.0",
36
+ "eslint-plugin-import": "^2.29.1",
37
+ "eslint-plugin-prettier": "^5.1.0",
39
38
  "husky": "^8.0.3",
40
- "jest": "^29.5.0",
41
- "prettier": "^2.8.8",
39
+ "jest": "^29.7.0",
40
+ "prettier": "^3.1.1",
42
41
  "pretty-quick": "^3.1.3",
43
- "semantic-release": "^21.0.6",
42
+ "semantic-release": "^22.0.12",
44
43
  "ts-jest": "^29.1.1",
45
- "typescript": "^5.1.6"
44
+ "typescript": "^5.3.3"
46
45
  },
47
46
  "homepage": "https://console-table.netlify.app",
48
47
  "dependencies": {