Giter Site home page Giter Site logo

cli-simple-table's Introduction




Simple CLI table for simple people

Install

npm i cli-simple-table

Basic usage

import SimpleTable from 'cli-simple-table'
import chalk from 'chalk'

const table = new SimpleTable()

table.header('Name', 'Emoji')

table.row(chalk.red('Squid'), '๐Ÿฆ‘')
table.row(chalk.green('Frog'), '๐Ÿธ')
table.row(chalk.yellow('Tiger'), '๐Ÿฏ')
table.row(chalk.blue('Whale'), '๐Ÿณ')
table.row(chalk.magenta('Unicorn'), '๐Ÿฆ„')
table.row(chalk.cyan('Dolphin'), '๐Ÿฌ')
table.row(chalk.white('Panda'), '๐Ÿผ')

console.log(table.toString())

Alignment

const table = new SimpleTable()

table.header(
    'Name',
    {
        text: 'Age',
        align: 'right'
    }
)

table.row('Steve', 26)

console.log(table.toString())

Max column width

const table = new SimpleTable()

table.header(
    {
        text: 'Long text',
        maxWidth: 25
    },
    {
        text: 'Long long text',
        maxWidth: 25
    }
)

table.row('Truncates really really long text', chalk.magenta('Colored long long text too'))

console.log(table.toString())

Options

  • columnPadding <Number> (10) - Number of characters to pad the column content with

  • headerSeparator <Number> (1) - Number of lines that separate the header from the table body

cli-simple-table's People

Contributors

privatenumber avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cli-simple-table's Issues

Make empty line below header optional

First, thanks for sharing this code!

Second, it'd be great if this line were optional:

Or perhaps a function to return an object like:

{"header": "...",
 "rows": ["...", "..."]}

So it could be further formatted by a template engine or whatever.

Just a thought. ๐Ÿ˜„

Thanks, again!
๐ŸŽฉ

1.1.0 breaks require() usage

Looks like the build process changes between 1.0.0 and 1.1.0 broke the ability to use this as a Common JS module. Here's what I get post upgrade:

TypeError: SimpleTable is not a constructor

or sometimes

Cannot find module 'cli-simple-table'

or from eslint

import/no-unresolved: Unable to resolve path to module 'cli-simple-table'.

Versions:
NPM: 6.14.13
Node: v14.17.3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.