console-table-printer 2.11.0 β†’ 2.11.2

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
@@ -45,10 +45,10 @@ const testCases = [
45
45
  printTable(testCases);
46
46
  ```
47
47
 
48
- Output:
49
-
50
48
  ![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/quick-print.png)
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
@@ -147,12 +147,19 @@ new Table({
147
147
  filter: (row) => row.column1 < 3, // filtering rows (optional)
148
148
  enabledColumns: ['column1'], // array of columns that you want to see, all other will be ignored (optional)
149
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
150
157
  });
151
158
  ```
152
159
 
153
160
  ### Functions
154
161
 
155
- - `addRow(rowObjet, options)` adding single row.
162
+ - `addRow(rowObjet, options)` adding single row. This can be chained
156
163
  - `addRows(rowObjects, options)` adding multiple rows. array of row object. This case options will be applied to all the objects in row
157
164
  - `addColumn(columnObject)` adding single column
158
165
  - `addColumns(columnObjects)` adding multiple columns
@@ -11,5 +11,8 @@ 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 }, (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 }));
14
+ const rawColumnToInternalColumn = (column) => {
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 }));
17
+ };
15
18
  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, colorMap) => {
14
+ const renderOneLine = (tableStyle, columns, currentLineIndex, widthLimitedColumnsArray, isHeader, row, colorMap, charLength) => {
15
15
  const line = new colored_console_line_1.default(colorMap);
16
- line.addCharsWithColor(table_constants_1.DEFAULT_ROW_FONT_COLOR, tableStyle.vertical);
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
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, (0, string_utils_1.textWithPadding)(textForThisLine, column.alignment || table_constants_1.DEFAULT_ROW_ALIGNMENT, column.length || table_constants_1.DEFAULT_COLUMN_LEN));
24
- line.addCharsWithColor(table_constants_1.DEFAULT_ROW_FONT_COLOR, ` ${tableStyle.vertical}`);
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, colorMap, isHeader) => {
30
+ const renderWidthLimitedLines = (tableStyle, columns, row, colorMap, isHeader, charLength) => {
31
31
  // { col1: ['How', 'Is', 'Going'], col2: ['I am', 'Tom'], }
32
- const widthLimitedColumnsArray = (0, 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, colorMap);
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, colorMap, 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, table.colorMap));
44
+ ret = ret.concat(renderWidthLimitedLines(table.tableStyle, table.columns, row, table.colorMap, undefined, table.charLength));
45
45
  return ret;
46
46
  };
