A non-overflowing `console.table` alternative with customization options.

Overview

nice-table

A non-overflowing console.table alternative with customization options.

Usage

import { createTable } from 'nice-table';

type Person = {
    name: string;
    age: number;
};

const myData: Person[] = [
    { name: 'John', age: 30 },
    { name: 'Jane', age: 25 },
    { name: 'Joe', age: 20 },
    {
        name: 'Pablo Diego José Francisco de Paula Juan Nepomuceno María de los Remedios Cipriano de la Santísima Trinidad Ruiz y Picasso',
        age: new Date(Date.now() - Date.UTC(1881, 3, 8)).getUTCFullYear() - 1970,
    },
];

console.log(
    createTable<Person>(myData, ['name', 'age'], {
        maxWidth: 60,
        columnSizing: 'stretch',
        horizontalAlignment: 'middle',
        verticalAlignment: 'middle',
        fullWidth: true,
        indexColumn: false,
        throwIfTooSmall: false,
    }),
);

// Output:
// ┌────────────────────────────────────────────────────┬─────┐
// │                        name                        │ age │
// ├────────────────────────────────────────────────────┼─────┤
// │                        John                        │ 30  │
// │                        Jane                        │ 25  │
// │                        Joe                         │ 20  │
// │      Pablo Diego José Francisco de Paula Juan      │     │
// │  Nepomuceno María de los Remedios Cipriano de la   │ 141 │
// │         Santísima Trinidad Ruiz y Picasso          │     │
// └────────────────────────────────────────────────────┴─────┘

Colored Output

import * as util from 'node:util';

// ...

console.log(
    createTable<Person>(myData, ['name', 'age'], {
        stringify: (value: unknown) => util.inspect(value, { colors: true }),
    }),
);

Options

maxWidth

The maximum width of the table. This width will never be exceeded by the table. Can be set to process.stdout.columns to use the terminal width in Node.js.

Defaults to 80.

columnSizing

The strategy used to determine the width of each column. There are two possible values:

  • 'stretch': The size of each column is proportional to the length of its content. All columns larger than maxWidth / columnCount are shrunk by the same ratio in case the table is too large for the configured maxWidth.
  • 'even': All columns will have the same size.

Defaults to 'stretch'.

horizontalAlignment

The horizontal alignment the text in all table cells. Possible values are 'left', 'middle', 'right'.

Defaults to 'middle'.

verticalAlignment

The vertical alignment the text in all table cells. Possible values are 'top', 'middle', 'bottom'.

Defaults to 'middle'.

fullWidth

Whether to stretch the table to the maxWidth.

Defaults to false.

throwIfTooSmall

Whether to throw an error if the maxWidth is too small to fit the content. maxWidth should be at least 4 * columnCount + 1 to fit a table with columnCount columns.

If set to false will return a message indicating that there is not enough space to fit the table.

Defaults to true.

indexColumn

Whether to include an index column.

Defaults to false.

stringify

A function converts values into strings before they are is displayed. ANSI codes are supported, so colored input can be achieved as shown in Colored Output.

Defaults to String.

You might also like...

A fixed-width file format toolset with streaming support and flexible options.

fixed-width A fixed-width file format toolset with streaming support and flexible options. Features Flexible: lot of options Zero dependencies: small

Jul 14, 2022

A dashboard to display options-related data around PsyOptions markets and Serum orderbooks.

A dashboard to display options-related data around PsyOptions markets and Serum orderbooks.

PsyOptions Data Dashboard Digestible data around options activity on Solana is pretty inaccessible at the moment. PsyViz provides a clean and user-fri

May 13, 2022

Non-interactive publicly verifiable distributed key generation and resharing algorithm over BLS12-381

NPVDKG-RS This repository contains a mathematical presentation and some code to demonstrate our developed non-interactive publicly verifiable distribu

May 19, 2022

Browse local files using the non-standard Web Browser File System Access API

Browse local files using the non-standard Web Browser File System Access API

Browse local files using the non-standard Web Browser File System Access API

Oct 26, 2022

[Experimental] Browse local files using the non-standard File System Access API

[Experimental] Browse local files using the non-standard File System Access API

