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

table-console

v1.0.0

Published

JavaScript library for displaying table in the console

Downloads

7

Readme

table-console

JavaScript library for displaying table in the console

Features

  • Customizable border
    • Four built-in styles
    • Option to create custom style
  • Text and background color styling and text decorations
  • Text alignment (left, center, right)
  • Padding (left, right)
  • Horizontal lines customization (disabled, only header, enabled)
  • Zero dependency

Installation

npm install table-console

Usage

var Table = require("table-console");
var t = new Table({
    padding: 2,
    headerLine: false,
});
t.insertRows([
    ['First value', 'Second value'],
    ['First value', 'Second value']
]);

console.log(t.toString());

API

Constructor options

  • style - string or number, default value "unicode"
    Build-in style of border

    • "unicode" or 1 (default)

      ┌─────────────┬──────────────┐
      │ First value │ Second value │
      ├─────────────┼──────────────┤
      │ Third value │ Fourth value │
      └─────────────┴──────────────┘
    • "unicode bold" or 2

      ┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
      ┃ First value ┃ Second value ┃
      ┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━┫
      ┃ Third value ┃ Fourth value ┃
      ┗━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
    • "unicode double" or 3

      ╔═════════════╦══════════════╗
      ║ First value ║ Second value ║
      ╠═════════════╬══════════════╣
      ║ Third value ║ Fourth value ║
      ╚═════════════╩══════════════╝
    • "ascii" or 4

      +-------------+--------------+
      | First value | Second value |
      |-------------+--------------|
      | Third value | Fourth value |
      +-------------+--------------+
  • borders - object
    Custom border

    E.g.

    borders: {
        topLeft: "┌", top: "─", topMid: "┬", topRight: "┐",
        midLeft: "├", mid: "─", midMid: "┼", midRight: "┤",
        botLeft: "└", bot: "─", botMid: "┴", botRight: "┘",
        sep: "│",
    }
  • horizontalLines - boolean, default value false
    Put horizontal lines after each row

  • headerLine - boolean, default value true
    Put horizontal lines after first row

  • padding, leftPadding, rightPadding - number, default value 1
    Padding in cells leftPadding and rightPadding is preferred over padding if both are present.

Methods

  • insertRow(row)
    Inserts one row to bottom of the table

    Parameters:

    • row - Array containing row cells
  • insertRows(rows)
    Inserts multiple rows to bottom of the table

    Parameters:

    • rows - Array containing rows
  • removeRow(row)
    Removes one row from the table

    Parameters:

    • row - row id
  • getRows()
    Returns all rows in the table

  • toString()
    Returns string representation of the table

  • insertHorizontalLine()
    Inserts horizontal line to bottom of the table

  • getCell(row, col)
    Return cell value

    Parameters:

    • row - row id
    • col - column id
  • setCell(row, col, value)
    Sets cell value

    Parameters:

    • row - row id
    • col - column id
    • value - new value
  • setCellAttrs(row, col, attrs)
    Sets cell attributes

    Parameters:

    • row - row id
    • col - column id
    • attrs - attributes
      • color - string - black, red, green, yellow, blue, magenta, cyan, white, gray, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite
      • bgColor - string - black, red, green, yellow, blue, magenta, cyan, white, gray, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite
      • decorations - Array - bold, dim, italic, underline, overline, inverse, strikethrough, slowBlink, rapidBlink
      • align - string - left, center, right
  • setRowAttrs(row, attrs)
    Sets row attributes

    Parameters:

    • row - row id
    • attrs - same as setCellAttrs
  • setColAttrs(col, attrs)
    Sets column attributes

    Parameters:

    • col - column id
    • attrs - same as setCellAttrs