npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nice-table

v1.1.0

Published

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

Downloads

1,098

Readme

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.