packages/route-table/lib/table.js
function (printArray, format, preProcessor, settings) {
  format = format || ''
  preProcessor = preProcessor || []
  settings = settings || defaultSettings

  const INDENT = emptyString(settings.indent)
  const ROW_SPACER = emptyString(settings.rowSpace)

  const headings = getAllKeys(printArray)
  const maxLength = getMaxLength(headings, printArray)
  const maxLengths = Object.keys(maxLength).reduce((s, k) => s + maxLength[k], 0)

  // print headline
  const headline = []
  const seperator = []

  _.forEach(headings, function (header, i) {
    headline.push(toLength(header, maxLength[header], 'c'))
    seperator.push(new Array(maxLength[header] + 1).join('-'))
  })

  console.log(INDENT + seperator.join(ROW_SPACER))
  console.log(INDENT + headline.join(ROW_SPACER))
  console.log(INDENT + seperator.join(ROW_SPACER))

  // print rows
  _.forEach(printArray, function (row) {
    const line = []

    if (row === null || typeof row === 'string') {
      if (row === null || row === '') {
        return console.log('')
      }
      return console.log(chalk.grey.bold(toLength(row || '', maxLengths, 'l')))
    }

    _.forEach(headings, function (header, i) {
      let str = row[header] || ''

      if (_.isFunction(preProcessor[i])) {
        str = preProcessor[i](str) || str
      }

      line.push(toLength(str, maxLength[header], format.substr(i, 1)))
    })
    console.log(INDENT + line.join(ROW_SPACER))
  })
}
function (printArray, format, preProcessor, settings) {
  format = format || ''
  preProcessor = preProcessor || []
  settings = settings || defaultSettings

  const INDENT = emptyString(settings.indent)
  const ROW_SPACER = emptyString(settings.rowSpace)

  const headings = getAllKeys(printArray)
  const maxLength = getMaxLength(headings, printArray)
  const maxLengths = Object.keys(maxLength).reduce((s, k) => s + maxLength[k], 0)

  // print headline
  const headline = []
  const seperator = []

  _.forEach(headings, function (header, i) {
    headline.push(toLength(header, maxLength[header], 'c'))
    seperator.push(new Array(maxLength[header] + 1).join('-'))
  })

  console.log(INDENT + seperator.join(ROW_SPACER))
  console.log(INDENT + headline.join(ROW_SPACER))
  console.log(INDENT + seperator.join(ROW_SPACER))

  // print rows
  _.forEach(printArray, function (row) {
    const line = []

    if (row === null || typeof row === 'string') {
      if (row === null || row === '') {
        return console.log('')
      }
      return console.log(chalk.grey.bold(toLength(row || '', maxLengths, 'l')))
    }

    _.forEach(headings, function (header, i) {
      let str = row[header] || ''

      if (_.isFunction(preProcessor[i])) {
        str = preProcessor[i](str) || str
      }

      line.push(toLength(str, maxLength[header], format.substr(i, 1)))
    })
    console.log(INDENT + line.join(ROW_SPACER))
  })
}
function ( printArray , format , preProcessor , settings ) { format = format || '' preProcessor = preProcessor || [ ] settings = settings || defaultSettings const INDENT = emptyString ( settings . indent ) const ROW_SPACER = emptyString ( settings . rowSpace ) const headings = getAllKeys ( printArray ) const maxLength = getMaxLength ( headings , printArray ) const maxLengths = Object . keys ( maxLength ) . reduce ( ( s , k ) => s + maxLength [ k ] , 0 ) // print headline const headline = [ ] const seperator = [ ] _ . forEach ( headings , function ( header , i ) { headline . push ( toLength ( header , maxLength [ header ] , 'c' ) ) seperator . push ( new Array ( maxLength [ header ] + 1 ) . join ( '-' ) ) } ) console . log ( INDENT + seperator . join ( ROW_SPACER ) ) console . log ( INDENT + headline . join ( ROW_SPACER ) ) console . log ( INDENT + seperator . join ( ROW_SPACER ) ) // print rows _ . forEach ( printArray , function ( row ) { const line = [ ] if ( row === null || typeof row === 'string' ) { if ( row === null || row === '' ) { return console . log ( '' ) } return console . log ( chalk . grey . bold ( toLength ( row || '' , maxLengths , 'l' ) ) ) } _ . forEach ( headings , function ( header , i ) { let str = row [ header ] || '' if ( _ . isFunction ( preProcessor [ i ] ) ) { str = preProcessor [ i ] ( str ) || str } line . push ( toLength ( str , maxLength [ header ] , format . substr ( i , 1 ) ) ) } ) console . log ( INDENT + line . join ( ROW_SPACER ) ) } ) }
Prints a given array of json objects.
@param printArray The array of json objects to be printed.
@param format
@param preProcessor
@param settings
Prints a given array of json objects .