console-table-printer
Advanced tools
Comparing version 2.11.2 to 2.12.0
@@ -31,3 +31,6 @@ "use strict"; | ||
this.charLength = (options === null || options === void 0 ? void 0 : options.charLength) || this.charLength; | ||
if (options === null || options === void 0 ? void 0 : options.colorMap) { | ||
if (options === null || options === void 0 ? void 0 : options.shouldDisableColors) { | ||
this.colorMap = {}; | ||
} | ||
else if (options === null || options === void 0 ? void 0 : options.colorMap) { | ||
this.colorMap = Object.assign(Object.assign({}, this.colorMap), options.colorMap); | ||
@@ -34,0 +37,0 @@ } |
@@ -29,4 +29,5 @@ import { ColorMap } from '../utils/colored-console-line'; | ||
rowSeparator?: boolean; | ||
shouldDisableColors?: boolean; | ||
colorMap?: ColorMap; | ||
charLength?: CharLengthDict; | ||
} |
import { ALIGNMENT, CharLengthDict } from '../models/common'; | ||
export declare const splitTextIntoTextsOfMinLen: (inpStr: string, width: number, charLength?: CharLengthDict) => string[]; | ||
export declare const textWithPadding: (text: string, alignment: ALIGNMENT, columnLen: number, charLength?: CharLengthDict) => string; | ||
export declare const limitWidth: (inpStr: string, width: number, charLength?: CharLengthDict) => string[]; | ||
export declare const biggestWordInSentence: (inpStr: string, charLength?: CharLengthDict) => number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.biggestWordInSentence = exports.limitWidth = exports.textWithPadding = void 0; | ||
exports.biggestWordInSentence = exports.textWithPadding = exports.splitTextIntoTextsOfMinLen = void 0; | ||
const console_utils_1 = require("./console-utils"); | ||
// ("How are you?",10) => ["How are ", "you?"] | ||
const splitTextIntoTextsOfMinLen = (inpStr, width, charLength) => { | ||
const ret = []; | ||
const spaceSeparatedStrings = inpStr.split(' '); | ||
let now = []; | ||
let cnt = 0; | ||
spaceSeparatedStrings.forEach((strWithoutSpace) => { | ||
const consoleWidth = (0, console_utils_1.findWidthInConsole)(strWithoutSpace, charLength); | ||
if (cnt + consoleWidth <= width) { | ||
cnt += consoleWidth + 1; // 1 for the space | ||
now.push(strWithoutSpace); | ||
} | ||
else { | ||
ret.push(now.join(' ')); | ||
now = [strWithoutSpace]; | ||
cnt = consoleWidth + 1; | ||
} | ||
}); | ||
ret.push(now.join(' ')); | ||
return ret; | ||
}; | ||
exports.splitTextIntoTextsOfMinLen = splitTextIntoTextsOfMinLen; | ||
// ("How are you?",center, 20) => " How are you? " | ||
// ("How are you?",right, 20) => " How are you?" | ||
// ("How are you?",center, 4) => "How\nare\nyou?" | ||
const textWithPadding = (text, alignment, columnLen, charLength) => { | ||
@@ -14,3 +37,9 @@ const curTextSize = (0, console_utils_1.findWidthInConsole)(text, charLength); | ||
if (columnLen < curTextSize) { | ||
return text; | ||
const splittedLines = (0, exports.splitTextIntoTextsOfMinLen)(text, columnLen); | ||
if (splittedLines.length === 1) { | ||
return text; | ||
} | ||
return splittedLines | ||
.map((singleLine) => (0, exports.textWithPadding)(singleLine, alignment, columnLen, charLength)) | ||
.join('\n'); | ||
} | ||
@@ -33,24 +62,2 @@ // console.log(text, columnLen, curTextSize); | ||
// ("How are you?",10) => ["How are ", "you?"] | ||
const limitWidth = (inpStr, width, charLength) => { | ||
const ret = []; | ||
const spaceSeparatedStrings = inpStr.split(' '); | ||
let now = []; | ||
let cnt = 0; | ||
spaceSeparatedStrings.forEach((strWithoutSpace) => { | ||
const consoleWidth = (0, console_utils_1.findWidthInConsole)(strWithoutSpace, charLength); | ||
if (cnt + consoleWidth <= width) { | ||
cnt += consoleWidth + 1; // 1 for the space | ||
now.push(strWithoutSpace); | ||
} | ||
else { | ||
ret.push(now.join(' ')); | ||
now = [strWithoutSpace]; | ||
cnt = consoleWidth + 1; | ||
} | ||
}); | ||
ret.push(now.join(' ')); | ||
return ret; | ||
}; | ||
exports.limitWidth = limitWidth; | ||
// ("How are you?",10) => ["How are ", "you?"] | ||
const biggestWordInSentence = (inpStr, charLength) => inpStr | ||
@@ -57,0 +64,0 @@ .split(' ') |
@@ -89,3 +89,3 @@ "use strict"; | ||
columns.forEach((column) => { | ||
ret[column.name] = (0, string_utils_1.limitWidth)((0, exports.cellText)(row.text[column.name]), column.length || table_constants_1.DEFAULT_COLUMN_LEN, charLength); | ||
ret[column.name] = (0, string_utils_1.splitTextIntoTextsOfMinLen)((0, exports.cellText)(row.text[column.name]), column.length || table_constants_1.DEFAULT_COLUMN_LEN, charLength); | ||
}); | ||
@@ -92,0 +92,0 @@ return ret; |
{ | ||
"name": "console-table-printer", | ||
"version": "2.11.2", | ||
"version": "2.12.0", | ||
"repository": "github:ayonious/console-table-printer", | ||
@@ -30,18 +30,17 @@ "description": "Printing pretty tables on console log", | ||
"@semantic-release/git": "^10.0.1", | ||
"@types/jest": "^29.5.2", | ||
"@typescript-eslint/eslint-plugin": "^5.60.1", | ||
"@typescript-eslint/parser": "^5.60.1", | ||
"chalk": "^4.1.2", | ||
"eslint": "^8.44.0", | ||
"@types/jest": "^29.5.11", | ||
"@typescript-eslint/eslint-plugin": "^6.15.0", | ||
"@typescript-eslint/parser": "^6.15.0", | ||
"eslint": "^8.56.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-prettier": "^5.1.0", | ||
"husky": "^8.0.3", | ||
"jest": "^29.5.0", | ||
"prettier": "^2.8.8", | ||
"jest": "^29.7.0", | ||
"prettier": "^3.1.1", | ||
"pretty-quick": "^3.1.3", | ||
"semantic-release": "^21.0.6", | ||
"semantic-release": "^22.0.12", | ||
"ts-jest": "^29.1.1", | ||
"typescript": "^5.1.6" | ||
"typescript": "^5.3.3" | ||
}, | ||
@@ -48,0 +47,0 @@ "homepage": "https://console-table.netlify.app", |
@@ -40,4 +40,4 @@ <h1 align="center">console-table-printer</h1> | ||
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 }, | ||
{ Rank: 3, text: 'I would like some Yellow', value: 100 }, | ||
{ Rank: 4, text: 'I hope batch update is working', value: 300 }, | ||
]; | ||
@@ -49,3 +49,3 @@ | ||
![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/quick-print.png) | ||
![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/readme-quick-1.png) | ||
@@ -62,9 +62,9 @@ ## 🚨🚨Announcement🚨🚨 Official Documentation is moved [Here](https://console-table.netlify.app/docs) | ||
//add rows with color | ||
p.addRow({ index: 1, text: 'red wine please', value: 10.212 }); | ||
p.addRow({ index: 2, text: 'green gemuse please', value: 20.0 }); | ||
// add rows with color | ||
p.addRow({ Record: 'a', text: 'red wine please', value: 10.212 }); | ||
p.addRow({ Record: 'b', 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 }, | ||
// adding multiple rows are possible | ||
{ Record: 'c', text: 'gelb bananen bitte', value: 100 }, | ||
{ Record: 'd', text: 'update is working', value: 300 }, | ||
]); | ||
@@ -76,3 +76,3 @@ | ||
![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/screenshot-simple.png) | ||
![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/readme-instance-1.png) | ||
@@ -83,9 +83,9 @@ You can also put some color to your table like this: | ||
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.0 }, { color: 'green' }); | ||
p.addRow({ index: 3, text: 'gelb bananen', value: 100 }, { color: 'yellow' }); | ||
p.addRow({ description: 'red wine', value: 10.212 }, { color: 'red' }); | ||
p.addRow({ description: 'green gemuse', value: 20.0 }, { color: 'green' }); | ||
p.addRow({ description: 'gelb bananen', value: 100 }, { color: 'yellow' }); | ||
p.printTable(); | ||
``` | ||
![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/screenshot-colored.png) | ||
![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/readme-color-1.png) | ||
@@ -97,3 +97,3 @@ You can also put properties based on columns (color/alignment/title) | ||
columns: [ | ||
{ name: 'index', alignment: 'left', color: 'blue' }, // with alignment and color | ||
{ name: 'id', alignment: 'left', color: 'blue' }, // with alignment and color | ||
{ name: 'text', alignment: 'right' }, | ||
@@ -107,19 +107,17 @@ { name: 'is_priority_today', title: 'Is This Priority?' }, // with Title as separate Text | ||
p.addRow({ index: 1, text: 'red wine', value: 10.212 }, { color: 'green' }); | ||
p.addRow({ id: 1, text: 'red wine', value: 10.212 }, { color: 'green' }); | ||
p.addRow( | ||
{ index: 2, text: 'green gemuse', value: 20.0 }, | ||
{ id: 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' }, | ||
{ id: 3, text: 'gelb bananen', value: 100, is_priority_today: 'Y' }, | ||
{ color: 'yellow' } | ||
); | ||
p.addRow( | ||
{ index: 3, text: 'rosa hemd wie immer', value: 100 }, | ||
{ color: 'cyan' } | ||
); | ||
p.addRow({ id: 3, text: 'rosa hemd wie immer', value: 100 }, { color: 'cyan' }); | ||
p.printTable(); | ||
``` | ||
![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/screenshot-column-props-2.png) | ||
![Screenshot](https://cdn.jsdelivr.net/gh/ayonious/console-table-printer@master/static-resources/readme-columns-1.png) | ||
@@ -126,0 +124,0 @@ ## CLI |
44825
17
794
193