larswaechter / voici.js

A Node.js library for pretty printing your data on the terminal🎨

Home Page:https://voici.larswaechter.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Option for displaying only the top / bottom "n" rows

larswaechter opened this issue · comments

In order to display large datasets clearer, there should be an option for displaying only the top / bottom n rows of the dataset. Notice that still all rows are considered for calculations, like accumulations for example. They are just not displayed.

Example 1

Setting peek to an fixed integer, only the top and bottom n rows should be printed

const data  = [
  { firstname: 'Homer', lastname: 'Simpson', age: 39 },
  { firstname: 'Marge', lastname: 'Simpson', age: 36 },
  { firstname: 'Bart', lastname: 'Simpson', age: 10 },
  { firstname: 'Lisa', lastname: 'Simpson', age: 8 },
  { firstname: 'Maggie', lastname: 'Simpson', age: 1 }
];

const table = new Table(data, {
  body: {
    peek: 2
  }
});
table.print();

Output:

  firstname    lastname    age  
================================
  Homer        Simpson     39   
  Marge        Simpson     36   
    <---------------------->    
  Lisa         Simpson     8    
  Maggie       Simpson     1    

Example 2

Setting peek to an array, like [1, 3], only the top 1 and bottom 3 rows should be displayed:

  firstname    lastname    age  
================================
  Homer        Simpson     39   
    <---------------------->    
  Bart         Simpson     10   
  Lisa         Simpson     8    
  Maggie       Simpson     1   

Example 3

You can also display only the top or bottom n rows using [n, 0] or [0, n]. For example peek=[2, 0].

  firstname    lastname    age  
================================
  Homer        Simpson     39   
  Marge        Simpson     36