import { table , TableUserConfig } from 'table' ; import logger from './logger' ; const config = { border : { topBody : '─' , topJoin : '┬' , topLeft : '┌' , topRight : '┐' , bottomBody : '─' , bottomJoin : '┴' , bottomLeft : '└' , bottomRight : '┘' , bodyLeft : '│' , bodyRight : '│' , bodyJoin : '│' , joinBody : '─' , joinLeft : '├' , joinRight : '┤' , joinJoin : '┼' , } , } ; param matrix export const isRegularMatrix = ( matrix ) : boolean => matrix && matrix . length > 0 && matrix [ 0 ] . constructor === Array && matrix . every ( ( r ) => r . length === matrix [ 0 ] . length ) ; param header param data export const printArray = ( header , data ) : void => { if ( ! isRegularMatrix ( data ) ) { logger . warning ( 'Table rows are not all the same length; this may produce an irregular tabular view.' ) ; } if ( header . length === Object . keys ( data [ 0 ] ) . length ) { data . unshift ( header . map ( ( h ) => h . toUpperCase ( ) ) ) ; } else { logger . warning ( 'Header length does not match data row length; printing table without header.' ) ; } logger . info ( table ( data , config ) ) ; } ; param data export const printObjectArray = ( data ) : void => { if ( data . length !== 0 ) { const header = Object . keys ( data [ 0 ] ) ; const rows = data . map ( Object . values ) ; printArray ( header , rows ) ; } } ; export default { isRegularMatrix , printArray , printObjectArray , } ;