console-table-printer icon indicating copy to clipboard operation
console-table-printer copied to clipboard

Bug: MaxLen minLen are working completely opposite as column options

Open ayonious opened this issue 7 months ago • 2 comments

ayonious avatar May 24 '25 10:05 ayonious

import { Table } from 'console-table-printer';

const p = new Table({
  columns: [
    { name: 'item', alignment: 'left' },
    {
      name: 'price',
      alignment: 'right',
      transform: (value) => `$${Number(value).toFixed(2)}`,
      maxLen: 80,
    },
  ],
});

p.addRows([
  { item: 'Coffee', price: 3.5 },
  { item: 'Sandwich', price: 7.99 },
  { item: 'Water', price: 1 },
]);

p.printTable();
┌──────────┬──────────────────────────────────────────┐
 │ item     │                                    price  
├──────────┼──────────────────────────────────────────┤
 │ Coffee   │                                    $3.50 │
 │ Sandwich │                                    $7.99 │
 │ Water    │                                    $1.00 │
└──────────┴──────────────────────────────────────────┘

if there is just maxLen then it goes to maxLen although smaller would look lot nicer

ayonious avatar Oct 21 '25 17:10 ayonious

I wonder why do we need maxLen at all?

We need it only to force the len not to be more than that. And the only ways it can go over the length is if a sentence has very big word and we want to keep wrap the sentence to multiple lines.

So I think we need 2 things:

  1. Fix this Ticket as always keep size as min possible.
  2. If there is a maxLen then its used only to split particular words into multi line words

ayonious avatar Oct 21 '25 19:10 ayonious