How to use the cli-table/index.js function in cli-table

To help you get started, we’ve selected a few cli-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 gladiusjs / gladius-core / node_modules / qunit / node_modules / cli-table / lib-cov / cli-table / index.js View on Github external
_$jscoverage['cli-table/index.js'][184]++;
  ret += chars.right;
}));
    _$jscoverage['cli-table/index.js'][187]++;
    ret += "\n";
  }
}));
  }
  _$jscoverage['cli-table/index.js'][191]++;
  line(chars.bottom, chars["bottom-left"] || chars.bottom, chars["bottom-right"] || chars.bottom, chars["bottom-mid"]);
  _$jscoverage['cli-table/index.js'][196]++;
  return ret;
});
_$jscoverage['cli-table/index.js'][203]++;
module.exports = Table;
_$jscoverage['cli-table/index.js'].source = ["","/**"," * Module dependencies."," */","","var utils = require('./utils')","  , repeat = utils.repeat","  , truncate = utils.truncate","  , pad = utils.pad;","","require('../../support/colors.js/colors');","","/**"," * Table constructor"," *"," * @param {Object} options"," * @api public"," */","","function Table (options){","  this.options = utils.options({","      chars: {","          'top': '━'","        , 'top-mid': '┳'","        , 'top-left': '┏'","        , 'top-right': '┓'","        , 'bottom': '━'","        , 'bottom-mid': '┻'","        , 'bottom-left': '┗' ","        , 'bottom-right': '┛'","        , 'left': '┃'","        , 'left-mid': '┣'","        , 'mid': '━'","        , 'mid-mid': '╋'","        , 'right': '┃'","        , 'right-mid': '┫'","      }","    , truncate: '…'","    , colWidths: []","    , colAligns: []","    , style: {","          'padding-left': 1","        , 'padding-right': 1","        , head: ['cyan']","      }","    , head: []","  }, options);","};","","/**"," * Inherit from Array."," */","","Table.prototype.__proto__ = Array.prototype;","","/**"," * Width getter"," *"," * @return {Number} width"," * @api public"," */","","Table.prototype.__defineGetter__('width', function (){","  var str = this.toString().split(\"\\n\");","  if (str.length) return str[0].length;","  return 0;","});","","/**"," * Render to a string."," *"," * @return {String} table representation"," * @api public"," */","","Table.prototype.render ","Table.prototype.toString = function (){","  var ret = ''","    , options = this.options","    , style = options.style","    , head = options.head","    , chars = options.chars","    , truncater = options.truncate","    , colWidths = options.colWidths || []","    , totalWidth = 0;","  ","  if (!head.length && !this.length) return '';","","  if (!colWidths.length){","    this.concat([head]).forEach(function(cells){","      cells.forEach(function(cell, i){","        var width = typeof cell == 'object' && cell.width != undefined","          ? cell.width ","          : ((typeof cell == 'object' ? String(cell.text) : String(cell)).length + (style['padding-left'] || 0) + (style['padding-right'] || 0))","        colWidths[i] = Math.max(colWidths[i] || 0, width || 0);","      });","    });","  };","","  totalWidth = (colWidths.length == 1 ? colWidths[0] : colWidths.reduce(","    function (a, b){","      return a + b","    })) + colWidths.length + 1;","","  // draws a line","  function line (line, left, right, intersection){","    var width = 0","      , line =","          left","        + repeat(line, totalWidth - 2)","        + right;","","    colWidths.forEach(function (w, i){","      if (i == colWidths.length - 1) return;","      width += w + 1;","      line = line.substr(0, width) + intersection + line.substr(width + 1);","    });","","    ret += line;","  };","","  // draws the top line","  function lineTop (){","    line(chars.top","       , chars['top-left'] || chars.top","       , chars['top-right'] ||  chars.top","       , chars['top-mid']);","    ret += \"\\n\";","  };","","  // renders a string, by padding it or truncating it","  function string (str, index){","    var str = String(typeof str == 'object' && str.text ? str.text : str)","      , length = str.length","      , width = colWidths[index]","          - (style['padding-left'] || 0)","          - (style['padding-right'] || 0)","      , align = options.colAligns[index] || 'left';","","    return repeat(' ', style['padding-left'] || 0)","         + (length == width ? str :","             (length < width ","              ? pad(str, width, ' ', align == 'left' ? 'right' : ","                  (align == 'middle' ? 'both' : 'left'))","              : (truncater ? truncate(str, width, truncater) : str))","           )","         + repeat(' ', style['padding-right'] || 0);","  };","","  if (head.length){","    lineTop();","","    ret += chars.left;","    ","    head.forEach(function (th, index){","      var text = string(th, index);","      if (style.head){","        style.head.forEach(function(style){","          text = text[style];","        });","      }","","      ret += text;","      ret += chars.right;","    });","","    ret += \"\\n\";","  }","","  if (this.length)","    this.forEach(function (cells, i){","      if (!head.length && i == 0)","        lineTop();","      else {","        line(chars.mid","           , chars['left-mid']","           , chars['right-mid']","           , chars['mid-mid']);","","        ret += \"\\n\" + chars.left;","","        cells.forEach(function(cell, i){","          ret += string(cell, i);","          ret += chars.right;","        });","","        ret += \"\\n\";","      }","    });","","  line(chars.bottom","     , chars['bottom-left'] || chars.bottom","     , chars['bottom-right'] || chars.bottom","     , chars['bottom-mid']);","","  return ret;","};","","/**"," * Module exports."," */","","module.exports = Table;"];
github gladiusjs / gladius-core / node_modules / qunit / node_modules / cli-table / lib-cov / cli-table / index.js View on Github external
/* automatically generated by JSCoverage - do not edit */
if (typeof _$jscoverage === 'undefined') _$jscoverage = {};
if (! _$jscoverage['cli-table/index.js']) {
  _$jscoverage['cli-table/index.js'] = [];
  _$jscoverage['cli-table/index.js'][6] = 0;
  _$jscoverage['cli-table/index.js'][11] = 0;
  _$jscoverage['cli-table/index.js'][20] = 0;
  _$jscoverage['cli-table/index.js'][21] = 0;
  _$jscoverage['cli-table/index.js'][48] = 0;
  _$jscoverage['cli-table/index.js'][54] = 0;
  _$jscoverage['cli-table/index.js'][63] = 0;
  _$jscoverage['cli-table/index.js'][64] = 0;
  _$jscoverage['cli-table/index.js'][65] = 0;
  _$jscoverage['cli-table/index.js'][66] = 0;
  _$jscoverage['cli-table/index.js'][76] = 0;
  _$jscoverage['cli-table/index.js'][77] = 0;
  _$jscoverage['cli-table/index.js'][78] = 0;
  _$jscoverage['cli-table/index.js'][87] = 0;
  _$jscoverage['cli-table/index.js'][89] = 0;
github gladiusjs / gladius-core / node_modules / qunit / node_modules / cli-table / lib-cov / cli-table / index.js View on Github external
function string(str, index) {
    _$jscoverage['cli-table/index.js'][133]++;
    var str = String(typeof str == "object" && str.text? str.text: str), length = str.length, width = colWidths[index] - (style["padding-left"] || 0) - (style["padding-right"] || 0), align = options.colAligns[index] || "left";
    _$jscoverage['cli-table/index.js'][140]++;
    return repeat(" ", style["padding-left"] || 0) + (length == width? str: (length < width? pad(str, width, " ", align == "left"? "right": (align == "middle"? "both": "left")): (truncater? truncate(str, width, truncater): str))) + repeat(" ", style["padding-right"] || 0);
}
  _$jscoverage['cli-table/index.js'][148]++;

cli-table

Pretty unicode tables for the CLI

MIT
Latest version published 3 years ago

Package Health Score

76 / 100
Full package analysis