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

terminal-char-table

v2.0.2

Published

a simple javascript (node.js) library for drawing ascii tables in the terminal and console.

Downloads

7

Readme

📦 terminal-char-table

📌 a simple javascript (node.js) library for drawing ascii tables in the terminal and console.

screenshot

⚠️Version belows 2.0.0 is deprecated and not recommend to use.

Install

$ npm install terminal-char-table

Example

  • Create a simple char table with default options.
const CharTable = require('terminal-char-table');
let table = new CharTable();

// fill the table row by rows
table.append(['1', 'xxx', 'xxx', ':)', '?']);
table.append(['2', 'xxx', 'xxx']);
table.append(['3', 'xxx', 'xxx', ':3']);
table.append(['10', 'xxx', 'xxx', '', 'owo']);

// this row will be the table header
table.insert(['#', 'column1', 'column2']);

// output table with 1 indentation
console.log(table.string(1));

API

CharTable([option])

Constructor function of CharTable class, An object with optional propertys can be passed in:

  • @string column_align : default alignment of columns, value can be a left or right or center. default left.
  • @number column_fill_length : an integer to specify how many spaces fill into each columns. default 2.
    • bigger value will make the table looks more wider, if alignment is left or right, set this value to 2 or higher is recommended.
  • @boolean column_empty_drawn : specify whether empty columns are drawn. default true.

insert(columns[, align])

Add a new row at the top of the table.

  • @string[] columns : an array of string to build columns of this row left side to right.
  • @string align : columns alignment of this row, value can be a left or right or center.

append(columns[, align])

Add a new row at the bottom of the table.

  • @string[] columns : an array of string to build columns of this row left side to right.
  • @string align : columns alignment of this row, value can be a left or right or center.

from(rows[, align])

Set the table rows from given data.

  • @string[] rows : an array include rows to append, each cell is columns of that row.
  • @string align : columns alignment of each rows, value can be a left or right or center.
// table header
table.append(['#', 'data', 'alignment']);

// 1~3 rows (center alignment)
table.from([['1', '-----', 'center'], ['2', '-----', 'center'], ['3', '-----', 'center']], 'center');

// 4~6 rows (default alignment)
table.from([['4', '-----', 'default'], ['5', '-----', 'default'], ['6', '-----', 'default']]);

from2(row_objects)

Set the table rows from given data.

  • @object[] row_objects : an array of object that include rows to append, each object indicated a single row:
    • @string[] columns : an array of string to build columns of that row left side to right.
    • @string? align : columns alignment of that row, value can be a left or right or center.
table.from2([
	{
		columns: ['#', 'data', 'alignment']
	},
	{
		columns: ['1', '-----', 'left'],
		align: 'left'
	},
	{
		columns: ['2', '-----', 'center'],
		align: 'center'
	},
	{
		columns: ['3', '-----', 'right'],
		align: 'right'
	}
]);

lines()

Get printable string lines. an array of string will be returned.

string([left_indentation, first_line_break])

Get printable string. wrapped from lines() method.

  • @number left_indentation : an integer to specify how many spaces filling before each string lines. default 0.
  • @boolean first_line_break : specify whether add a line break before the first line. default false.

clear()

Delete all rows in the table.

Note

  • The complete methods and description can be found in module.js
  • More example see test.js and run test using npm test command.