GithubHelp home page GithubHelp logo

table-layout's Introduction

view on npm npm module downloads Build Status Dependency Status js-standard-style

table-layout

Generates plain-text tables from JSON recordset input (array of objects). Useful for presenting text in column layout or data in table layout in text-based user interfaces. Also available as a command-line tool.

Synopsis

> const Table = require('table-layout')
> const issues = require('./example/issues')

> const table = new Table(issues, { maxWidth: 60 })
> console.log(table.toString())

 15134  Coveralls has no source available   ndelangen     0
 15133  Fixing --preserve-symlinks.         phestermcs    0
        Enhancing node to exploit.
 15131  Question - Confused about NPM's     the1mills     0
        local installation philosophy
 15130  Question - global npm cache         ORESoftware   0
        directory if user is root?
 15127  how to installa gulp fontfacegen    aramgreat     0
        on Windows 10
 15097  Cannot install package from         mastertinner  3
        tarball out of package.json entry
        generated by npm
 15067  npm "SELF_SIGNED_CERT_IN_CHAIN"     LegendsLyfe   3
        error when installing discord.js
        with .log

API Reference

Table ⏏

Recordset data in (array of objects), text table out.

Kind: Exported class

new Table(data, [options])

Params

  • data Array.<object> - input data
  • [options] object - optional settings
    • [.maxWidth] number - maximum width of layout
    • [.noWrap] boolean - disable wrapping on all columns
    • [.noTrim] boolean - disable line-trimming
    • [.break] boolean - enable word-breaking on all columns
    • [.columns] columnOption - array of column-specific options
    • [.ignoreEmptyColumns] boolean - if set, empty columns or columns containing only whitespace are not rendered.
    • [.padding] object - Padding values to set on each column. Per-column overrides can be set in the options.columns array.
      • [.left] string - Defaults to a single space.
      • [.right] string - Defaults to a single space.

Example

> Table = require('table-layout')
> jsonData = [{
  col1: 'Some text you wish to read in table layout',
  col2: 'And some more text in column two. '
}]
> table = new Table(jsonData, { maxWidth: 30 })
> console.log(table.toString())
 Some text you  And some more
 wish to read   text in
 in table      column two.
 layout

table.renderLines() ⇒ Array.<string>

Identical to .toString() with the exception that the result will be an array of lines, rather than a single, multi-line string.

Kind: instance method of Table

table.toString() ⇒ string

Returns the input data as a text table.

Kind: instance method of Table

Table~columnOption

Kind: inner typedef of Table
Properties

Name Type Description
name string column name, must match a property name in the input
[width] number A specific column width. Supply either this or a min and/or max width.
[minWidth] number column min width
[maxWidth] number column max width
[nowrap] boolean disable wrapping for this column
[break] boolean enable word-breaking for this columns
[padding] object padding options
[padding.left] string a string to pad the left of each cell (default: ' ')
[padding.right] string a string to pad the right of each cell (default: ' ')

© 2015-18 Lloyd Brookes <[email protected]>. Documented by jsdoc-to-markdown.

table-layout's People

Contributors

75lb avatar

Watchers

 avatar  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.