console-table-printer
Advanced tools
Comparing version 2.10.0 to 2.11.0
import Table from './src/console-table-printer'; | ||
import { printSimpleTable as printTable } from './src/internalTable/internal-table-printer'; | ||
import { printSimpleTable as printTable, renderSimpleTable as renderTable } from './src/internalTable/internal-table-printer'; | ||
import { COLOR, ALIGNMENT } from './src/models/external-table'; | ||
export { Table, printTable, COLOR, ALIGNMENT }; | ||
export { Table, printTable, renderTable, COLOR, ALIGNMENT }; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.printTable = exports.Table = void 0; | ||
exports.renderTable = exports.printTable = exports.Table = void 0; | ||
const console_table_printer_1 = __importDefault(require("./src/console-table-printer")); | ||
@@ -12,1 +12,2 @@ exports.Table = console_table_printer_1.default; | ||
Object.defineProperty(exports, "printTable", { enumerable: true, get: function () { return internal_table_printer_1.printSimpleTable; } }); | ||
Object.defineProperty(exports, "renderTable", { enumerable: true, get: function () { return internal_table_printer_1.renderSimpleTable; } }); |
@@ -8,8 +8,8 @@ import TableInternal from './internalTable/internal-table'; | ||
constructor(options?: ComplexOptions | string[]); | ||
addColumn(column: string): void; | ||
addColumns(columns: string[]): void; | ||
addRow(text: Dictionary, rowOptions?: RowOptionsRaw): void; | ||
addRows(toBeInsertedRows: any, rowOptions?: RowOptionsRaw): void; | ||
addColumn(column: string): this; | ||
addColumns(columns: string[]): this; | ||
addRow(text: Dictionary, rowOptions?: RowOptionsRaw): this; | ||
addRows(toBeInsertedRows: any, rowOptions?: RowOptionsRaw): this; | ||
printTable(): void; | ||
render(): string; | ||
} |
@@ -14,11 +14,15 @@ "use strict"; | ||
this.table.addColumn(column); | ||
return this; | ||
} | ||
addColumns(columns) { | ||
this.table.addColumns(columns); | ||
return this; | ||
} | ||
addRow(text, rowOptions) { | ||
this.table.addRow(text, table_helpers_1.convertRawRowOptionsToStandard(rowOptions)); | ||
this.table.addRow(text, (0, table_helpers_1.convertRawRowOptionsToStandard)(rowOptions)); | ||
return this; | ||
} | ||
addRows(toBeInsertedRows, rowOptions) { | ||
this.table.addRows(toBeInsertedRows, table_helpers_1.convertRawRowOptionsToStandard(rowOptions)); | ||
this.table.addRows(toBeInsertedRows, (0, table_helpers_1.convertRawRowOptionsToStandard)(rowOptions)); | ||
return this; | ||
} | ||
@@ -25,0 +29,0 @@ printTable() { |
@@ -14,3 +14,3 @@ "use strict"; | ||
exports.objIfExists = objIfExists; | ||
const rawColumnToInternalColumn = (column) => (Object.assign(Object.assign(Object.assign(Object.assign({ name: column.name, title: column.title || column.name }, exports.objIfExists('color', column.color)), exports.objIfExists('maxLen', column.maxLen)), exports.objIfExists('minLen', column.minLen)), { alignment: column.alignment || table_constants_1.DEFAULT_ROW_ALIGNMENT })); | ||
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 })); | ||
exports.rawColumnToInternalColumn = rawColumnToInternalColumn; |
@@ -14,4 +14,4 @@ "use strict"; | ||
// ║ Index ║ ║ ║ | ||
const renderOneLine = (tableStyle, columns, currentLineIndex, widthLimitedColumnsArray, isHeader, row) => { | ||
const line = new colored_console_line_1.default(); | ||
const renderOneLine = (tableStyle, columns, currentLineIndex, widthLimitedColumnsArray, isHeader, row, colorMap) => { | ||
const line = new colored_console_line_1.default(colorMap); | ||
line.addCharsWithColor(table_constants_1.DEFAULT_ROW_FONT_COLOR, tableStyle.vertical); | ||
@@ -21,6 +21,6 @@ columns.forEach((column) => { | ||
const textForThisLine = thisLineHasText | ||
? table_helpers_1.cellText(widthLimitedColumnsArray[column.name][currentLineIndex]) | ||
? (0, table_helpers_1.cellText)(widthLimitedColumnsArray[column.name][currentLineIndex]) | ||
: ''; | ||
line.addCharsWithColor(table_constants_1.DEFAULT_ROW_FONT_COLOR, ' '); | ||
line.addCharsWithColor((isHeader && table_constants_1.DEFAULT_HEADER_FONT_COLOR) || column.color || row.color, string_utils_1.textWithPadding(textForThisLine, column.alignment || table_constants_1.DEFAULT_ROW_ALIGNMENT, column.length || table_constants_1.DEFAULT_COLUMN_LEN)); | ||
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)); | ||
line.addCharsWithColor(table_constants_1.DEFAULT_ROW_FONT_COLOR, ` ${tableStyle.vertical}`); | ||
@@ -32,9 +32,9 @@ }); | ||
// ║ Index ║ ║ ║ | ||
const renderWidthLimitedLines = (tableStyle, columns, row, isHeader) => { | ||
const renderWidthLimitedLines = (tableStyle, columns, row, colorMap, isHeader) => { | ||
// { col1: ['How', 'Is', 'Going'], col2: ['I am', 'Tom'], } | ||
const widthLimitedColumnsArray = table_helpers_1.getWidthLimitedColumnsArray(columns, row); | ||
const widthLimitedColumnsArray = (0, table_helpers_1.getWidthLimitedColumnsArray)(columns, row); | ||
const totalLines = Object.values(widthLimitedColumnsArray).reduce((a, b) => Math.max(a, b.length), 0); | ||
const ret = []; | ||
for (let currentLineIndex = 0; currentLineIndex < totalLines; currentLineIndex += 1) { | ||
const singleLine = renderOneLine(tableStyle, columns, currentLineIndex, widthLimitedColumnsArray, isHeader, row); | ||
const singleLine = renderOneLine(tableStyle, columns, currentLineIndex, widthLimitedColumnsArray, isHeader, row, colorMap); | ||
ret.push(singleLine); | ||
@@ -47,3 +47,3 @@ } | ||
let ret = []; | ||
ret = ret.concat(renderWidthLimitedLines(table.tableStyle, table.columns, row)); | ||
ret = ret.concat(renderWidthLimitedLines(table.tableStyle, table.columns, row, table.colorMap)); | ||
return ret; | ||
@@ -68,4 +68,4 @@ }; | ||
}; | ||
const titleWithPadding = string_utils_1.textWithPadding(table.title, table_constants_1.DEFAULT_HEADER_ALIGNMENT, getTableWidth()); | ||
const styledText = new colored_console_line_1.default(); | ||
const titleWithPadding = (0, string_utils_1.textWithPadding)(table.title, table_constants_1.DEFAULT_HEADER_ALIGNMENT, getTableWidth()); | ||
const styledText = new colored_console_line_1.default(table.colorMap); | ||
styledText.addCharsWithColor(table_constants_1.DEFAULT_HEADER_FONT_COLOR, titleWithPadding); | ||
@@ -84,8 +84,8 @@ // The analysis Result | ||
// ╔═══════╦═══════════════════════════════════════╦════════╗ | ||
ret.push(table_helpers_1.renderTableHorizontalBorders(table.tableStyle.headerTop, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN))); | ||
ret.push((0, table_helpers_1.renderTableHorizontalBorders)(table.tableStyle.headerTop, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN))); | ||
// ║ index ║ text ║ value ║ | ||
const row = table_helpers_1.createHeaderAsRow(table_helpers_1.createRow, table.columns); | ||
ret = ret.concat(renderWidthLimitedLines(table.tableStyle, table.columns, row, true)); | ||
const row = (0, table_helpers_1.createHeaderAsRow)(table_helpers_1.createRow, table.columns); | ||
ret = ret.concat(renderWidthLimitedLines(table.tableStyle, table.columns, row, table.colorMap, true)); | ||
// ╟═══════╬═══════════════════════════════════════╬════════╢ | ||
ret.push(table_helpers_1.renderTableHorizontalBorders(table.tableStyle.headerBottom, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN))); | ||
ret.push((0, table_helpers_1.renderTableHorizontalBorders)(table.tableStyle.headerBottom, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN))); | ||
return ret; | ||
@@ -96,3 +96,3 @@ }; | ||
// ╚═══════╩═══════════════════════════════════════╩════════╝ | ||
ret.push(table_helpers_1.renderTableHorizontalBorders(table.tableStyle.tableBottom, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN))); | ||
ret.push((0, table_helpers_1.renderTableHorizontalBorders)(table.tableStyle.tableBottom, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN))); | ||
return ret; | ||
@@ -106,3 +106,3 @@ }; | ||
// ╟═══════╬═══════════════════════════════════════╬════════╢ | ||
ret.push(table_helpers_1.renderTableHorizontalBorders(table.tableStyle.rowSeparator, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN))); | ||
ret.push((0, table_helpers_1.renderTableHorizontalBorders)(table.tableStyle.rowSeparator, table.columns.map((m) => m.length || table_constants_1.DEFAULT_COLUMN_LEN))); | ||
} | ||
@@ -112,4 +112,4 @@ return ret; | ||
const renderTable = (table) => { | ||
table_pre_processors_1.preProcessColumns(table); // enable / disable cols, find maxLn of each col/ computed Columns | ||
table_pre_processors_1.preProcessRows(table); // sort and filter | ||
(0, table_pre_processors_1.preProcessColumns)(table); // enable / disable cols, find maxLn of each col/ computed Columns | ||
(0, table_pre_processors_1.preProcessRows)(table); // sort and filter | ||
const ret = []; | ||
@@ -129,8 +129,8 @@ renderTableTitle(table).forEach((row) => ret.push(row)); | ||
table.addRows(rows); | ||
return exports.renderTable(table); | ||
return (0, exports.renderTable)(table); | ||
}; | ||
exports.renderSimpleTable = renderSimpleTable; | ||
const printSimpleTable = (rows) => { | ||
console.log(exports.renderSimpleTable(rows)); | ||
console.log((0, exports.renderSimpleTable)(rows)); | ||
}; | ||
exports.printSimpleTable = printSimpleTable; |
import { Dictionary, Row } from '../models/common'; | ||
import { ComplexOptions, ComputedColumn, RowFilterFunction, RowSortFunction } from '../models/external-table'; | ||
import { Column, TableStyleDetails } from '../models/internal-table'; | ||
import { ColorMap } from '../utils/colored-console-line'; | ||
import { RowOptions } from '../utils/table-helpers'; | ||
@@ -16,2 +17,3 @@ declare class TableInternal { | ||
rowSeparator: boolean; | ||
colorMap: ColorMap; | ||
initSimple(columns: string[]): void; | ||
@@ -18,0 +20,0 @@ initDetailed(options: ComplexOptions): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const colored_console_line_1 = require("../utils/colored-console-line"); | ||
const table_constants_1 = require("../utils/table-constants"); | ||
@@ -22,2 +23,3 @@ const table_helpers_1 = require("../utils/table-helpers"); | ||
this.rowSeparator = table_constants_1.DEFAULT_ROW_SEPARATOR; | ||
this.colorMap = colored_console_line_1.DEFAULT_COLOR_MAP; | ||
if (options instanceof Array) { | ||
@@ -49,2 +51,8 @@ this.initSimple(options); | ||
this.rowSeparator = (options === null || options === void 0 ? void 0 : options.rowSeparator) || this.rowSeparator; | ||
if (options === null || options === void 0 ? void 0 : options.colorMap) { | ||
this.colorMap = Object.assign(Object.assign({}, this.colorMap), options.colorMap); | ||
} | ||
if (options.rows !== undefined) { | ||
this.addRows(options.rows); | ||
} | ||
} | ||
@@ -55,3 +63,3 @@ createColumnFromRow(text) { | ||
if (!colNames.includes(key)) { | ||
this.columns.push(table_helpers_1.createColumFromOnlyName(key)); | ||
this.columns.push((0, table_helpers_1.createColumFromOnlyName)(key)); | ||
} | ||
@@ -62,6 +70,6 @@ }); | ||
if (typeof textOrObj === 'string') { | ||
this.columns.push(table_helpers_1.createColumFromOnlyName(textOrObj)); | ||
this.columns.push((0, table_helpers_1.createColumFromOnlyName)(textOrObj)); | ||
} | ||
else { | ||
this.columns.push(table_helpers_1.createColumFromComputedColumn(textOrObj)); | ||
this.columns.push((0, table_helpers_1.createColumFromComputedColumn)(textOrObj)); | ||
} | ||
@@ -76,3 +84,3 @@ } | ||
this.createColumnFromRow(text); | ||
this.rows.push(table_helpers_1.createRow((options === null || options === void 0 ? void 0 : options.color) || table_constants_1.DEFAULT_ROW_FONT_COLOR, text, (options === null || options === void 0 ? void 0 : options.separator) !== undefined | ||
this.rows.push((0, table_helpers_1.createRow)((options === null || options === void 0 ? void 0 : options.color) || table_constants_1.DEFAULT_ROW_FONT_COLOR, text, (options === null || options === void 0 ? void 0 : options.separator) !== undefined | ||
? options === null || options === void 0 ? void 0 : options.separator | ||
@@ -87,5 +95,5 @@ : this.rowSeparator)); | ||
renderTable() { | ||
return internal_table_printer_1.renderTable(this); | ||
return (0, internal_table_printer_1.renderTable)(this); | ||
} | ||
} | ||
exports.default = TableInternal; |
@@ -27,3 +27,3 @@ "use strict"; | ||
table.columns.forEach((column) => { | ||
column.length = table_helpers_1.findLenOfColumn(column, table.rows); | ||
column.length = (0, table_helpers_1.findLenOfColumn)(column, table.rows); | ||
}); | ||
@@ -30,0 +30,0 @@ }; |
@@ -1,2 +0,3 @@ | ||
import { ALIGNMENT, COLOR } from './common'; | ||
import { ColorMap } from '../utils/colored-console-line'; | ||
import { ALIGNMENT, COLOR, Dictionary } from './common'; | ||
import { TableStyleDetails } from './internal-table'; | ||
@@ -21,2 +22,3 @@ export { ALIGNMENT, COLOR }; | ||
columns?: ColumnOptionsRaw[]; | ||
rows?: Dictionary[]; | ||
sort?: RowSortFunction; | ||
@@ -28,2 +30,3 @@ filter?: RowFilterFunction; | ||
rowSeparator?: boolean; | ||
colorMap?: ColorMap; | ||
} |
import { COLOR } from '../models/common'; | ||
export declare const colorString: (color: COLOR, text: string) => string; | ||
export declare type ColorMap = { | ||
[key in COLOR]?: string; | ||
}; | ||
export declare const DEFAULT_COLOR_MAP: ColorMap; | ||
export default class ColoredConsoleLine { | ||
text: string; | ||
constructor(); | ||
colorMap: ColorMap; | ||
constructor(colorMap?: ColorMap); | ||
addCharsWithColor(color: COLOR, text: string): void; | ||
renderConsole(): string; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.colorString = void 0; | ||
const COLOR_MAP = { | ||
exports.DEFAULT_COLOR_MAP = void 0; | ||
exports.DEFAULT_COLOR_MAP = { | ||
red: '\x1b[31m', | ||
@@ -16,10 +16,13 @@ green: '\x1b[32m', | ||
}; | ||
const colorString = (color, text) => `${color && COLOR_MAP[color]}${text}${COLOR_MAP.reset}`; | ||
exports.colorString = colorString; | ||
class ColoredConsoleLine { | ||
constructor() { | ||
constructor(colorMap = exports.DEFAULT_COLOR_MAP) { | ||
this.text = ''; | ||
this.colorMap = colorMap; | ||
} | ||
addCharsWithColor(color, text) { | ||
this.text += exports.colorString(color, text); | ||
const colorAnsi = this.colorMap[color]; | ||
this.text += | ||
colorAnsi !== undefined | ||
? `${colorAnsi}${text}${this.colorMap.reset}` | ||
: text; | ||
} | ||
@@ -26,0 +29,0 @@ renderConsole() { |
@@ -7,3 +7,3 @@ "use strict"; | ||
const stripAnsi = (str) => str.replace(colorRegex, ''); | ||
const findWidthInConsole = (str) => simple_wcswidth_1.wcswidth(stripAnsi(str)); | ||
const findWidthInConsole = (str) => (0, simple_wcswidth_1.wcswidth)(stripAnsi(str)); | ||
exports.default = findWidthInConsole; |
@@ -11,3 +11,3 @@ "use strict"; | ||
const textWithPadding = (text, alignment, columnLen) => { | ||
const curTextSize = console_utils_1.default(text); | ||
const curTextSize = (0, console_utils_1.default)(text); | ||
// alignments for center padding case | ||
@@ -38,3 +38,3 @@ const leftPadding = Math.floor((columnLen - curTextSize) / 2); | ||
spaceSeparatedStrings.forEach((strWithoutSpace) => { | ||
const consoleWidth = console_utils_1.default(strWithoutSpace); | ||
const consoleWidth = (0, console_utils_1.default)(strWithoutSpace); | ||
if (cnt + consoleWidth <= width) { | ||
@@ -55,3 +55,3 @@ cnt += consoleWidth + 1; // 1 for the space | ||
// ("How are you?",10) => ["How are ", "you?"] | ||
const biggestWordInSentence = (inpStr) => inpStr.split(' ').reduce((a, b) => Math.max(a, console_utils_1.default(b)), 0); | ||
const biggestWordInSentence = (inpStr) => inpStr.split(' ').reduce((a, b) => Math.max(a, (0, console_utils_1.default)(b)), 0); | ||
exports.biggestWordInSentence = biggestWordInSentence; |
@@ -45,3 +45,3 @@ "use strict"; | ||
exports.createColumFromOnlyName = createColumFromOnlyName; | ||
const createColumFromComputedColumn = (column) => (Object.assign(Object.assign(Object.assign(Object.assign({ name: column.name, title: column.title || column.name }, input_converter_1.objIfExists('color', column.color)), input_converter_1.objIfExists('maxLen', column.maxLen)), input_converter_1.objIfExists('minLen', column.minLen)), { alignment: column.alignment || table_constants_1.DEFAULT_ROW_ALIGNMENT })); | ||
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 })); | ||
exports.createColumFromComputedColumn = createColumFromComputedColumn; | ||
@@ -61,9 +61,9 @@ const createRow = (color, text, separator) => ({ | ||
// if others cant fit find the max word length so that at least the table can be printed | ||
length = max(length, max(column.maxLen, string_utils_1.biggestWordInSentence(columnTitle))); | ||
length = rows.reduce((acc, row) => max(acc, string_utils_1.biggestWordInSentence(exports.cellText(row.text[columnId]))), length); | ||
length = max(length, max(column.maxLen, (0, string_utils_1.biggestWordInSentence)(columnTitle))); | ||
length = rows.reduce((acc, row) => max(acc, (0, string_utils_1.biggestWordInSentence)((0, exports.cellText)(row.text[columnId]))), length); | ||
return length; | ||
} | ||
length = max(length, console_utils_1.default(columnTitle)); | ||
length = max(length, (0, console_utils_1.default)(columnTitle)); | ||
rows.forEach((row) => { | ||
length = max(length, console_utils_1.default(exports.cellText(row.text[columnId]))); | ||
length = max(length, (0, console_utils_1.default)((0, exports.cellText)(row.text[columnId]))); | ||
}); | ||
@@ -74,3 +74,3 @@ return length; | ||
const renderTableHorizontalBorders = (style, column_lengths) => { | ||
const str = exports.createTableHorizontalBorders(style, column_lengths); | ||
const str = (0, exports.createTableHorizontalBorders)(style, column_lengths); | ||
return str; | ||
@@ -92,3 +92,3 @@ }; | ||
columns.forEach((column) => { | ||
ret[column.name] = string_utils_1.limitWidth(exports.cellText(row.text[column.name]), column.length || table_constants_1.DEFAULT_COLUMN_LEN); | ||
ret[column.name] = (0, string_utils_1.limitWidth)((0, exports.cellText)(row.text[column.name]), column.length || table_constants_1.DEFAULT_COLUMN_LEN); | ||
}); | ||
@@ -95,0 +95,0 @@ return ret; |
{ | ||
"name": "console-table-printer", | ||
"version": "2.10.0", | ||
"version": "2.11.0", | ||
"repository": "github:ayonious/console-table-printer", | ||
@@ -28,20 +28,20 @@ "description": "Printing pretty tables on console log", | ||
"devDependencies": { | ||
"@semantic-release/changelog": "^5.0.1", | ||
"@semantic-release/git": "^9.0.0", | ||
"@types/jest": "^26.0.24", | ||
"@typescript-eslint/eslint-plugin": "^4.29.0", | ||
"@typescript-eslint/parser": "^4.29.0", | ||
"@semantic-release/changelog": "^6.0.1", | ||
"@semantic-release/git": "^10.0.1", | ||
"@types/jest": "^27.0.2", | ||
"@typescript-eslint/eslint-plugin": "^5.2.0", | ||
"@typescript-eslint/parser": "^5.2.0", | ||
"chalk": "^4.1.2", | ||
"eslint": "^7.32.0", | ||
"eslint": "^8.1.0", | ||
"eslint-config-airbnb-base": "^14.2.1", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-import": "^2.23.4", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"husky": "^7.0.1", | ||
"jest": "^27.0.6", | ||
"prettier": "^2.3.2", | ||
"eslint-plugin-import": "^2.25.2", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"husky": "^7.0.4", | ||
"jest": "^27.3.1", | ||
"prettier": "^2.4.1", | ||
"pretty-quick": "^3.1.1", | ||
"semantic-release": "^17.4.4", | ||
"ts-jest": "^27.0.4", | ||
"typescript": "^4.3.5" | ||
"semantic-release": "^18.0.0", | ||
"ts-jest": "^27.0.7", | ||
"typescript": "^4.4.4" | ||
}, | ||
@@ -48,0 +48,0 @@ "homepage": "https://console-table.netlify.app", |
@@ -92,11 +92,17 @@ <h1 align="center">console-table-printer</h1> | ||
columns: [ | ||
{ name: 'index', alignment: 'left', color: 'blue' }, //with alignment and color | ||
{ name: 'index', alignment: 'left', color: 'blue' }, // with alignment and color | ||
{ name: 'text', alignment: 'right' }, | ||
{ name: 'is_priority_today', title: 'Is This Priority?' }, // with Title as separate Text | ||
], | ||
colorMap: { | ||
custom_green: '\x1b[32m', // define customized color | ||
}, | ||
}); | ||
p.addRow({ index: 1, text: 'red wine', value: 10.212 }, { color: 'green' }); | ||
p.addRow({ index: 2, text: 'green gemuse', value: 20.0 }); | ||
p.addRow( | ||
{ index: 2, text: 'green gemuse', value: 20.0 }, | ||
{ color: 'custom_green' } // your green | ||
); | ||
p.addRow( | ||
{ index: 3, text: 'gelb bananen', value: 100, is_priority_today: 'Y' }, | ||
@@ -112,3 +118,3 @@ { color: 'yellow' } | ||
![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/screenshot-column-props.png) | ||
![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/screenshot-column-props-2.png) | ||
@@ -141,2 +147,3 @@ ## CLI | ||
], | ||
rows: [{ column1: 'row1' }, { column2: 'row2' }, { column3: 'row3' }], | ||
sort: (row1, row2) => row2.column1 - row1.column1, // sorting order of rows (optional), this is normal js sort function for Array.sort | ||
@@ -143,0 +150,0 @@ filter: (row) => row.column1 < 3, // filtering rows (optional) |
756
188
42657
31