ayonious / console-table-printer Goto Github PK
View Code? Open in Web Editor NEW๐ฅ๏ธ ๐ญ Printing Pretty Tables on your console
Home Page: https://console-table.netlify.app
License: MIT License
๐ฅ๏ธ ๐ญ Printing Pretty Tables on your console
Home Page: https://console-table.netlify.app
License: MIT License
Sometimes when the json input is too huge its better to be able to configure which columns I want to see. or which columns I dont want to see.
Could be something like this
new Table({
hide_columns: ["col1"],
show_colmumns: ["col2"]
});
Great job with this module.
When creating a computed column with a custom title, the column will still display the name as a title.
computedColumns: [{
title: "my title",
name: "col_name",
function: row => "row value"
}]
Maybe createColumn could receive a title as well? Some pseudo-code:
export const createColum = (name: string, title: string): Column => ({ name, title: title ? title : name });
This needs to be reduced
Would be good to give input a function that will generate a new column.
Example Problem: I would like to get % of each row (apple_percent) Where input columns are only
apple_amount, orange_amount
apple_amount orange_amount apple_percent
1 1 50
2 1 33.3%
Curently the addRows()
method doesnt take color arguement. A common color for addRows method should be supported
If I have a very long path in my table, is it possible to also split after /
character?
Example: /home/user/project/subproject/category/66623/contents/fd6873d67a3f3d67a3.jpg
Should be in the table (with maxLen) something like:
/home/user/project/subproject/
category/66623/contents/
fd6873d67a3f3d67a3.jpg
console-table-printer v2.9.0
const bundle = new Table({
title: 'Bundle (BUNDLENAME)',
columns: [
{ name: 'Weapon' },
{ name: 'Chroma' },
{ name: 'Quality' },
{ name: 'Price' },
],
})
bundle.addRows([
{
Weapon: '๐๐ป',
Chroma: 'โ
',
Quality: 'Deluxe',
Price: '1 775 VP',
},
])
bundle.printTable()
There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.
Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.
็คบไพไปฃ็ ๏ผ
const { Table } = require('console-table-printer');
const p = new Table();
let MAP = {
'libVersion': 'ๅฐ็จๅบSDK็ๆฌๅบ',
'es6': 'ES6่ฝฌES5',
'enhance': 'ๅขๅผบ็ผ่ฏ',
'nodeModules': 'ไฝฟ็จnpmๆจกๅ',
'minified': 'ไธไผ ไปฃ็ ่ชๅจๅ็ผฉๆททๆท'
};
for (let keyName in MAP) {
p.addRow({ '้้กน': MAP[keyName], '่ฎพ็ฝฎ็ๅผ': resourceValue, 'ๅ่ๅผ': targetValue });
}
p.printTable();
Sometimes you want to show a text as a banner that is wrapped up with box.
This is a feature request to add support for center aligning columns. Right now, it only supports left and right.
At end of each table we can print the av/sum of a column.
Thanks for the library.
Can you add a feature where the table is sorted by column names and enable passing in something like 'ASC' or 'DESC' and also by defined column header names I pass?
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
@typescript-eslint/eslint-plugin
, @typescript-eslint/parser
, cimg/node
, eslint
, eslint-plugin-prettier
, husky
, prettier
, ts-jest
, typescript
).circleci/config.yml
cimg/node 22.2.0
package.json
simple-wcswidth ^1.0.1
@semantic-release/changelog ^6.0.3
@semantic-release/git ^10.0.1
@types/jest ^29.5.12
@typescript-eslint/eslint-plugin ^7.13.1
@typescript-eslint/parser ^7.13.1
eslint ^9.5.0
eslint-config-airbnb-base ^15.0.0
eslint-config-prettier ^9.1.0
eslint-plugin-import ^2.29.1
eslint-plugin-prettier ^5.1.3
husky ^9.0.11
jest ^29.7.0
prettier ^3.3.2
pretty-quick ^4.0.0
semantic-release ^24.0.0
ts-jest ^29.1.5
typescript ^5.4.5
Hi,
Thanks for writing this - we quite like it.
I noticed a bunch of new versions, but there isn't a changelog, nor tags on the repo mapping back to the NPM package.
Just some friendly feedback for users - it would be great if we could see a change log file or at least tags on the repo that match the npm artifacts. We actually use this in a cli app that we share with 50+ people so it would be nice to make the upgrade path a little easier.
I've found using commitizen and standard-version packages make this quite a nice experience - if you were looking for a suggestion.
Anyways, thanks again for publishing this!
Coneverting the Repo to Typescript
See #57 for another report of similar bug.
If I do something like:
const p = new Table();
p.addRows(
[
{ index: 3, text: chalk.red("text"), value: 100 },
{ index: 4, text: 'short', value: 300 },
],
);
p.printTable();
Then the spacing for the cell is off because it's width is incorrectly calculated.
I can't find any way to make the columns appear in the table in a certain order.
In particular, they don't follow the order in the columns
, or enabledColumns
attribute fed to the table constructor.
color.
alignment
const { printTable } = require('./dist');
//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: 4, text: 'Unicode.... \uD83C\uDD9E', value: 300 },
];
//print
printTable(testCases);
This might be of interest: https://stackoverflow.com/questions/54369513/how-to-count-the-correct-length-of-a-string-with-emojis-in-javascript
Though the fix likely is [...str].length
. Example:
let str = `Unicode.... \uD83C\uDD9E`
console.log(str.length) // 14
console.log([...str].length) // 13
Hi,
I am trying to implement a dotmatrix print functionality for invoice generated by web application in browser and by default browser send the HTML as bitmap to printer and dotmatrix printer are not good in bitmap/image printing.
As it is an invoice on pre-printed stationery and columns width is fixed, I need to provide min column width or you can say fixed width column.
Another enhancement is to print a table without column header.
Thanks.
Currently print function only prints the results on console.
It would be cool if it also returns the table as array.
This way user can also print it in some file or any other place he wants.
In case of line being too long would be good this line to be splited based on max width of the column. Currently everything is printed in one line
Originally reported by @rylanzhou
I've found that if the text to be displayed contains special characters, e.g., chinese, which actually takes up two spaces for one character, it will cause alignment problems. Here's an example:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ
โ SUMMARY โ KEY โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโค
โ Some Descriptions and Summary ่ฟ้ๆฏไธญๆ่ฟ้ๆฏไธญๆ่ฟ้ๆฏไธญๆ โ ISSUE-19150 โ
โ Some Summary ่ฟ้ๆฏไธญๆ่ฟ้ๆฏไธญๆ โ ISSUE-18072 โ
โ Description ่ฟ้ๆฏไธญๆ โ ISSUE-17787 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโ
By doing some research, I figured out that this is because the original str.length
does not output the correct unicode length of a special character.
'char'.length; // Outputs 4, correct
'ไธญ'.length; // Outputs 1, but it actually contains 2 unicodes
The same problem also occurs when calling str.padEnd()
and str.padStart()
.
Hoping to fix this for better compatibility, I've installed a dependency called wcwidth
. This dependency would correctly return the unicode length of any special character.
I don't understand how the charLength
works when combined with text.
https://console-table.netlify.app/docs/doc-emojis-special-chars
See this example:
import { Table } from "console-table-printer";
const table = new Table({
rows: [
{
file: "All files",
"% score": 87.87,
"โ
killed": 158,
"โณ timeout": 4,
"๐ฝ survived": 15,
"๐ no cov": 8,
"๐ฅ error": 0,
},
],
charLength: { "โณ": 3, "โ
": 2, "๐ฝ": 2, "๐": 2, "๐ฅ": 2 },
});
table.printTable();
This outputs:
โโโโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโโโฌโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโฌโโโโโโโโโโโโฌโโโโโโโโโโโ
โ file โ % score โ โ
killed โ โณ timeout โ ๐ฝ survived โ ๐ no cov โ ๐ฅ error โ
โโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโโโโผโโโโโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโค
โ All files โ 87.87 โ 158 โ 4 โ 15 โ 8 โ 0 โ
โโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโ
But AFAIK I used the correct char lengths for the emojis. What exactly should the value of a charLength
be?
Hey!
I really appreciate your fantastic package!
I use render()
to get a string but it has come with ANSI escape codes like [37m
. Is there any way to get the raw text?
I want to use the output in a Telegram message so I need the raw text.
P.S. I can create a pull request if it's approved! Something like render(raw: boolean) => string
with the false
default value for raw
to have backward compatibility
Yo,
Nice tool! I've been using it to spice up some performance testing output, and it seems to work well.
It'd be great if there was a convenience method that matches the API of console.table
, so instead of having to do...
const t = new Table()
t.addRows(TEST_CASES)
t.printTable()
You could just do...
Table.printTable(TEST_CASES)
Example:
const p = new Table();
p.addRows([{ col1: 'col1', col2: `col\n2`, col3: 'col3' }]);
p.printTable();
produce:
โโโโโโโโฌโโโโโโโฌโโโโโโโ
โ col1 โ col2 โ col3 โ
โโโโโโโโผโโโโโโโผโโโโโโโค
โ col1 โ col
2 โ col3 โ
โโโโโโโโดโโโโโโโดโโโโโโโ
expect:
โโโโโโโโฌโโโโโโโฌโโโโโโโ
โ col1 โ col2 โ col3 โ
โโโโโโโโผโโโโโโโผโโโโโโโค
โ col1 โ col2 โ col3 โ
โ โ 2 โ โ
โโโโโโโโดโโโโโโโดโโโโโโโ
Hi, thanks for great job.
Is it possible to reset, empty rows ?
For making a dynamic array.
in a table if we can text wrap data.
Originally started from this:
#361
Im trying to find the best way to allow this.
How would the input in this case look like? Should it be array or arrays of string?
For example, if I want to color a particular cell if the user has a score >x and different when the score is <x.
Is it possible to render a table to string instead of the console? I'd like to render the table to string and send it over the wire to be rendered somewhere else.
It would be a nice feature if one could control alignment (left/right/center) of data within the cells - by column, say.
I have objects I want to pass in as rows, but I don't want to use those keys as the column headers. I would like to specify a column header name directly instead.
Something like:
const p = new Table({
columns: [
{ name: "index", title: 'Index', alignment: "left", color: "yellow" }, // column coloring
{ name: "text", title: chalk.blue('Description'), alignment: "right" },
],
});
Is this possible already?
Would be good if directly from commandline we could call this function and parse things on command line.
Example:
"[
{index: 1, talbe: "okay"},
{index: 2, talbe: "okay1"},
]" | printTable
โโโโโโโโโฌโโโโโโโโ
โ index โ talbe โ
โโโโโโโโโผโโโโโโโโค
โ 1 โ okay โ
โ 2 โ okay1 โ
โโโโโโโโโดโโโโโโโโ
Need to add code coverage tools
Thanks for this library. I really appreciate how easy it was to quickly understand and apply. Nice job on the docs and API design!
I found myself printing a couple narrow tables, where they could have fit side-by-side in my terminal. Something like this:
Table One Table Two
โโโโโโโโโฌโโโโโโโฌโโโโโโโ โโโโโโโโโฌโโโโโโโฌโโโโโโโ
โ Foo โ Bar โ Baz โ โ Foo โ Bar โ Baz โ
โโโโโโโโโผโโโโโโโผโโโโโโโค โโโโโโโโโผโโโโโโโผโโโโโโโค
โ aaa โ 13 โ 8 โ โ aaa โ 43 โ 8 โ
โ bbb โ 99 โ 10 โ โ bbb โ 12 โ 10 โ
โ ccc โ 91 โ 9 โ โ ccc โ 12 โ 9 โ
โ ddd โ 45 โ 6 โ โ ddd โ 75 โ 6 โ
โ eee โ 32 โ 4 โ โ eee โ 62 โ 4 โ
โ fff โ 31 โ 4 โ โ fff โ 61 โ 4 โ
โ ggg โ 26 โ 3 โ โ ggg โ 56 โ 3 โ
โ hhh โ 12 โ 7 โ โโโโโโโโโดโโโโโโโดโโโโโโโ
โ iii โ 21 โ 7 โ
โโโโโโโโโดโโโโโโโดโโโโโโโ
Would you be open to a PR that adds something like this? I'm thinking the API could be something like:
import { printTables } from "console-table-printer";
// ...
printTables(table1,table2);
The following code fails with the Invalid count value when no rows
error.
import { printTable, Table } from 'console-table-printer';
const table = new Table({
title: 'Project folders',
});
table.printTable();
It looks like the textWithPadding()
function in the string-utils
file does not handle situation when the size is invalid.
The use case is to print the table header even when there are no items to render.
The ability to change the header position to the bottom or the sides of the table.
Hi.
In this case:
const p = new Table();
p.addRows([{index:0, value:0}, {index:1, value:1}]);
p.printTable();
this is the result (node.js v10.16.0)
โโโโโโโโโฆโโโโโโโโ
โ index โ value โ
โโโโโโโโโฌโโโโโโโโข
โ โ โ
โ 1 โ 1 โ
โโโโโโโโโฉโโโโโโโโ
where did the zeros go?
Willing to take a crack at this myself, just let me know if this is wanted.
I think it would be useful for the Table
constructor or a static from method accepts a object and automatically generates a table. Similar to console.table
but also allows a config parameter to change column size and the like.
Let me know!
I have an array that have some Dates props,
Can we print the table with a specific date format? Any configuration ?
Thanks, the fact that I'm able to print the table is already awesome, thank you guys!
Adding a title at the top of the table would be awesome!
Thanks for the package!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.