How to use the easy-table.prototype function in easy-table

To help you get started, we’ve selected a few easy-table examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Jimbly / node-mtrace / lib / mtrace.js View on Github external
#!/usr/bin/env node

var fs = require('fs');
var child_process = require('child_process');
var Table = require('easy-table')

// add our own ".total()" method on the Table object
Table.prototype.totals = function(keys, label) {
    keys = keys || Object.keys(this.columns);
    label = label || 'Totals';
    var totals = {};
    var ii, jj, key;
    for (ii in this.rows) {
        var line = this.rows[ii];
        for (jj in keys) {
            key = keys[jj];
            var val = line[key];
            if (typeof val === 'number') {
                totals[key] = (totals[key] || 0) + val;
            }
        }
    }
    // then totals
    var first = true;