Coder Social home page Coder Social logo

tabledown's Introduction

Tabledown

Easily create markdown tables in your Javascript applications.

Features

  • Input data format agnostic
    • Array of arrays
    • Array of objects
  • Support for several markdown flavors
    • Simple tables
    • Multiline tables
    • Grid tables
    • Pipe tables
  • Column alignment
  • Custom headers
  • Optional caption

Installation

As command line tool:

npm install --global tabledown

As module:

npm install --save tabledown

Usage

Command Line

echo '[{"name": "John", "age": 32}, {"name": "Anna", "age": 27}]' | tabledown

yields

name | age
-----|----
John | 32
Anna | 27

Module

Simple

import Tabledown from 'tabledown'
const food = [
  {
    name: 'banana',
    color: 'yellow',
    price: 3.23,
    quantity: 2,
  },
  {
    name: 'tomato',
    color: 'red',
    price: 2.67,
    quantity: 6,
  }
]

const table = new Tabledown({data: food})

console.log(table.toString())

yields

name   |  color | price | quantity
-------|--------|-------|---------
banana | yellow | 3.23  |    2
tomato |    red | 2.67  |    6

Extended

import Tabledown from 'tabledown'
const food = [
  {
    name: 'banana',
    color: 'yellow',
    price: 3.23,
    quantity: 2,
  },
  {
    name: 'tomato',
    color: 'red',
    price: 2.67,
    quantity: 6,
  },
  {
    name: 'cucumber',
    color: 'green',
    price: 5.82,
    quantity: 4,
  },
  {
    name: 'carrot',
    color: 'orange',
    price: 3,
    quantity: 9,
  }
]

const table = new Tabledown({
  caption: 'Food',
  data: food,
  alignments: {
    name: 'left',
    color: 'right',
    price: 'decimal mark', // Not yet implemented
    quantity: 'center',
  },
  headerTexts: {
    name: 'the Fruit',
    color: 'the Color',
    price: 'the Price (€)',
    quantity: 'the Quantity',
  },
  style: 'pipe', // or simple, multiline, grid (not yet implemented)
  capitalizeHeaders: true,
})

console.log(table.toString())

yields

Table: Food

The Fruit | The Color | The Price (€) | The Quantity
:---------|----------:|---------------|:-----------:
banana    |    yellow | 3.23          |      2
tomato    |       red | 2.5           |      6
cucumber  |     green | 5.82          |      4
carrot    |    orange | 12            |      9

The data can also be provided as an array. The first sub-array must contain the headers.

const food = [
  ['name',     'color', 'price', 'quantity'],
  ['banana',   'yellow',  3.23,      2     ],
  ['tomato',   'red',     2.5 ,      6     ],
  ['cucumber', 'green',   5.82,      4     ],
  ['carrot',   'orange', 12,         9     ],
]

const table = new Tabledown({data: food})

tabledown's People

Contributors

ad-si avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

tabledown's Issues

Fix width

Nummer | Datum | Beschreibung | Dauer (min) | Preis (€)
:-----:|:-----:|:-------------|------------:|---------:
  1    | 2013‑10‑27 | asdf asdf s                                                    |          30 |       7.5
  2    | 2013‑11‑11 | asdfdfdf                                                       |          10 |       2.5

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.