helpers/helpers.js
function tableHead () {
  var args = arrayify(arguments)
  var data = args.shift()
  if (!data) return
  args.pop()
  var cols = args
  var colHeaders = cols.map(function (col) {
    var spl = col.split('|')
    return spl[1] || spl[0]
  })
  cols = cols.map(function (col) {
    return col.split('|')[0]
  })
  var toSplice = []
  cols = cols.filter(function (col, index) {
    var hasValue = data.some(function (row) {
      return typeof row[col] !== 'undefined'
    })
    if (!hasValue) toSplice.push(index)
    return hasValue
  })
  toSplice.reverse().forEach(function (index) {
    colHeaders.splice(index, 1)
  })

  var table = '| ' + colHeaders.join(' | ') + ' |\n'
  table += cols.reduce(function (p) { return p + ' --- |' }, '|') + '\n'
  return table
}
function tableHead () {
  var args = arrayify(arguments)
  var data = args.shift()
  if (!data) return
  args.pop()
  var cols = args
  var colHeaders = cols.map(function (col) {
    var spl = col.split('|')
    return spl[1] || spl[0]
  })
  cols = cols.map(function (col) {
    return col.split('|')[0]
  })
  var toSplice = []
  cols = cols.filter(function (col, index) {
    var hasValue = data.some(function (row) {
      return typeof row[col] !== 'undefined'
    })
    if (!hasValue) toSplice.push(index)
    return hasValue
  })
  toSplice.reverse().forEach(function (index) {
    colHeaders.splice(index, 1)
  })

  var table = '| ' + colHeaders.join(' | ') + ' |\n'
  table += cols.reduce(function (p) { return p + ' --- |' }, '|') + '\n'
  return table
}
function tableHead ( ) { var args = arrayify ( arguments ) var data = args . shift ( ) if ( ! data ) return args . pop ( ) var cols = args var colHeaders = cols . map ( function ( col ) { var spl = col . split ( '|' ) return spl [ 1 ] || spl [ 0 ] } ) cols = cols . map ( function ( col ) { return col . split ( '|' ) [ 0 ] } ) var toSplice = [ ] cols = cols . filter ( function ( col , index ) { var hasValue = data . some ( function ( row ) { return typeof row [ col ] !== 'undefined' } ) if ( ! hasValue ) toSplice . push ( index ) return hasValue } ) toSplice . reverse ( ) . forEach ( function ( index ) { colHeaders . splice ( index , 1 ) } ) var table = '| ' + colHeaders . join ( ' | ' ) + ' |\n' table += cols . reduce ( function ( p ) { return p + ' --- |' } , '|' ) + '\n' return table }
returns a gfm table header row.. only columns which contain data are included in the output
returns a gfm table header row .. only columns which contain data are included in the output