47
47
  /*
@@ -1,4 +1,4 @@
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
4
  import { ColorMap } from '../utils/colored-console-line';
@@ -15,6 +15,7 @@ declare class TableInternal {
15
15
  computedColumns: any[];
16
16
  rowSeparator: boolean;
17
17
  colorMap: ColorMap;
18
+ charLength: CharLengthDict;
18
19
  initSimple(columns: string[]): void;
19
20
  initDetailed(options: ComplexOptions): void;
20
21
  constructor(options?: ComplexOptions | string[]);
@@ -8,26 +8,6 @@ const internal_table_printer_1 = require("./internal-table-printer");
8
8
  const DEFAULT_ROW_SORT_FUNC = () => 0;
9
9
  const DEFAULT_ROW_FILTER_FUNC = () => true;
10
10
  class TableInternal {
11
- constructor(options) {
12
- // default construction
13
- this.rows = [];
14
- this.columns = [];
15
- this.title = undefined;
16
- this.tableStyle = table_constants_1.DEFAULT_TABLE_STYLE;
17
- this.filterFunction = DEFAULT_ROW_FILTER_FUNC;
18
- this.sortFunction = DEFAULT_ROW_SORT_FUNC;
19
- this.enabledColumns = [];
20
- this.disabledColumns = [];
21
- this.computedColumns = [];
22
- this.rowSeparator = table_constants_1.DEFAULT_ROW_SEPARATOR;
23
- this.colorMap = colored_console_line_1.DEFAULT_COLOR_MAP;
24
- if (options instanceof Array) {
25
- this.initSimple(options);
26
- }
27
- else if (typeof options === 'object') {
28
- this.initDetailed(options);
29
- }
30
- }
31
11
  initSimple(columns) {
32
12
  this.columns = columns.map((column) => ({
33
13
  name: column,
@@ -47,6 +27,7 @@ class TableInternal {
47
27
  this.columns =
48
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;
49
29
  this.rowSeparator = (options === null || options === void 0 ? void 0 : options.rowSeparator) || this.rowSeparator;
30
+ this.charLength = (options === null || options === void 0 ? void 0 : options.charLength) || this.charLength;
50
31
  if (options === null || options === void 0 ? void 0 : options.colorMap) {
51
32
  this.colorMap = Object.assign(Object.assign({}, this.colorMap), options.colorMap);
52
33
  }
@@ -54,6 +35,27 @@ class TableInternal {
54
35
  this.addRows(options.rows);
55
36
  }
56
37
  }
38
+ constructor(options) {
39
+ // default construction
40
+ this.rows = [];
41
+ this.columns = [];
42
+ this.title = undefined;
43
+ this.tableStyle = table_constants_1.DEFAULT_TABLE_STYLE;
44
+ this.filterFunction = DEFAULT_ROW_FILTER_FUNC;
45
+ this.sortFunction = DEFAULT_ROW_SORT_FUNC;
46
+ this.enabledColumns = [];
47
+ this.disabledColumns = [];
48
+ this.computedColumns = [];
49
+ this.rowSeparator = table_constants_1.DEFAULT_ROW_SEPARATOR;
50
+ this.colorMap = colored_console_line_1.DEFAULT_COLOR_MAP;
51
+ this.charLength = {};
52
+ if (options instanceof Array) {
53
+ this.initSimple(options);
54
+ }
55
+ else if (typeof options === 'object') {
56
+ this.initDetailed(options);
57
+ }
58
+ }
57
59
  createColumnFromRow(text) {
58
60
  const colNames = this.columns.map((col) => col.name);
59
61
  Object.keys(text).forEach((key) => {
@@ -24,7 +24,7 @@ const enableColumnsIfNecessary = (table) => {
24
24
  };
25
25
  const findColumnWidth = (table) => {
26
26
  table.columns.forEach((column) => {
27
- column.length = (0, 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) => {
@@ -1,9 +1,12 @@
1
1
  import { ALIGNMENTS, COLORS } from '../utils/table-constants';
2
- export declare type ALIGNMENT = typeof ALIGNMENTS[number];
3
- export declare type COLOR = typeof COLORS[number];
2
+ export type ALIGNMENT = typeof ALIGNMENTS[number];
3
+ export 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;
9
12
  separator: boolean;
@@ -1,5 +1,5 @@
1
1
  import { ColorMap } from '../utils/colored-console-line';
2
- import { ALIGNMENT, COLOR, Dictionary } from './common';
2
+ import { ALIGNMENT, CharLengthDict, COLOR, Dictionary } from './common';
3
3
  import { TableStyleDetails } from './internal-table';
4
4
  export { ALIGNMENT, COLOR };
5
5
  export interface ColumnOptionsRaw {
@@ -13,8 +13,8 @@ export interface ColumnOptionsRaw {
13
13
  export interface ComputedColumn extends ColumnOptionsRaw {
14
14
  function: (arg0: any) => any;
15
15
  }
16
- export declare type RowSortFunction = (row1: any, row2: any) => number;
17
- export declare type RowFilterFunction = (row: any) => Boolean;
16
+ export type RowSortFunction = (row1: any, row2: any) => number;
17
+ export type RowFilterFunction = (row: any) => Boolean;
18
18
  export interface ComplexOptions {
19
19
  style?: TableStyleDetails;
20
20
  title?: string;
@@ -27,4 +27,5 @@ export interface ComplexOptions {
27
27
  computedColumns?: ComputedColumn[];
28
28
  rowSeparator?: boolean;
29
29
  colorMap?: ColorMap;
30
+ charLength?: CharLengthDict;
30
31
  }
@@ -8,11 +8,11 @@ export interface Column {
8
8
  minLen?: number;
9
9
  maxLen?: number;
10
10
  }
11
- declare type TableLineDetailsKeys = 'left' | 'right' | 'mid' | 'other';
12
- export declare type TableLineDetails = {
11
+ type TableLineDetailsKeys = 'left' | 'right' | 'mid' | 'other';
12
+ export type TableLineDetails = {
13
13
  [key in TableLineDetailsKeys]: string;
14
14
  };
15
- export declare type TableStyleDetails = {
15
+ export type TableStyleDetails = {
16
16
  headerTop: TableLineDetails;
17
17
  headerBottom: TableLineDetails;
18
18
  tableBottom: TableLineDetails;
@@ -1,5 +1,5 @@
1
1
  import { COLOR } from '../models/common';
2
- export declare type ColorMap = {
2
+ export type ColorMap = {
3
3
  [key in COLOR]?: string;
4
4
  };
5
5
  export declare const DEFAULT_COLOR_MAP: ColorMap;
@@ -9,7 +9,6 @@ exports.DEFAULT_COLOR_MAP = {
9
9
  magenta: '\x1b[35m',
10
10
  cyan: '\x1b[36m',
11
11
  white: '\x1b[37m',
12
- crimson: '\x1b[38m',
13
12
  white_bold: '\x1b[01m',
14
13
  reset: '\x1b[0m',
15
14
  };
@@ -1,2 +1,3 @@
1
- declare const findWidthInConsole: (str: string) => number;
2
- export default findWidthInConsole;
1
+ import { CharLengthDict } from '../models/common';
2
+ export declare const stripAnsi: (str: string) => string;
3
+ export declare const findWidthInConsole: (str: string, charLength?: CharLengthDict) => number;
@@ -1,8 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findWidthInConsole = exports.stripAnsi = void 0;
3
4
  const simple_wcswidth_1 = require("simple-wcswidth");
4
5
  /* eslint-disable no-control-regex */
