console-table-printer 2.12.1 → 2.13.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
@@ -152,6 +152,12 @@ new Table({
152
152
  '👋': 2,
153
153
  '😅': 2,
154
154
  }, // custom len of chars in console
155
+ defaultColumnOptions: {
156
+ alignment: 'center',
157
+ color: 'red',
158
+ maxLen: 40,
159
+ minLen: 20,
160
+ },
155
161
  });
156
162
  ```
157
163
 
@@ -189,4 +195,4 @@ You can get color / alignment as types. Check Docs: [types-docs](https://console
189
195
 
190
196
  ## License
191
197
 
192
- [MIT](https://github.com/ayonious/console-table-printer/blob/master/LICENSE)
198
+ [MIT](https://github.com/ayonious/console-table-printer/blob/master/LICENSE)
@@ -1,12 +1,12 @@
1
1
  import TableInternal from './internalTable/internal-table';
2
2
  import { Dictionary } from './models/common';
3
- import { ComplexOptions } from './models/external-table';
3
+ import { ColumnOptionsRaw, ComplexOptions } from './models/external-table';
4
4
  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): this;
9
- addColumns(columns: string[]): this;
8
+ addColumn(column: string | ColumnOptionsRaw): this;
9
+ addColumns(columns: string[] | ColumnOptionsRaw[]): this;
10
10
  addRow(text: Dictionary, rowOptions?: RowOptionsRaw): this;
11
11
  addRows(toBeInsertedRows: any, rowOptions?: RowOptionsRaw): this;
12
12
  printTable(): void;
@@ -1,6 +1,12 @@
1
+ import { ALIGNMENT, COLOR } from '../models/common';
1
2
  import { ColumnOptionsRaw } from '../models/external-table';
2
3
  import { Column } from '../models/internal-table';
3
4
  export declare const objIfExists: (key: string, val: any) => {
4
5
  [x: string]: any;
5
6
  };
6
- export declare const rawColumnToInternalColumn: (column: ColumnOptionsRaw) => Column;
7
+ export declare const rawColumnToInternalColumn: (column: ColumnOptionsRaw, defaultColumnStyles?: {
8
+ alignment?: ALIGNMENT;
9
+ color?: COLOR;
10
+ maxLen?: number;
11
+ minLen?: number;
12
+ }) => Column;
@@ -11,8 +11,8 @@ const objIfExists = (key, val) => {
11
11
  };
12
12
  };
13
13
  exports.objIfExists = objIfExists;
14
- const rawColumnToInternalColumn = (column) => {
14
+ const rawColumnToInternalColumn = (column, defaultColumnStyles) => {
15
15
  var _a;
16
- return (Object.assign(Object.assign(Object.assign(Object.assign({ name: column.name, title: (_a = column.title) !== null && _a !== void 0 ? _a : 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 }));
16
+ return (Object.assign(Object.assign(Object.assign(Object.assign({ name: column.name, title: (_a = column.title) !== null && _a !== void 0 ? _a : column.name }, (0, exports.objIfExists)('color', (column.color || (defaultColumnStyles === null || defaultColumnStyles === void 0 ? void 0 : defaultColumnStyles.color)))), (0, exports.objIfExists)('maxLen', (column.maxLen || (defaultColumnStyles === null || defaultColumnStyles === void 0 ? void 0 : defaultColumnStyles.maxLen)))), (0, exports.objIfExists)('minLen', (column.minLen || (defaultColumnStyles === null || defaultColumnStyles === void 0 ? void 0 : defaultColumnStyles.minLen)))), { alignment: (column.alignment || (defaultColumnStyles === null || defaultColumnStyles === void 0 ? void 0 : defaultColumnStyles.alignment) || table_constants_1.DEFAULT_ROW_ALIGNMENT) }));
17
17
  };
18
18
  exports.rawColumnToInternalColumn = rawColumnToInternalColumn;
@@ -1,5 +1,5 @@
1
1
  import { CharLengthDict, Dictionary, Row } from '../models/common';
2
- import { ComplexOptions, ComputedColumn, RowFilterFunction, RowSortFunction } from '../models/external-table';
2
+ import { ColumnOptionsRaw, ComplexOptions, ComputedColumn, 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';
@@ -20,8 +20,8 @@ declare class TableInternal {
20
20
  initDetailed(options: ComplexOptions): void;
21
21
  constructor(options?: ComplexOptions | string[]);
22
22
  createColumnFromRow(text: Dictionary): void;
23
- addColumn(textOrObj: string | ComputedColumn): void;
24
- addColumns(toBeInsertedColumns: string[]): void;
23
+ addColumn(textOrObj: string | ComputedColumn | ColumnOptionsRaw): void;
24
+ addColumns(toBeInsertedColumns: string[] | ColumnOptionsRaw[]): void;
25
25
  addRow(text: Dictionary, options?: RowOptions): void;
26
26
  addRows(toBeInsertedRows: Dictionary[], options?: RowOptions): void;
27
27
  renderTable(): string;
@@ -25,7 +25,7 @@ class TableInternal {
25
25
  this.disabledColumns = (options === null || options === void 0 ? void 0 : options.disabledColumns) || this.disabledColumns;
26
26
  this.computedColumns = (options === null || options === void 0 ? void 0 : options.computedColumns) || this.computedColumns;
27
27
  this.columns =
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;
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
31
  if (options === null || options === void 0 ? void 0 : options.shouldDisableColors) {
@@ -71,9 +71,12 @@ class TableInternal {
71
71
  if (typeof textOrObj === 'string') {
72
72
  this.columns.push((0, table_helpers_1.createColumFromOnlyName)(textOrObj));
73
73
  }
74
- else {
74
+ else if ('function' in textOrObj) { // Only way to know if this is a computed column
75
75
  this.columns.push((0, table_helpers_1.createColumFromComputedColumn)(textOrObj));
76
76
  }
77
+ else {
78
+ this.columns.push((0, input_converter_1.rawColumnToInternalColumn)(textOrObj));
79
+ }
77
80
  }
78
81
  addColumns(toBeInsertedColumns) {
79
82
  toBeInsertedColumns.forEach((toBeInsertedColumn) => {
@@ -6,8 +6,9 @@ const createComputedColumnsIfNecessary = (table) => {
6
6
  if (table.computedColumns.length) {
7
7
  table.computedColumns.forEach((computedColumn) => {
8
8
  table.addColumn(computedColumn);
9
- table.rows.forEach((row) => {
10
- row.text[computedColumn.name] = computedColumn.function(row.text);
9
+ table.rows.forEach((row, index, array) => {
10
+ const arrayRowText = array.map(() => row.text);
11
+ row.text[computedColumn.name] = computedColumn.function(row.text, index, arrayRowText);
11
12
  });
12
13
  });
13
14
  }
@@ -11,7 +11,7 @@ export interface ColumnOptionsRaw {
11
11
  minLen?: number;
12
12
  }
13
13
  export interface ComputedColumn extends ColumnOptionsRaw {
14
- function: (arg0: any) => any;
14
+ function: (arg0: any, index: number, array: any[]) => any;
15
15
  }
16
16
  export type RowSortFunction = (row1: any, row2: any) => number;
17
17
  export type RowFilterFunction = (row: any) => Boolean;
@@ -29,4 +29,11 @@ export interface ComplexOptions {
29
29
  shouldDisableColors?: boolean;
30
30
  colorMap?: ColorMap;
31
31
  charLength?: CharLengthDict;
32
+ defaultColumnOptions?: {
33
+ alignment?: ALIGNMENT;
34
+ color?: COLOR;
35
+ title?: string;
36
+ maxLen?: number;
37
+ minLen?: number;
38
+ };
32
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "console-table-printer",
3
- "version": "2.12.1",
3
+ "version": "2.13.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,21 +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.12",
31
- "@typescript-eslint/eslint-plugin": "^7.13.1",
32
- "@typescript-eslint/parser": "^7.13.1",
33
- "eslint": "^9.5.0",
30
+ "@types/jest": "^29.5.14",
31
+ "@typescript-eslint/eslint-plugin": "^8.32.1",
32
+ "@typescript-eslint/parser": "^8.32.1",
33
+ "eslint": "^9.27.0",
34
34
  "eslint-config-airbnb-base": "^15.0.0",
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",
35
+ "eslint-config-prettier": "^10.1.5",
36
+ "eslint-plugin-import": "^2.31.0",
37
+ "eslint-plugin-prettier": "^5.4.0",
38
+ "husky": "^9.1.7",
39
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"
40
+ "prettier": "^3.5.3",
41
+ "pretty-quick": "^4.1.1",
42
+ "semantic-release": "^24.2.4",
43
+ "ts-jest": "^29.3.4",
44
+ "typescript": "^5.8.3"
45
45
  },
46
46
  "homepage": "https://console-table.netlify.app",
47
47
  "dependencies": {