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

tablite

v1.0.5

Published

Turn your data into a modern text table.

Downloads

4

Readme

tablite

Turn your data into a modern text table.


Table of Contents


☁️ Installation

npm install tablite --save

📋 Example

Check out the examples folder for more.

const Table = require('tablite');

let options = {size: 100, header: true, ratios: [10, 10], align: 'l,c'};

let data = [
    ['Color', 'hex', 'Description'],
    ['Green', '#008000', `Seeing the colour \u001b[32mgreen\u001b[0m has been linked to more creative thinking—so greens are good options for home offices.`],
    ['Violet', '#0000FF', `People link a greyish violet with sophistication, so it can be a good selection for places where you’re trying to make the “right” impression.`],
    ['Blue', '#EE82EE', `People are more likely to tell you that blue is their favourite colour than any other shade.\n That makes it a safe choice.`]];

console.log(new Table(data, options).toString());
┌─────────┬─────────┬─────────────────────────────────────────────────────────────────────────────┐
│ Color   │   hex   │ Description                                                                 │
├─────────┼─────────┼─────────────────────────────────────────────────────────────────────────────┤
│ Green   │ #008000 │ Seeing the colour green has been linked to more creative thinking—so greens │
│         │         │ are good options for home offices.                                          │
│         │         │                                                                             │
│ Violet  │ #0000FF │ People link a greyish violet with sophistication, so it can be a good       │
│         │         │ selection for places where you’re trying to make the “right” impression.    │
│         │         │                                                                             │
│ Blue    │ #EE82EE │ People are more likely to tell you that blue is their favourite colour than │
│         │         │ any other shade.                                                            │
│         │         │ That makes it a safe choice.                                                │
└─────────┴─────────┴─────────────────────────────────────────────────────────────────────────────┘

📝 Documentation

Every table used in this documentation was generated with tablite itself.

Methods

Here are a list of the simple methods to help you.

╒═════════════╤═════════════════════════════════════════════════════════════════════╤════════════════════════════════╕
│    Method   │ Documentation                                                       │ Usage example                  │
╞═════════════╪═════════════════════════════════════════════════════════════════════╪════════════════════════════════╡
│ constructor │ Constructor of the table. Generates an empty table by default.      │ console.log(new Table(data,    │
│             │ Takes two optional parameters: data and options.                    │ options).toString());          │
│             │ You can directly build your table with these.                       │                                │
╞═════════════╪═════════════════════════════════════════════════════════════════════╪════════════════════════════════╡
│     set     │ Set new options. Takes your option structure as parameter.          │ let table = new Table();       │
│             │ Optional: you can disable regeneration with the second parameter.   │ table.set(options);            │
│             │ (see options section for more informations)                         │                                │
╞═════════════╪═════════════════════════════════════════════════════════════════════╪════════════════════════════════╡
│    input    │ Set new data. Takes your data structure as parameter.               │ let table = new Table();       │
│             │ Optional: you can disable regeneration with the second parameter.   │ table.input(data);             │
│             │ (see options section for more informations)                         │                                │
╞═════════════╪═════════════════════════════════════════════════════════════════════╪════════════════════════════════╡
│   generate  │ Regenerate your table. Don't forget to set options and input data   │ table.generate();              │
│             │ first.                                                              │                                │
│             │ Returns the generated table array. (see toString() for string       │                                │
│             │ version)                                                            │                                │
╞═════════════╪═════════════════════════════════════════════════════════════════════╪════════════════════════════════╡
│    split    │ Split your table into different arrays of a specified maximum       │ console.log(table.split(50)[0  │
│             │ character size.                                                     │ ].join('\n'));                 │
╞═════════════╪═════════════════════════════════════════════════════════════════════╪════════════════════════════════╡
│   toString  │ Convert the table into a printable string.                          │ console.log(table.toString()); │
╘═════════════╧═════════════════════════════════════════════════════════════════════╧════════════════════════════════╛

Options

You can give multiple options to customize your table.

Here are several ways to structure your options, they would all give the same output as the previous example code:

╒══════════╤═════════════════════════════════════════════════════════════════════════════════════════════════╕
│   Type   │ Usage example                                                                                   │
╞══════════╪═════════════════════════════════════════════════════════════════════════════════════════════════╡
│  Object  │ let options = new Object();                                                                     │
│          │ options.size = 100;                                                                             │
│          │ options.header = true;                                                                          │
│          │ options.ratios = [10, 10];                                                                      │
│          │ options.align = 'l,c';                                                                          │
╞══════════╪═════════════════════════════════════════════════════════════════════════════════════════════════╡
│   JSON   │ let options = JSON.parse('{"size": 100, "header": true, "ratios": [10, 10], "align": "l,c"}');  │
╞══════════╪═════════════════════════════════════════════════════════════════════════════════════════════════╡
│    Map   │ let options = new Map();                                                                        │
│          │ options.set('size', 100);                                                                       │
│          │ options.set('header', true);                                                                    │
│          │ options.set('ratios', [10, 10]);                                                                │
│          │ options.set('align', 'l,c');                                                                    │
╞══════════╪═════════════════════════════════════════════════════════════════════════════════════════════════╡
│   Array  │ let options = {size: 100, header: true, ratios: [10, 10], align: 'l,c'};                        │
╘══════════╧═════════════════════════════════════════════════════════════════════════════════════════════════╛

