Giter Site home page Giter Site logo

ayonious / console-table-printer Goto Github PK

View Code? Open in Web Editor NEW
170.0 3.0 22.0 2.2 MB

๐Ÿ–ฅ๏ธ ๐Ÿญ Printing Pretty Tables on your console

Home Page: https://console-table.netlify.app

License: MIT License

TypeScript 100.00%
console tables consolelog opensource opensource-library

console-table-printer's Introduction

console-table-printer

๐Ÿ–ฅ๏ธ๐ŸญPrinting Pretty Tables on your console

codecov npm version install size

code style: prettier semantic-release

Synopsis

Printing Simple Table with Coloring rows on your console. Its useful when you want to present some tables on console using js.

Installation

npm install console-table-printer --save

Basic Example

const { printTable } = require('console-table-printer');

//Create a table
const testCases = [
  { Rank: 3, text: 'I would like some Yellow', value: 100 },
  { Rank: 4, text: 'I hope batch update is working', value: 300 },
];

//print
printTable(testCases);

Screenshot

๐Ÿšจ๐ŸšจAnnouncement๐Ÿšจ๐Ÿšจ Official Documentation is moved Here

You can also create a Table instance and print it:

const { Table } = require('console-table-printer');

//Create a table
const p = new Table();

// 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
  { Record: 'c', text: 'gelb bananen bitte', value: 100 },
  { Record: 'd', text: 'update is working', value: 300 },
]);

//print
p.printTable();

Screenshot

You can also put some color to your table like this:

const p = new Table();
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

You can also put properties based on columns (color/alignment/title)

const p = new Table({
  columns: [
    { name: 'id', 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({ id: 1, text: 'red wine', value: 10.212 }, { color: 'green' });
p.addRow(
  { id: 2, text: 'green gemuse', value: 20.0 },
  { color: 'custom_green' } // your green
);
p.addRow(
  { id: 3, text: 'gelb bananen', value: 100, is_priority_today: 'Y' },
  { color: 'yellow' }
);
p.addRow({ id: 3, text: 'rosa hemd wie immer', value: 100 }, { color: 'cyan' });

p.printTable();

Screenshot

CLI

There is also a CLI tool for printing Tables on Terminal directly table-printer-cli

Documentation

Official documentation has been moved here: console-table-documentation

Table instance creation

3 ways to Table Instance creation:

  1. Simplest way new Table()

  2. Only with column names: new Table(['column1', 'column2', 'column3'])

  3. Detailed way of creating table instance

new Table({
  title: 'Title of the Table', // A text showsup on top of table (optoinal)
  columns: [
    { name: 'column1', alignment: 'left', color: 'red' }, // with alignment and color
    { name: 'column2', alignment: 'right', maxLen: 30 }, // lines bigger than this will be splitted in multiple lines
    { name: 'column3', title: 'Column3' }, // Title is what will be shown while printing, by default title = name
  ],
  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
  filter: (row) => row.column1 < 3, // filtering rows (optional)
  enabledColumns: ['column1'], // array of columns that you want to see, all other will be ignored (optional)
  disabledColumns: ['column2'], // array of columns that you DONT want to see, these will always be hidden
  colorMap: {
    custom_green: '\x1b[32m', // define customized color
  },
  charLength: {
    '๐Ÿ‘‹': 2,
    '๐Ÿ˜…': 2,
  }, // custom len of chars in console
});

Functions

  • addRow(rowObjet, options) adding single row. This can be chained
  • addRows(rowObjects, options) 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

Check Docs: color-vals

Example usage: To Create a row of color blue

table.addRow(rowObject, { color: 'blue' });

Example usage: To apply blue for all rows

table.addRows(rowsArray, { color: 'blue' });

possible alignment values for columns

Check Docs: alignment-vals

Typescript Support

You can get color / alignment as types. Check Docs: types-docs

License

MIT

console-table-printer's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

console-table-printer's Issues

Feature Request: Allow setting different column name for a column

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?

newlines in cells produce newlines in table

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    โ”‚      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Option for minColSize

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.

Box Print

Sometimes you want to show a text as a banner that is wrapped up with box.

data alignment

It would be a nice feature if one could control alignment (left/right/center) of data within the cells - by column, say.

Returning the table as output

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.

request: include release artifacts & tags

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!

Table from object with config arguments for all columns

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!

Error: Invalid count value when no rows

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.

Feature: calculated Column

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%

alignment: 'center'

This is a feature request to add support for center aligning columns. Right now, it only supports left and right.

Computed columns show name as title even when different title is passed

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 });

Feature: View vol, hide col

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"]
});

where did the zeros go?

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?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

circleci
.circleci/config.yml
  • cimg/node 22.2.0
npm
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

  • Check this box to trigger a request for Renovate to run again on this repository

unicode breaks alignment

image

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

Emoji charLength when combining with text

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?

Emojis can break the rendering

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()

Result:
image

Sort by column names

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?

How to format Dates with printTable ?

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!

Print table without Table Header

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?

Action Required: Fix Renovate Configuration

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.

Convenience method like `console.table`?

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)

If the input in the form contains Chinese characters, the layout is wrong

็คบไพ‹ไปฃ็ ๏ผš
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();

่พ“ๅ…ฅ็ป“ๆžœ๏ผš
image

CLI feature

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 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Render raw string

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

Render to string

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.

Split also long paths into multi line

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

Adding color to a cell messes up spacing

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.

Hard to identify rows if multiline columns are present

Currently if there are multiple line column (width limited column), it looks hard to detect separate rows.

fish__Users_nahiyankamal_Desktop_ayonious_console-table-printer

Would be good to have a way to put a separator between each row in this case to figure out each row.

Something like this would be nice:

fish__Users_nahiyankamal_Desktop_ayonious_console-table-printer

width issue with Table showing different Characters of another language

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.

Order of columns?

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.

Feature request: print multiple tables, side-by-side

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);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.