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-cli-flipper

v1.0.4

Published

A simple cyan colored table for your data that allows you to format columns and flip your data.

Downloads

38

Readme

Table CLI Flipper

Table CLI Flipper

A simple cyan colored table for your data that allows you to format columns and flip your data.

npm install table-cli-flipper --save

Update

1.0.1 :

  • You can show/hide header/columns
  • Format columns/rows as you consider. (Breaking lines can be done by using '\n', '\r', '\r\n' in your texts, or by returning an array of strings [ string1, string2, ... , stringN])
  • WrapWrap texts
  • Flip table to the left
  • Read the example below for usage and additional information. 'exampleConfig' contains global and user options.

Example - Table Normal

Table Normal

Example - Table Flipped

Table Flipped

Usage Example


process.stdout.write('\033c');
console.log('\033c');

let table = require('table-cli-flipper');

let data = {};

let recordsNr = 5;

for (let i = 0; i < recordsNr; i++) {

    if (typeof data[i] === 'undefined') {

        data[i] = {
            rowNr: 'this will change', // We'll format this column to get a numeric incremented values
            id: i, // Color the 3rd row
            name: 'Project #' + i,
            status: Math.round(Math.random()), // 1 or 0 -> We'll format this to show "Online" or "Offline"
        }
    }

}

/**
 * Default Config
 * @type {{showHeader: boolean, globalOptions: {align: string, valign: string, width: string, paddingLeft: number, paddingRight: number, wordWrap: boolean, terminalWidth: number}, header: {id: {alias: string, align: string, valign: string, priority: number, width: string, paddingLeft: number, paddingRight: number, wordWrap: boolean, show: boolean}, rowNr: {alias: string}}}}
 */
let exampleConfig = {
    showHeader: true,
    globalOptions: {
        align: 'right',
        valign: 'top',
        width: 'auto',
        paddingLeft: 2,
        paddingRight: 2,
        wordWrap: true,
        terminalWidth: process.stdout.columns, // terminal Width by default, you can change this with a constant
    },
    header: {
        id: {
            alias: 'ids', // Change column name
            align: 'right', // Horizontal align -> left | center | right
            valign: 'middle', // Vertical align -> top | middle | bottom
            priority: 1000, // This is used for trimming columns, it's auto-incremented for columns that don't have it. The columns with the highest priority will be removed if the table is larger than the terminalWidth
            width: 'auto', // Can accept a percentage, a constant or 'auto' ( 'auto' columns will get a higher priority than the % or constant columns, therefore will be targeted for removing as being noted in the 'priority' option )
            paddingLeft: 1, // paddingLeft -  ( Width - paddingLeft - paddingRight ) cannot be less than 0
            paddingRight: 1, // paddingRight -  ( Width - paddingRight - paddingRight  ) cannot be less than 0
            wordWrap: true, // Word wrap the cell text
            show: true, // True: show column , False : hide column
        },
        rowNr: {
            alias: 'Row Number'
        },

    }
};

const chalk = require('chalk');

let flipTable = process.env.FLIP_TABLE === "true";

process.title = 'TABLE ' + (flipTable ? "FLIPPED" : "NORMAL") + ' - Width: ' + process.stdout.columns + ' - Records count: ' + recordsNr;

let simpleTable = table(exampleConfig)

/**
 * Set data gets and object with data
 * Set the second parameter to TRUE to flip the table
 */
    .setData(data, flipTable)
    /**
     * Format Columns
     * Long Version:
     * -------------
     * columnNameOrIndex: string | number, replacer: (cellValue?: string, rowInfo?: { [key: string]: any }, cellIndex?: number) => string
     * columnNameOrIndex: string | number, rowIndex: number, replacer: (cellValue?: string, rowInfo?: { [key: string]: any }, cellIndex?: number) => string
     *
     * Short Version
     * -------------
     * ( columnNameOrIndex, (cellValue, rowInfo, rowIndex) => { return cellValue } )
     * ( columnNameOrIndex, rowIndex, (cellValue, rowInfo, rowIndex) => { return cellValue } )
     */
    .formatColumn('rowNr', (cellValue, rowInfo, rowIndex) => {

        /**
         * Target all rows from column 'rowNr'
         */

        return rowIndex + 1;

    })
    .formatColumn('id', 2, (cellValue, rowInfo, rowIndex) => {

        /**
         * Target only the 3rd row from 'id' column
         */

        return chalk.white.bgGreen(cellValue);

    })
    .formatColumn('status', (cellValue, rowInfo, rowIndex) => {

        /**
         * Format your column based on the other columns values
         *
         * 'rowInfo' data
         *
         * { rowNr: '1', id: '0', name: 'Project #0', status: '0' }
         * { rowNr: '2', id: '1', name: 'Project #1', status: '0' }
         * { rowNr: '3', id: '2', name: 'Project #2', status: '1' }
         * { rowNr: '4', id: '3', name: 'Project #3', status: '0' }
         * { rowNr: '5', id: '4', name: 'Project #4', status: '0' }
         *
         */

        return +rowInfo.id < 2 ? chalk.white.bgGreen('Green ' + rowIndex) : chalk.white.bgRed('Red ' + rowIndex);

    });

/**
 * By default output parameter is set to FALSE, and the table will be flushed to terminal
 */
simpleTable.output(); //

/**
 * Get the table array
 * 1. First parameter TRUE, second FALSE ( by default ) - get the data formatted with delimiters
 * 2. First parameter TRUE, second TRUE - get the raw data
 */
// let output = simpleTable.output(true);
// let output = simpleTable.output(true, true);