console-table-printer 2.11.1 → 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.
@@ -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;
@@ -8,27 +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
- this.charLength = {};
25
- if (options instanceof Array) {
26
- this.initSimple(options);
27
- }
28
- else if (typeof options === 'object') {
29
- this.initDetailed(options);
30
- }
31
- }
32
11
  initSimple(columns) {
33
12
  this.columns = columns.map((column) => ({
34
13
  name: column,
@@ -56,6 +35,27 @@ class TableInternal {
56
35
  this.addRows(options.rows);
57
36
  }
58
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
+ }
59
59
  createColumnFromRow(text) {
60
60
  const colNames = this.columns.map((col) => col.name);
61
61
  Object.keys(text).forEach((key) => {
@@ -1,6 +1,6 @@
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
  }
@@ -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;
@@ -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,3 +1,3 @@
1
1
  import { CharLengthDict } from '../models/common';
2
+ export declare const stripAnsi: (str: string) => string;
2
3
  export declare const findWidthInConsole: (str: string, charLength?: CharLengthDict) => number;
3
- export default findWidthInConsole;
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findWidthInConsole = void 0;
3
+ exports.findWidthInConsole = exports.stripAnsi = void 0;
4
4
  const simple_wcswidth_1 = require("simple-wcswidth");
5
5
  /* eslint-disable no-control-regex */
6
- 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
7
7
  const stripAnsi = (str) => str.replace(colorRegex, '');
8
+ exports.stripAnsi = stripAnsi;
8
9
  const findWidthInConsole = (str, charLength) => {
9
10
  let strLen = 0;
10
- str = stripAnsi(str);
11
+ str = (0, exports.stripAnsi)(str);
11
12
  if (charLength) {
12
13
  Object.entries(charLength).forEach(([key, value]) => {
13
14
  // count appearance of the key in the string and remove from original string
@@ -20,4 +21,3 @@ const findWidthInConsole = (str, charLength) => {
20
21
  return strLen;
21
22
  };
22
23
  exports.findWidthInConsole = findWidthInConsole;
23
- exports.default = exports.findWidthInConsole;
@@ -1,14 +1,11 @@
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
7
  const textWithPadding = (text, alignment, columnLen, charLength) => {
11
- const curTextSize = (0, console_utils_1.default)(text, 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;
@@ -38,7 +35,7 @@ const limitWidth = (inpStr, width, charLength) => {
38
35
  let now = [];
39
36
  let cnt = 0;
40
37
  spaceSeparatedStrings.forEach((strWithoutSpace) => {
41
- const consoleWidth = (0, console_utils_1.default)(strWithoutSpace, charLength);
38
+ const consoleWidth = (0, console_utils_1.findWidthInConsole)(strWithoutSpace, charLength);
42
39
  if (cnt + consoleWidth <= width) {
43
40
  cnt += consoleWidth + 1; // 1 for the space
44
41
  now.push(strWithoutSpace);
@@ -56,5 +53,5 @@ exports.limitWidth = limitWidth;
56
53
  // ("How are you?",10) => ["How are ", "you?"]
57
54
  const biggestWordInSentence = (inpStr, charLength) => inpStr
58
55
  .split(' ')
59
- .reduce((a, b) => Math.max(a, (0, console_utils_1.default)(b, charLength)), 0);
56
+ .reduce((a, b) => Math.max(a, (0, console_utils_1.findWidthInConsole)(b, charLength)), 0);
60
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,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,
@@ -61,9 +61,9 @@ const findLenOfColumn = (column, rows, charLength) => {
61
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, charLength));
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]), charLength));
66
+ length = max(length, (0, console_utils_1.findWidthInConsole)((0, exports.cellText)(row.text[columnId]), charLength));
67
67
  });
68
68
  return length;
69
69
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "console-table-printer",
3
- "version": "2.11.1",
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": "^28.1.8",
31
- "@typescript-eslint/eslint-plugin": "^5.34.0",
32
- "@typescript-eslint/parser": "^5.34.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.22.0",
34
+ "eslint": "^8.44.0",
35
35
  "eslint-config-airbnb-base": "^15.0.0",
36
- "eslint-config-prettier": "^8.5.0",
37
- "eslint-plugin-import": "^2.26.0",
36
+ "eslint-config-prettier": "^8.8.0",
37
+ "eslint-plugin-import": "^2.27.5",
38
38
  "eslint-plugin-prettier": "^4.2.1",
39
- "husky": "^8.0.1",
40
- "jest": "^28.1.3",
41
- "prettier": "^2.7.1",
39
+ "husky": "^8.0.3",
40
+ "jest": "^29.5.0",
41
+ "prettier": "^2.8.8",
42
42
  "pretty-quick": "^3.1.3",
43
- "semantic-release": "^19.0.5",
44
- "ts-jest": "^28.0.8",
45
- "typescript": "^4.7.4"
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": {