Here is a list of the available options and their documentation:

╒════════════╤═════════════════════════════════════════════════════════════════════════════════╤═══════════════════════════════╕
│   Option   │ Documentation                                                                   │ Data                          │
╞════════════╪═════════════════════════════════════════════════════════════════════════════════╪═══════════════════════════════╡
│    size    │ Specify the maximum character count of the rows.                                │ Integer (might be given as a  │
│            │ The real size might be 1 character less, depends on column count's multiples.   │ string)                       │
╞════════════╪═════════════════════════════════════════════════════════════════════════════════╪═══════════════════════════════╡
│   header   │ Toggle the header line.                                                         │ Boolean                       │
│            │ Useless if gaps are filled (see gap option).                                    │                               │
╞════════════╪═════════════════════════════════════════════════════════════════════════════════╪═══════════════════════════════╡
│   border   │ Specify the border you like, single-line is used by default.                    │ String containing border name │
│            │ (See borders section for available borders)                                     │                               │
╞════════════╪═════════════════════════════════════════════════════════════════════════════════╪═══════════════════════════════╡
│     gap    │ Specify the separation between rows.                                            │ String containg separation    │
│            │ (See gaps section for available separations)                                    │ name                          │
╞════════════╪═════════════════════════════════════════════════════════════════════════════════╪═══════════════════════════════╡
│    align   │ Specify columns' aligns. If only one align is given, it is applied to every     │ Array of strings or one       │
│            │ columns.                                                                        │ string separated by commas    │
╞════════════╪═════════════════════════════════════════════════════════════════════════════════╪═══════════════════════════════╡
│   ratios   │ Specify columns' ratio. For example: [10,10] will apply 10% to the first        │ Array of percentages or one   │
│            │ column, 10% to the second and it will split the remaining 80% between remaining │ string separated by commas or │
│            │ columns if they exist.                                                          │ an integer as percentage      │
│            │ Otherwise they will all be added to the last column.                            │                               │
╞════════════╪═════════════════════════════════════════════════════════════════════════════════╪═══════════════════════════════╡
│    ansi    │ The table adapt a row's width when it contains an ANSI command.                 │ Boolean                       │
│            │ Disable this option if your terminal doesn't recognize ANSI commands.           │                               │
╘════════════╧═════════════════════════════════════════════════════════════════════════════════╧═══════════════════════════════╛

Borders

Wonder how the following table-ception was generated using tablite? Check out the examples folder.

       Name            double-line           single-line               dot                 rounded              classical               simple                modern               inversed                none         
                                                                                                                                                                                                                        
   Demonstration   ╔════════╦════════╗   ┌────────┬────────┐   ...................   .--------.--------.   +--------+--------+    ======== ========    ╒════════╤════════╕   ╓────────╥────────╖                        
                   ║    I   ║  love  ║   │    I   │  love  │   .    I   .  love  .   |    I   |  love  |   |    I   |  love  |        I      love      │    I   │  love  │   ║    I   ║  love  ║        I      love     
                   ╠════════╬════════╣   ├────────┼────────┤   ...................   :--------+--------:   +--------+--------+    ======== ========    ╞════════╪════════╡   ╟────────╫────────╢                        
                   ║   Tab  ║  lite  ║   │   Tab  │  lite  │   .   Tab  .  lite  .   |   Tab  |  lite  |   |   Tab  |  lite  |       Tab     lite      │   Tab  │  lite  │   ║   Tab  ║  lite  ║       Tab     lite     
                   ╚════════╩════════╝   └────────┴────────┘   ...................   '--------'--------'   +--------+--------+    ======== ========    ╘════════╧════════╛   ╙────────╨────────╜                                                                                                                                                                                                                                   

Gaps

Gaps are the separation lines between rows. Here is a list of the available ones:

        Name                 space                    fill                     small                    none

   Demonstration      ┌────────┬────────┐      ┌────────┬────────┐      ┌────────┬────────┐      ┌────────┬────────┐
                      │    I   │  love  │      │    I   │  love  │      │    I   │  love  │      │    I   │  love  │
                      │        │        │      ├────────┼────────┤      ├        │        ┤      │   Tab  │  lite  │
                      │   Tab  │  lite  │      │   Tab  │  lite  │      │   Tab  │  lite  │      └────────┴────────┘
                      └────────┴────────┘      └────────┴────────┘      └────────┴────────┘

New line character and template literals

You can use the \n character wherever you like in your data. It works. You can also use the template literals (`...`) for your complex cells.

const Table = require('tablite');

const data = [['I', 'love'], 
['Tablite', `Here is a very
complex cell that will print 
on several lines..`]];

console.log(new Table(data).toString());

ANSI

ANSI commands such as colors are also supported: the table's size won't be changed. Howewer, I can't predict if every ANSI commands work with tablite. Just keep in mind that if you use color commands in your table, make sure there are on a full row; otherwise colors will spread on the borders.

🏅 Badges

npm version Build Status Known Vulnerabilities Dependencies

📜 License

MIT © swordfatih