All Projects â†’ xpl â†’ as-table

xpl / as-table

Licence: MIT license
A simple function that prints objects as ASCII tables. Supports ANSI styling and weird Unicode 💩 emojis – they won't break the layout.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to as-table

Astpretty
Pretty print the output of python stdlib `ast.parse`.
Stars: ✭ 93 (+72.22%)
Mutual labels:  pretty-print
Paiges
an implementation of Wadler's a prettier printer
Stars: ✭ 153 (+183.33%)
Mutual labels:  pretty-print
json-peek
Stringify JSON *just enough* to see what it is
Stars: ✭ 33 (-38.89%)
Mutual labels:  stringify
Pretty Yaml
PyYAML-based module to produce pretty and readable YAML-serialized data
Stars: ✭ 110 (+103.7%)
Mutual labels:  pretty-print
Binpp
🔢 Erlang Binary Pretty Printer
Stars: ✭ 148 (+174.07%)
Mutual labels:  pretty-print
Pretty Simple
pretty-printer for Haskell data types that have a Show instance
Stars: ✭ 183 (+238.89%)
Mutual labels:  pretty-print
Colorjson
Fast Color JSON Marshaller + Pretty Printer for Golang
Stars: ✭ 71 (+31.48%)
Mutual labels:  pretty-print
nlcst-to-string
utility to transform an nlcst tree to a string
Stars: ✭ 16 (-70.37%)
Mutual labels:  stringify
Phpunit Pretty Print
✅  Make your PHPUnit output beautiful
Stars: ✭ 149 (+175.93%)
Mutual labels:  pretty-print
stringify-keys
Build an array of key paths from an object.
Stars: ✭ 18 (-66.67%)
Mutual labels:  stringify
Swiftprettyprint
Pretty print for Swift.
Stars: ✭ 118 (+118.52%)
Mutual labels:  pretty-print
Ololog
A better console.log for the log-driven debugging junkies
Stars: ✭ 141 (+161.11%)
Mutual labels:  pretty-print
Doctorpretty
Wadler's "A prettier printer" embedded pretty-printer DSL for Swift
Stars: ✭ 186 (+244.44%)
Mutual labels:  pretty-print
Webpack Format Messages
Beautiful formatting for Webpack messages; ported from Create React App!
Stars: ✭ 103 (+90.74%)
Mutual labels:  pretty-print
tabled
An easy to use library for pretty print tables of Rust structs and enums.
Stars: ✭ 1,337 (+2375.93%)
Mutual labels:  pretty-print
Prettier Package Json
Prettier formatter for package.json files
Stars: ✭ 86 (+59.26%)
Mutual labels:  pretty-print
Treeify
Pretty-print a javascript object as a tree
Stars: ✭ 174 (+222.22%)
Mutual labels:  pretty-print
stringify
print stl containers
Stars: ✭ 29 (-46.3%)
Mutual labels:  stringify
xijs
A business - oriented scene Js Library
Stars: ✭ 91 (+68.52%)
Mutual labels:  stringify
Webpack Messages
Beautifully format Webpack messages throughout your bundle lifecycle(s)!
Stars: ✭ 238 (+340.74%)
Mutual labels:  pretty-print

as-table

Build Status Coverage Status npm dependencies Status Scrutinizer Code Quality

A simple function that print objects and arrays as ASCII tables. Supports ANSI styling and weird 💩 Unicode emoji symbols (they won't break the layout), thanks to printable-characters.

npm install as-table

Printing objects

asTable = require ('as-table')

asTable ([ { foo: true,  string: 'abcde',      num: 42 },
           { foo: false, string: 'qwertyuiop', num: 43 },
           {             string:  null,        num: 44 } ])
foo    string      num
----------------------
true   abcde       42 
false  qwertyuiop  43 
       null        44 

Printing arrays

asTable ([['qwe',       '123456789', 'zxcvbnm'],
          ['qwerty',    '12',        'zxcvb'],
          ['qwertyiop', '1234567',   'z']])
qwe        123456789  zxcvbnm
qwerty     12         zxcvb
qwertyiop  1234567    z

Limiting total width by proportionally trimming cells + setting columns delimiter

asTable.configure ({ maxTotalWidth: 22, delimiter: ' | ' }) (data)
qwe   | 1234… | zxc…
qwer… | 12    | zxc…
qwer… | 1234… | z   

Right align

asTable.configure ({ right: true }) (data)
      foo        bar      baz
-----------------------------
      qwe  123456789  zxcvbnm
   qwerty         12    zxcvb
qwertyiop    1234567        z

Providing a custom object printer

asTable.configure ({ print: x => (typeof x === 'boolean') ? (x ? 'yes' : 'no') : String (x) }) (data)
foo  string      num
--------------------
yes  abcde       42 
no   qwertyuiop  43 
     null        44 

The callback also receives a field name (in case of objects) or a column index (in case of arrays):

asTable = require ('as-table').configure ({
    print (x, k) {
        if (k === 'timestamp') return new Date (x).toGMTString()
        return String (x)
    }
})

asTable ([ { name: 'A', timestamp: 1561202591572 },
           { name: 'B', timestamp: 1558524240034 } ])

Obtaining a pre-configured function

asTable = require ('as-table').configure ({ maxTotalWidth: 25, delimiter: ' | ' })

asTable (data)

Customizing the title rendering and the header separator

With string coloring by ansicolor (just for the demo purposes, any library will fit):

asTable = require ('as-table').configure ({ title: x => x.bright, delimiter: ' | '.dim.cyan, dash: '-'.bright.cyan })

console.log (
   asTable ([ { foo: true,  string: 'abcde',                             num: 42 },
              { foo: false, string: 'qwertyuiop'.bgMagenta.green.bright, num: 43 } ])

screen shot 2017-07-21 at 23 46 14

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].