Coder Social home page Coder Social logo

tablemark's Introduction

tablemark · Version License Travis CI JavaScript Standard Style

Generate markdown tables from JSON data.

Parses arrays of objects into markdown tables, complete with configuration for renaming columns and left, center, or right-aligning them.

installation

npm i tablemark

usage

const tablemark = require('tablemark')
tablemark([
  { name: 'Bob', age: 21, isCool: false },
  { name: 'Sarah', age: 22, isCool: true },
  { name: 'Lee', age: 23, isCool: true }
])

// | Name  | Age   | IsCool |
// | ----- | ----- | ------ |
// | Bob   | 21    | false  |
// | Sarah | 22    | true   |
// | Lee   | 23    | true   |

... displays as:

Name Age IsCool
Bob 21 false
Sarah 22 true
Lee 23 true
tablemark([
  { name: 'Bob', age: 21, isCool: false },
  { name: 'Sarah', age: 22, isCool: true },
  { name: 'Lee', age: 23, isCool: true }
], {
  columns: [
    'first name',
    { name: 'how old', align: 'center' },
    'are they cool'
  ]
})

// | first name | how old | are they cool |
// | ---------- | :-----: | ------------- |
// | Bob        |   21    | false         |
// | Sarah      |   22    | true          |
// | Lee        |   23    | true          |

... displays as:

first name how old are they cool
Bob 21 false
Sarah 22 true
Lee 23 true

api

tablemark

tablemark(input, [options = {}])

Arguments

  • {Array<Object>} input: the data to table-ify
  • {Object} [options = {}]
key type default description
columns <Array> - Array of column descriptors.
caseHeaders <Boolean> true Sentence case headers derived from keys.
stringify <Function> - Provide a custom "toString" function.
wrap.width <Number> Infinity Wrap texts at this length.
wrap.gutters <Boolean> false Add sides (| <content> |) to wrapped rows.

The columns array can either contain objects, in which case their name and align properties will be used to alter the display of the column in the table, or any other type which will be coerced to a string if necessary and used as a replacement for the column name.

text wrapping

To output valid GitHub Flavored Markdown a cell must not contain newlines. Consider replacing those with <br /> (e.g. using the stringify option).

Set the wrap.width option to wrap any content at that length onto a new adjacent line:

tablemark([
  { star: false, name: 'Benjamin' },
  { star: true, name: 'Jet Li' }
], { wrap: { width: 5 } })

// | Star  | Name  |
// | ----- | ----- |
// | false | Benja |
//           min
// | true  | Jet   |
//           Li

Enable wrap.gutters to add pipes on all lines:

tablemark([
  { star: false, name: 'Benjamin' },
  { star: true, name: 'Jet Li' }
], { wrap: { width: 5, gutters: true } })

// | Star  | Name  |
// | ----- | ----- |
// | false | Benja |
// |       | min   |
// | true  | Jet   |
// |       | Li    |

see also

contributing

Search the issues if you come across any trouble, open a new one if it hasn't been posted, or, if you're able, open a pull request. Contributions of any kind are welcome in this project.

The following people have already contributed their time and effort:

Thank you!

license

MIT © Bo Lingen / citycide

tablemark's People

Contributors

haltcase avatar tjconcept avatar

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.