5
- const colorRegex = /\x1b\[\d{1,3}m/g; // \x1b[30m \x1b[305m
6
+ const colorRegex = /\x1b\[\d{1,3}(;\d{1,3})*m/g; // \x1b[30m \x1b[305m \x1b[38;5m
6
7
  const stripAnsi = (str) => str.replace(colorRegex, '');
7
- const findWidthInConsole = (str) => (0, simple_wcswidth_1.wcswidth)(stripAnsi(str));
8
- exports.default = findWidthInConsole;
8
+ exports.stripAnsi = stripAnsi;
9
+ const findWidthInConsole = (str, charLength) => {
10
+ let strLen = 0;
11
+ str = (0, exports.stripAnsi)(str);
12
+ if (charLength) {
13
+ Object.entries(charLength).forEach(([key, value]) => {
14
+ // count appearance of the key in the string and remove from original string
15
+ let regex = new RegExp(key, 'g');
16
+ strLen += (str.match(regex) || []).length * value;
17
+ str = str.replace(key, '');
18
+ });
19
+ }
20
+ strLen += (0, simple_wcswidth_1.wcswidth)(str);
21
+ return strLen;
22
+ };
23
+ exports.findWidthInConsole = 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;
@@ -1,17 +1,18 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.biggestWordInSentence = exports.limitWidth = exports.textWithPadding = void 0;
7
- const console_utils_1 = __importDefault(require("./console-utils"));
4
+ const console_utils_1 = require("./console-utils");
8
5
  // ("How are you?",center, 20) => " How are you? "
9
6
  // ("How are you?",right, 20) => " How are you?"
10
- const textWithPadding = (text, alignment, columnLen) => {
11
- const curTextSize = (0, console_utils_1.default)(text);
7
+ const textWithPadding = (text, alignment, columnLen, charLength) => {
8
+ const curTextSize = (0, console_utils_1.findWidthInConsole)(text, charLength);
12
9
  // alignments for center padding case
13
10
  const leftPadding = Math.floor((columnLen - curTextSize) / 2);
14
11
  const rightPadding = columnLen - leftPadding - curTextSize;
12
+ // handle edge cases where the text size is larger than the column length
13
+ if (columnLen < curTextSize) {
14
+ return text;
15
+ }
15
16
  // console.log(text, columnLen, curTextSize);
16
17
  switch (alignment) {
17
18
  case 'left':
@@ -28,13 +29,13 @@ const textWithPadding = (text, alignment, columnLen) => {
28
29
  };
29
30
  exports.textWithPadding = textWithPadding;
30
31
  // ("How are you?",10) => ["How are ", "you?"]
31
- const limitWidth = (inpStr, width) => {
32
+ const limitWidth = (inpStr, width, charLength) => {
32
33
  const ret = [];
33
34
  const spaceSeparatedStrings = inpStr.split(' ');
34
35
  let now = [];
35
36
  let cnt = 0;
36
37
  spaceSeparatedStrings.forEach((strWithoutSpace) => {
37
- const consoleWidth = (0, console_utils_1.default)(strWithoutSpace);
38
+ const consoleWidth = (0, console_utils_1.findWidthInConsole)(strWithoutSpace, charLength);
38
39
  if (cnt + consoleWidth <= width) {
39
40
  cnt += consoleWidth + 1; // 1 for the space
40
41
  now.push(strWithoutSpace);
@@ -50,5 +51,7 @@ const limitWidth = (inpStr, width) => {
50
51
  };
51
52
  exports.limitWidth = limitWidth;
52
53
  // ("How are you?",10) => ["How are ", "you?"]
53
- const biggestWordInSentence = (inpStr) => inpStr.split(' ').reduce((a, b) => Math.max(a, (0, console_utils_1.default)(b)), 0);
54
+ const biggestWordInSentence = (inpStr, charLength) => inpStr
55
+ .split(' ')
56
+ .reduce((a, b) => Math.max(a, (0, console_utils_1.findWidthInConsole)(b, charLength)), 0);
54
57
  exports.biggestWordInSentence = biggestWordInSentence;
@@ -46,7 +46,6 @@ exports.COLORS = [
46
46
  'blue',
47
47
  'magenta',
48
48
  'cyan',
49
- 'crimson',
50
49
  'white_bold',
51
50
  'reset',
52
51
  ];
@@ -1,4 +1,4 @@
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;
@@ -10,7 +10,7 @@ export interface RowOptions {
10
10
  color: COLOR;
11
11
  separator: boolean;
12
12
  }
13
- export declare const convertRawRowOptionsToStandard: (options?: RowOptionsRaw | undefined) => RowOptions | undefined;
13
+ export declare const convertRawRowOptionsToStandard: (options?: RowOptionsRaw) => RowOptions | undefined;
14
14
  export declare const createTableHorizontalBorders: ({ left, mid, right, other, }: {
15
15
  left: string;
16
16
  mid: string;
@@ -20,9 +20,9 @@ export declare const createTableHorizontalBorders: ({ left, mid, right, other, }
20
20
  export declare const createColumFromOnlyName: (name: string) => Column;
21
21
  export declare const createColumFromComputedColumn: (column: ComputedColumn) => Column;
22
22
  export declare const createRow: (color: COLOR, text: Dictionary, separator: boolean) => Row;
23
- export declare const findLenOfColumn: (column: Column, rows: Row[]) => number;
23
+ export declare const findLenOfColumn: (column: Column, rows: Row[], charLength?: CharLengthDict) => number;
24
24
  export declare const renderTableHorizontalBorders: (style: any, column_lengths: number[]) => string;
25
25
  export declare const createHeaderAsRow: (createRowFn: any, columns: Column[]) => Row;
26
- export declare const getWidthLimitedColumnsArray: (columns: Column[], row: Row) => {
26
+ export declare const getWidthLimitedColumnsArray: (columns: Column[], row: Row, charLength?: CharLengthDict) => {
27
27
  [key: string]: string[];
28
28
  };
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getWidthLimitedColumnsArray = exports.createHeaderAsRow = exports.renderTableHorizontalBorders = exports.findLenOfColumn = exports.createRow = exports.createColumFromComputedColumn = exports.createColumFromOnlyName = exports.createTableHorizontalBorders = exports.convertRawRowOptionsToStandard = exports.cellText = void 0;
7
4
  const input_converter_1 = require("../internalTable/input-converter");
8
- const console_utils_1 = __importDefault(require("./console-utils"));
5
+ const console_utils_1 = require("./console-utils");
9
6
  const string_utils_1 = require("./string-utils");
10
7
  const table_constants_1 = require("./table-constants");
11
8
  const max = (a, b) => Math.max(a, b);
@@ -42,7 +39,10 @@ const createColumFromOnlyName = (name) => ({
42
39
  title: name,
43
40
  });
44
41
  exports.createColumFromOnlyName = createColumFromOnlyName;
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 }));
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
46
  exports.createColumFromComputedColumn = createColumFromComputedColumn;
47
47
  const createRow = (color, text, separator) => ({
48
48
  color,
@@ -50,20 +50,20 @@ const createRow = (color, text, separator) => ({
50
50
  text,
51
51
  });
52
52
  exports.createRow = createRow;
53
- const findLenOfColumn = (column, rows) => {
53
+ const findLenOfColumn = (column, rows, charLength) => {
54
54
  const columnId = column.name;
55
55
  const columnTitle = column.title;
56
56
  let length = max(0, (column === null || column === void 0 ? void 0 : column.minLen) || 0);
57
57
  if (column.maxLen) {
58
58
  // if customer input is mentioned a max width, lets see if all other can fit here
59
59
  // if others cant fit find the max word length so that at least the table can be printed
60
- length = max(length, max(column.maxLen, (0, string_utils_1.biggestWordInSentence)(columnTitle)));
61
- length = rows.reduce((acc, row) => max(acc, (0, string_utils_1.biggestWordInSentence)((0, 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);
62
62
  return length;
63
63
  }
64
- length = max(length, (0, console_utils_1.default)(columnTitle));
64
+ length = max(length, (0, console_utils_1.findWidthInConsole)(columnTitle, charLength));
65
65
  rows.forEach((row) => {
66
- length = max(length, (0, console_utils_1.default)((0, exports.cellText)(row.text[columnId])));
66
+ length = max(length, (0, console_utils_1.findWidthInConsole)((0, exports.cellText)(row.text[columnId]), charLength));
67
67
  });
68
68
  return length;
69
69
  };
@@ -83,10 +83,10 @@ const createHeaderAsRow = (createRowFn, columns) => {
83
83
  };
84
84
  exports.createHeaderAsRow = createHeaderAsRow;
85
85
  // { col1: ['How', 'Is', 'Going'], col2: ['I am', 'Tom'], }
86
- const getWidthLimitedColumnsArray = (columns, row) => {
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);
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);
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.0",
3
+ "version": "2.11.2",
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": "^6.0.1",
28
+ "@semantic-release/changelog": "^6.0.3",
29
29
  "@semantic-release/git": "^10.0.1",
30
- "@types/jest": "^27.0.2",
31
- "@typescript-eslint/eslint-plugin": "^5.2.0",
32
- "@typescript-eslint/parser": "^5.2.0",
30
+ "@types/jest": "^29.5.2",
31
+ "@typescript-eslint/eslint-plugin": "^5.60.1",
32
+ "@typescript-eslint/parser": "^5.60.1",
33
33
  "chalk": "^4.1.2",
34
- "eslint": "^8.1.0",
35
- "eslint-config-airbnb-base": "^14.2.1",
36
- "eslint-config-prettier": "^8.3.0",
37
- "eslint-plugin-import": "^2.25.2",
38
- "eslint-plugin-prettier": "^4.0.0",
39
- "husky": "^7.0.4",
40
- "jest": "^27.3.1",
41
- "prettier": "^2.4.1",
42
- "pretty-quick": "^3.1.1",
43
- "semantic-release": "^18.0.0",
44
- "ts-jest": "^27.0.7",
45
- "typescript": "^4.4.4"
34
+ "eslint": "^8.44.0",
35
+ "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",
39
+ "husky": "^8.0.3",
40
+ "jest": "^29.5.0",
41
+ "prettier": "^2.8.8",
42
+ "pretty-quick": "^3.1.3",
43
+ "semantic-release": "^21.0.6",
44
+ "ts-jest": "^29.1.1",
45
+ "typescript": "^5.1.6"
46
46
  },
47
47
  "homepage": "https://console-table.netlify.app",
48
48
  "dependencies": {