npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

zygon

v0.1.0

Published

Simple terminal table renderer

Downloads

4

Readme

Zygon

Simple terminal table renderer

Usage:

zygon(columnsDefinition[, data][, options]);

columnsDefinition

  • name (string), required
  • key (string), required for rendering arrays of objects
  • size (number or Infinity), default = options.size
  • align (string), 'left', 'right' or 'center', default='left'
  • color (string or function), function(val, row) { return color; }
  • format (function), function(val, row) { return newVal; }

data

Array of arrays or array of objects (if "key" was defined for columns)

options

  • size (number), default = 20
  • spacing (number), spaces between columns, default = 2
  • notBold (boolean), print heading without styles
  • output (writable stream), default = process.stdout

returns

an object

  • printHead()
  • printRow( array or object )
  • printRows( array of arrays or objects )
  • end()

Examples

var zygon=require('zygon');

zygon([
  {name:'Actor', size:22},
  {name:'Episodes', size:8, align:'right'}
], [
  ['William Hartnell', 134],
  ['Patrick Troughton', 119],
  ['Jon Pertwee', 128]
]);

  Actor                   Episodes  
  William Hartnell             134  
  Patrick Troughton            119  
  Jon Pertwee                  128  
  Tom Baker                    172  

Render streamed data

var tbl=zygon([
  {name:'Actor', size:15},
  {name:'Episodes', size:8, align:'right'}
]);

tbl.printHead();

tbl.printRow(['Tom Baker', 172]);

tbl.printRow(['Peter Davison', 69]);

tbl.printRows([
  ['Colin Baker', 31],
  ['Sylvester McCoy', 42],
  ['Paul McGann', 1]
]);

tbl.end();

  Actor            Episodes  
  Tom Baker             172  
  Peter Davison          69  
  Colin Baker            31  
  Sylvester McCoy        42  
  Paul McGann             1  

Arrays of objects / color and format functions / spacing option

zygon([
  {
    name:'Name',
    key:'name',
    size:22,
    color:'blue'
  }, {
    name:'Episodes',
    key:'ep',
    size:8,
    align:'right',
    color:function(val) {
      return isNaN(Number(val)) ? 'red' : null;
    }
  }, {
    name:'Year',
    key:'yrs',
    size:9,
    align:'center',
    format:function(yrs) {
      return yrs.length>1 ? yrs[0]+'-'+yrs[yrs.length-1] : yrs[0];
    }
  }
], [
  {name:'Christopher Eccleston', ep:13, yrs:[2005]},
  {name:'David Tennant', ep:47, yrs:[2005, 2006, 2007, 2008, 2009, 2010]},
  {name:'Matt Smith', ep:44, yrs:[2010, 2011, 2012, 2013]},
  {name:'Peter Capaldi', ep:'?', yrs:[2013, 2014, 2015, 2016]}
], {
  spacing:3
});

   Name                     Episodes     Year     
   Christopher Eccleston          13     2005      
   David Tennant                  47   2005-2010   
   Matt Smith                     44   2010-2013   
   Peter Capaldi                   ?   2013-2016   

Tests

Run tests with npm test or generate coverage reports with npm run test-cov.

License

MIT