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

prettytable.js

v1.0.1

Published

Browser/Node module for generating pretty tables from multiple data sources

Downloads

32

Readme

JavaScript / TypeScript library for Node.JS and browsers to easily creating ASCII tables

About

Creates ASCII tables from multiple data sources. The table can be populated by adding table rows one by one, by multiple, from a CSV file or from a JSON file.

Table of contents

Installation

Node.js 14.0.0 or newer supported.

Install with the npm:

npm install prettytable.js

Install with the yarn:

yarn add prettytable.js

Usage

Working with PrettyTable.js you can start from follow small code snippet:

import { PrettyTable } from 'prettytable.js';

const table = new PrettyTable();

table.setHeader(['Name', 'Age', 'City']);

table.addRows([
  ['John', 22, 'New York'],
  ['Elizabeth', 43, 'Chicago'],
  ['Bill', 31, 'Atlanta'],
  ['Mary', 18, 'Los Angeles'],
]);

console.log(table.toString());

This gives you the following table on console:

+-----------+-----+-------------+
| Name      | Age | City        |
+-----------+-----+-------------+
| John      | 22  | New York    |
| Elizabeth | 43  | Chicago     |
| Bill      | 31  | Atlanta     |
| Mary      | 18  | Los Angeles |
+-----------+-----+-------------+

Table methods

Note
type Cell = string | number | null | undefined;

getHeader

Gets header of the table.

table.getHeader();
() => Cell[];

setHeader

Sets header to the table.

table.setHeader(['Name', 'Age', 'City']);
(header: Cell[]) => void;

| Argument | Required | Description | |----------|----------|---------------------------------------| | header | Yes | The header to be settled to the table |

getFooter

Gets footer of the table.

table.getFooter();
() => Cell[];

setFooter

Sets header to the table.

table.setFooter(['Name', 'Age', 'City']);
(footer: Cell[]) => void;

| Argument | Required | Description | |----------|----------|---------------------------------------| | footer | Yes | The footer to be settled to the table |

getRows

Gets all rows of the table.

table.getRows();
() => Cell[][];

getRow

Gets row of the table.

table.getRow(index);
(index: number) => Cell[];

| Argument | Required | Description | |----------|----------|----------------------| | index | Yes | The index of the row |

addRows

Adds list of rows to the table.

table.addRows([
  ['first row', 'value'],
  ['second row', 'value'],
]);
(rows: Cell[][]) => void;

| Argument | Required | Description | |----------|----------|------------------| | rows | Yes | The list of rows |

addRow

Adds row to the table.

table.addRow(['first row', 'value']);
(row: Cell[]) => void;

| Argument | Required | Description | |----------|----------|-------------| | row | Yes | The row |

deleteRow

Deletes row from table.

table.deleteRow(4);
(index: number) => void;

| Argument | Required | Description | |----------|----------|----------------------------| | index | Yes | The row index for deletion |

toString

Converts table to string representation.

table.toString();
() => string;

toCsv

Converts table to CSV representation.

table.toCsv();
() => string;

toJson

Converts table to JSON representation.

table.toJson();
() => Record<string | number, Cell>[];

clone

Clones table.

table.clone();
() => PrettyTable;

static from

Creates table from arguments.

const table = PrettyTable.from(
  ['header 1', 'header 2'],
  [ ['row 1', 'row 1'] ],
  ['footer 1', 'footer 1'],
);
(
  header?: Cell[] | null,
  rows?: Cell[][] | null,
  footer?: Cell[] | null,
) => PrettyTable;

| Argument | Required | Default | Description | |----------|----------|---------|-------------------------| | header | No | null | The header of the table | | rows | No | null | The list of table rows | | footer | No | null | The footer of the table |

static fromCsv

Creates table from CSV.

const table = PrettyTable.fromCsv(csvFile, { header: true });
(file: string | Buffer, options?: { header?: boolean; footer?: boolean; }) => PrettyTable;

| Argument | Required | Default | Description | |-----------|----------|-----------------------------------|--------------------------| | file | Yes | N\A | The content of CSV | | options | No | { header: true, footer: false } | The options of CSV table |

static fromJson

Creates table from JSON.

const table = PrettyTable.fromJson([
  {
    "name": "john",
    "age": 22,
    "city": "new york"
  },
  {
    "name": "elizabeth",
    "age": 43,
    "city": "chicago"
  },
  {
    "name": "bill",
    "age": 31,
    "city": "atlanta"
  },
  {
    "name": "mary",
    "age": 18,
    "city": "los angeles"
  }
]);
(json: Record<string | number, Cell>[]) => PrettyTable;

| Argument | Required | Description | |----------|----------|---------------------| | json | Yes | The content of JSON |

License

Distributed under the MIT License. See LICENSE for more information.