console-table-printer
Advanced tools
@@ -1,2 +0,2 @@ | ||
| import { COLOR } from "./table-constants"; | ||
| import { COLOR } from './table-constants'; | ||
| export declare class ColoredConsoleLine { | ||
@@ -3,0 +3,0 @@ text: string; |
@@ -5,16 +5,16 @@ "use strict"; | ||
| const COLOR_MAP = { | ||
| [table_constants_1.COLOR.red]: "\x1b[31m", | ||
| [table_constants_1.COLOR.green]: "\x1b[32m", | ||
| [table_constants_1.COLOR.yellow]: "\x1b[33m", | ||
| [table_constants_1.COLOR.blue]: "\x1b[34m", | ||
| [table_constants_1.COLOR.magenta]: "\x1b[35m", | ||
| [table_constants_1.COLOR.cyan]: "\x1b[36m", | ||
| [table_constants_1.COLOR.white]: "\x1b[37m", | ||
| [table_constants_1.COLOR.crimson]: "\x1b[38m", | ||
| [table_constants_1.COLOR.white_bold]: "\x1b[01m", | ||
| [table_constants_1.COLOR.reset]: "\x1b[0m" | ||
| [table_constants_1.COLOR.red]: '\x1b[31m', | ||
| [table_constants_1.COLOR.green]: '\x1b[32m', | ||
| [table_constants_1.COLOR.yellow]: '\x1b[33m', | ||
| [table_constants_1.COLOR.blue]: '\x1b[34m', | ||
| [table_constants_1.COLOR.magenta]: '\x1b[35m', | ||
| [table_constants_1.COLOR.cyan]: '\x1b[36m', | ||
| [table_constants_1.COLOR.white]: '\x1b[37m', | ||
| [table_constants_1.COLOR.crimson]: '\x1b[38m', | ||
| [table_constants_1.COLOR.white_bold]: '\x1b[01m', | ||
| [table_constants_1.COLOR.reset]: '\x1b[0m', | ||
| }; | ||
| class ColoredConsoleLine { | ||
| constructor() { | ||
| this.text = ""; | ||
| this.text = ''; | ||
| } | ||
@@ -21,0 +21,0 @@ addWithColor(color, text) { |
@@ -1,3 +0,3 @@ | ||
| import { TableInternal, ComplexOptions } from "./internal-table"; | ||
| import { RowOptionsRaw } from "./table-helpers"; | ||
| import { ComplexOptions, TableInternal } from './internal-table'; | ||
| import { RowOptionsRaw } from './table-helpers'; | ||
| export declare class Table { | ||
@@ -4,0 +4,0 @@ table: TableInternal; |
@@ -1,2 +0,2 @@ | ||
| import { TableInternal } from "./internal-table"; | ||
| import { TableInternal } from './internal-table'; | ||
| export declare function printTableTest(table: TableInternal): string[]; | ||
@@ -3,0 +3,0 @@ export declare function printTable(table: TableInternal): void; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const colored_console_line_1 = require("./colored-console-line"); | ||
| const internal_table_1 = require("./internal-table"); | ||
| const table_constants_1 = require("./table-constants"); | ||
| const colored_console_line_1 = require("./colored-console-line"); | ||
| const table_helpers_1 = require("./table-helpers"); | ||
| const internal_table_1 = require("./internal-table"); | ||
| function prepareLineAndPrint(tableStyle, columns, row) { | ||
@@ -11,5 +11,5 @@ let line = new colored_console_line_1.ColoredConsoleLine(); | ||
| for (let column of columns) { | ||
| line.addWithColor(table_constants_1.COLOR.white, " "); | ||
| line.addWithColor(row.color, table_helpers_1.textWithPadding(`${row.text[column.name] || ""}`, column.alignment || table_constants_1.COLUMN_ALIGNMENT.right, column.max_ln || 20)); | ||
| line.addWithColor(table_constants_1.COLOR.white, " " + tableStyle.vertical); | ||
| line.addWithColor(table_constants_1.COLOR.white, ' '); | ||
| line.addWithColor(row.color, table_helpers_1.textWithPadding(`${row.text[column.name] || ''}`, column.alignment || table_constants_1.COLUMN_ALIGNMENT.right, column.max_ln || 20)); | ||
| line.addWithColor(table_constants_1.COLOR.white, ' ' + tableStyle.vertical); | ||
| } | ||
@@ -32,3 +32,3 @@ return line.printConsole(); | ||
| // ╔═══════╦═══════════════════════════════════════╦════════╗ | ||
| ret.push(table_helpers_1.printTableHorizontalBorders(table.tableStyle.headerTop, table.columns.map(m => (m.max_ln || 20)))); | ||
| ret.push(table_helpers_1.printTableHorizontalBorders(table.tableStyle.headerTop, table.columns.map(m => m.max_ln || 20))); | ||
| // ║ index ║ text ║ value ║ | ||
@@ -38,3 +38,3 @@ let row = table_helpers_1.createHeaderAsRow(table_helpers_1.createRow, table.columns); | ||
| // ╟═══════╬═══════════════════════════════════════╬════════╢ | ||
| ret.push(table_helpers_1.printTableHorizontalBorders(table.tableStyle.headerBottom, table.columns.map(m => (m.max_ln || 20)))); | ||
| ret.push(table_helpers_1.printTableHorizontalBorders(table.tableStyle.headerBottom, table.columns.map(m => m.max_ln || 20))); | ||
| return ret; | ||
@@ -45,3 +45,3 @@ } | ||
| // ╚═══════╩═══════════════════════════════════════╩════════╝ | ||
| ret.push(table_helpers_1.printTableHorizontalBorders(table.tableStyle.tableBottom, table.columns.map(m => (m.max_ln || 20)))); | ||
| ret.push(table_helpers_1.printTableHorizontalBorders(table.tableStyle.tableBottom, table.columns.map(m => m.max_ln || 20))); | ||
| return ret; | ||
@@ -48,0 +48,0 @@ } |
@@ -1,3 +0,3 @@ | ||
| import { TABLE_BORDER_STYLES, TABLE_STYLE_DETAILS } from "./table-constants"; | ||
| import { Column, Row, RowOptions } from "./table-helpers"; | ||
| import { TABLE_BORDER_STYLES, TABLE_STYLE_DETAILS } from './table-constants'; | ||
| import { Column, Row, RowOptions } from './table-helpers'; | ||
| interface ColumnOptionsRaw { | ||
@@ -4,0 +4,0 @@ name: string; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const internal_table_printer_1 = require("./internal-table-printer"); | ||
| const table_constants_1 = require("./table-constants"); | ||
| const table_helpers_1 = require("./table-helpers"); | ||
| const internal_table_printer_1 = require("./internal-table-printer"); | ||
| class TableInternal { | ||
@@ -16,3 +16,3 @@ constructor(options) { | ||
| } | ||
| else if (typeof options === "object") { | ||
| else if (typeof options === 'object') { | ||
| this.initDetailed(options); | ||
@@ -24,3 +24,3 @@ } | ||
| name: column, | ||
| alignment: table_constants_1.COLUMN_ALIGNMENT.right | ||
| alignment: table_constants_1.COLUMN_ALIGNMENT.right, | ||
| })); | ||
@@ -30,3 +30,4 @@ } | ||
| this.tableStyle = | ||
| (options && options.style && table_constants_1.TABLE_STYLE[options.style]) || table_constants_1.TABLE_STYLE.thinBorder; | ||
| (options && options.style && table_constants_1.TABLE_STYLE[options.style]) || | ||
| table_constants_1.TABLE_STYLE.thinBorder; | ||
| this.columns = | ||
@@ -36,3 +37,3 @@ (options.columns && | ||
| name: column.name, | ||
| alignment: table_constants_1.COLUMN_ALIGNMENT[column.alignment || table_constants_1.COLUMN_ALIGNMENT.right] | ||
| alignment: table_constants_1.COLUMN_ALIGNMENT[column.alignment || table_constants_1.COLUMN_ALIGNMENT.right], | ||
| }))) || | ||
@@ -39,0 +40,0 @@ []; |
@@ -19,20 +19,20 @@ "use strict"; | ||
| headerTop: { | ||
| left: "┌", | ||
| mid: "┬", | ||
| right: "┐", | ||
| other: "─" | ||
| left: '┌', | ||
| mid: '┬', | ||
| right: '┐', | ||
| other: '─', | ||
| }, | ||
| headerBottom: { | ||
| left: "├", | ||
| mid: "┼", | ||
| right: "┤", | ||
| other: "─" | ||
| left: '├', | ||
| mid: '┼', | ||
| right: '┤', | ||
| other: '─', | ||
| }, | ||
| tableBottom: { | ||
| left: "└", | ||
| mid: "┴", | ||
| right: "┘", | ||
| other: "─" | ||
| left: '└', | ||
| mid: '┴', | ||
| right: '┘', | ||
| other: '─', | ||
| }, | ||
| vertical: "│" | ||
| vertical: '│', | ||
| }, | ||
@@ -49,21 +49,21 @@ fatBorder: { | ||
| headerTop: { | ||
| left: "╔", | ||
| mid: "╦", | ||
| right: "╗", | ||
| other: "═" | ||
| left: '╔', | ||
| mid: '╦', | ||
| right: '╗', | ||
| other: '═', | ||
| }, | ||
| headerBottom: { | ||
| left: "╟", | ||
| mid: "╬", | ||
| right: "╢", | ||
| other: "═" | ||
| left: '╟', | ||
| mid: '╬', | ||
| right: '╢', | ||
| other: '═', | ||
| }, | ||
| tableBottom: { | ||
| left: "╚", | ||
| mid: "╩", | ||
| right: "╝", | ||
| other: "═" | ||
| left: '╚', | ||
| mid: '╩', | ||
| right: '╝', | ||
| other: '═', | ||
| }, | ||
| vertical: "║" | ||
| } | ||
| vertical: '║', | ||
| }, | ||
| }; | ||
@@ -70,0 +70,0 @@ var COLUMN_ALIGNMENT; |
@@ -1,2 +0,2 @@ | ||
| import { COLUMN_ALIGNMENT, COLOR } from "./table-constants"; | ||
| import { COLOR, COLUMN_ALIGNMENT } from './table-constants'; | ||
| export interface Column { | ||
@@ -19,3 +19,3 @@ name: string; | ||
| export declare function textWithPadding(text: string, alignment: COLUMN_ALIGNMENT, size: number): string; | ||
| export declare function createTableHorizontalBorders({ left, mid, right, other }: { | ||
| export declare function createTableHorizontalBorders({ left, mid, right, other, }: { | ||
| left: string; | ||
@@ -22,0 +22,0 @@ mid: string; |
@@ -7,3 +7,3 @@ "use strict"; | ||
| return { | ||
| color: table_constants_1.COLOR[options.color] | ||
| color: table_constants_1.COLOR[options.color], | ||
| }; | ||
@@ -25,3 +25,3 @@ } | ||
| exports.textWithPadding = textWithPadding; | ||
| function createTableHorizontalBorders({ left, mid, right, other }, column_lengths) { | ||
| function createTableHorizontalBorders({ left, mid, right, other, }, column_lengths) { | ||
| let ret = left; | ||
@@ -49,3 +49,3 @@ for (let len of column_lengths) { | ||
| for (let row of rows) { | ||
| max_ln = Math.max(max_ln, `${row.text[column_name] || ""}`.length); | ||
| max_ln = Math.max(max_ln, `${row.text[column_name] || ''}`.length); | ||
| } | ||
@@ -52,0 +52,0 @@ return max_ln; |
+5
-1
| { | ||
| "name": "console-table-printer", | ||
| "version": "1.1.23", | ||
| "version": "1.1.24", | ||
| "repository": "github:ayonious/console-table-printer", | ||
@@ -11,2 +11,3 @@ "description": "Printing pretty tables on console log", | ||
| "build": "tsc", | ||
| "format": "prettier --write \"**/*.{json,md,ts,tsx,yml,js,jsx}\"", | ||
| "test": "jest --config jestconfig.json" | ||
@@ -21,3 +22,6 @@ }, | ||
| "@types/jest": "^24.0.23", | ||
| "husky": "^3.1.0", | ||
| "jest": "^24.9.0", | ||
| "prettier": "^1.19.1", | ||
| "pretty-quick": "^2.0.1", | ||
| "ts-jest": "^24.2.0", | ||
@@ -24,0 +28,0 @@ "typescript": "^3.7.2" |
+39
-34
@@ -39,8 +39,8 @@ <h1 align="center">console-table-printer</h1> | ||
| ```javascript | ||
| const {printTable} = require('console-table-printer'); | ||
| const { printTable } = require('console-table-printer'); | ||
| //Create a table | ||
| const testCases = [ | ||
| { index: 3, text: 'I would like some gelb bananen bitte', value: 100 }, | ||
| { index: 4, text: 'I hope batch update is working', value: 300 } | ||
| { index: 3, text: 'I would like some gelb bananen bitte', value: 100 }, | ||
| { index: 4, text: 'I hope batch update is working', value: 300 }, | ||
| ]; | ||
@@ -57,4 +57,5 @@ | ||
| You can also create a Table instance and print it: | ||
| ```javascript | ||
| const {Table} = require('console-table-printer'); | ||
| const { Table } = require('console-table-printer'); | ||
@@ -66,6 +67,7 @@ //Create a table | ||
| p.addRow({ index: 1, text: 'red wine please', value: 10.212 }); | ||
| p.addRow({ index: 2, text: 'green gemuse please', value: 20.00 }); | ||
| p.addRows([ //adding multiple rows are possible | ||
| { index: 3, text: 'gelb bananen bitte', value: 100 }, | ||
| { index: 4, text: 'update is working', value: 300} | ||
| p.addRow({ index: 2, text: 'green gemuse please', value: 20.0 }); | ||
| p.addRows([ | ||
| //adding multiple rows are possible | ||
| { index: 3, text: 'gelb bananen bitte', value: 100 }, | ||
| { index: 4, text: 'update is working', value: 300 }, | ||
| ]); | ||
@@ -82,7 +84,8 @@ | ||
| You can also put some color to your table like this: | ||
| ```javascript | ||
| const p = new Table(); | ||
| p.addRow({ index: 1, text: 'red wine', value: 10.212 }, {color: 'red'}); | ||
| p.addRow({ index: 2, text: 'green gemuse', value: 20.00 }, {color: 'green'}); | ||
| p.addRow({ index: 3, text: 'gelb bananen', value: 100 }, {color: 'yellow'}); | ||
| p.addRow({ index: 1, text: 'red wine', value: 10.212 }, { color: 'red' }); | ||
| p.addRow({ index: 2, text: 'green gemuse', value: 20.0 }, { color: 'green' }); | ||
| p.addRow({ index: 3, text: 'gelb bananen', value: 100 }, { color: 'yellow' }); | ||
| p.printTable(); | ||
@@ -98,2 +101,3 @@ ``` | ||
| ### Table instance creation | ||
| 3 ways to Table Instance creation: | ||
@@ -109,8 +113,8 @@ | ||
| new Table({ | ||
| style: 'fatBorder', //style of border of the table | ||
| columns: [ | ||
| {name: 'column1', alignment: 'left'}, //with alignment | ||
| {name: 'column2', alignment: 'right'}, | ||
| {name: 'column3'} | ||
| ] | ||
| style: 'fatBorder', //style of border of the table | ||
| columns: [ | ||
| { name: 'column1', alignment: 'left' }, //with alignment | ||
| { name: 'column2', alignment: 'right' }, | ||
| { name: 'column3' }, | ||
| ], | ||
| }); | ||
@@ -121,23 +125,24 @@ ``` | ||
| * `addRow(rowObjet, options)` adding single row. | ||
| * `addRows(rowObjets)` adding multiple rows. array of row object. This case options will be applied to all the objects in row | ||
| * `addColumn(columnObject)` adding single column | ||
| * `addColumns(columnObjects)` adding multiple columns | ||
| * `printTable()` Prints the table on your console | ||
| - `addRow(rowObjet, options)` adding single row. | ||
| - `addRows(rowObjets)` adding multiple rows. array of row object. This case options will be applied to all the objects in row | ||
| - `addColumn(columnObject)` adding single column | ||
| - `addColumns(columnObjects)` adding multiple columns | ||
| - `printTable()` Prints the table on your console | ||
| ### possible `color` values for rows | ||
| * red | ||
| * green | ||
| * yellow | ||
| * white | ||
| * blue | ||
| * magenta | ||
| * cyan | ||
| * crimson | ||
| * white_bold | ||
| - red | ||
| - green | ||
| - yellow | ||
| - white | ||
| - blue | ||
| - magenta | ||
| - cyan | ||
| - crimson | ||
| - white_bold | ||
| Example usage: To Create a row of color blue | ||
| ```js | ||
| table.addRow(rowObject, {color: 'blue'}); | ||
| table.addRow(rowObject, { color: 'blue' }); | ||
| ``` | ||
@@ -147,7 +152,7 @@ | ||
| * thinBorder | ||
| - thinBorder | ||
|  | ||
| * fatBorder: | ||
| - fatBorder: | ||
@@ -154,0 +159,0 @@  |
24363
0.73%510
0.2%158
3.27%7
75%