jupyterlab-filesystem-access Browse local files using the non-standard Web Browser File System Access API. ⚠️ This extension is compatible with Chromi

Apr 14, 2022

A simple template to get started with a non-profit website.

A simple template to get started with a non-profit website.

Next.js Non-Profit Website A non-profit website template powered by the Cosmic headless CMS. Uses Next.js, Tailwind CSS, and Stripe for donation payme

Sep 6, 2022

[Experimental] Browse local files using the non-standard File System Access API

[Experimental] Browse local files using the non-standard File System Access API

jupyterlab-filesystem-access Browse local files using the non-standard Web Browser File System Access API. ⚠️ This extension is compatible with Chromi

Apr 15, 2022

DecentraMix.io is a cross-chain, non-custodial, universal privacy-preserving protocol with the decentralized governance

DecentraMix.io is a cross-chain, non-custodial, universal privacy-preserving protocol with the decentralized governance

DecentraMix.io is a cross-chain, non-custodial, universal privacy-preserving protocol with the decentralized governance. DecentraWorld applies zkSNARKs to enable transactional privacy for all DeFi components by breaking the on-chain link between depositor and recipient addresses.

May 7, 2022

🚀🚀 A Shopify App template for serverless, non-embedded Apps.

🚀 Free Shopify x Next.js App Template for serverless non-embedded Apps Everything to build your next non-embedded Shopify App and Marketing pages in

Dec 30, 2022
Releases(v1.1.0)
Owner
Tim van Dam
I like to automate stuff with NodeJS
Tim van Dam
Another table select prompt plugin of inquirer.js, with powerful table render and filters.

inquirer-table-select-prompt Table row selection prompt for Inquirer.js 动机 现有的 inquirer.js 没有支持表格行选中的命令行交互的插件. 社区内能查找到的,只有一个二维数组的 checkbox,eduardobouc

锂电 3 Jan 7, 2023
Lazy evaluation list with high tree-shaking affinity and easy customization.

Lazy evaluation list with high tree-shaking affinity and easy customization. Features ?? Lazy Evaluation: The collections are only enumerated to the m

Masanori Onoue 22 Dec 28, 2022
Salazar - a Discord bot that is easy to customize and configure, aiming at the possibility of customization for the user

Salazar is a Discord bot that is easy to customize and configure, aiming at the possibility of customization for the user. This is the BETA version, which uses the current version of Node.js.

guto 5 Dec 7, 2022
This is a template for a peripheral customization PWA.

Peripheral Customization PWA This repository contains a template Progressive Web App (PWA) that can be used to customize peripherals. The template was

Google 3 Sep 30, 2022
A starter and demo project for Keycloakify v6 - Component level customization.

A starter/demo project for Keycloakify ⚠️ Please read the two following notices ⚠️ This starter is for Component-level customization, if you only want

Joseph Garrone 12 Dec 26, 2022
Project to manage multiple emails at once with lots of customization. You can send and receive emails. Desktop notifications can be modified.

Technologies Used React Redux Tailwind CSS Features Admin dashboard User settings and or user dashboard send emails recive emails Connections through

Multi Email 9 Dec 17, 2022
Math Calc is a simple algebra calculator with options for basic addition, subtraction, multiplication, and division as well as many more mathematical properties.

Math-Calc Math Calc is a simple algebra calculator with options for basic addition, subtraction, multiplication, and division as well as many more mat

CoderX07 1 Dec 25, 2021
Duckhunt en javascript, HTML, CSS (projet non terminé)

Duckhunt.JS 1.0 Une réalisation personnel du jeu duckhunt réadapter à ma façon. Dans le cadre d'un cours de POO à l'école Metz Numeric School Histoire

BREGLER Thomas 3 Dec 2, 2022
KWin Script to switch to the next or previous non empty virtual desktop

kwin-cycle-non-empty-desktops KWin Script to switch to the next or previous non empty virtual desktop. Installation Method 1: From the KDE Store Go to

Shaan Subbaiah 1 Dec 5, 2022
An non-official esx-legacy 1.5 version for quasar inventory purpose.

Hi there ! It's my first post on github, and I'm releasing a free edited base with esx-legacy 1.5 compatible and made for Quasar Inventory. How can I

ChernyyOrel 3 Mar 19, 2022