File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -82,7 +82,24 @@ function formatTable(data: unknown, columns?: string[]): string {
8282 if ( firstItem && typeof firstItem === "object" ) {
8383 let selectedColumns : string [ ] ;
8484 if ( columns && columns . length > 0 ) {
85- selectedColumns = columns ;
85+ const allKeys = new Set < string > ( ) ;
86+ for ( const item of arrayData ) {
87+ if ( item && typeof item === "object" ) {
88+ Object . keys ( item as Record < string , unknown > ) . forEach ( ( k ) =>
89+ allKeys . add ( k )
90+ ) ;
91+ }
92+ }
93+ const invalid = columns . filter ( ( c ) => ! allKeys . has ( c ) ) ;
94+ if ( invalid . length > 0 ) {
95+ console . error ( // eslint-disable-line no-console
96+ `Warning: unknown column(s): ${ invalid . join ( ", " ) } . Available: ${ [ ...allKeys ] . join ( ", " ) } `
97+ ) ;
98+ }
99+ selectedColumns = columns . filter ( ( c ) => allKeys . has ( c ) ) ;
100+ if ( selectedColumns . length === 0 ) {
101+ selectedColumns = [ ...allKeys ] ;
102+ }
86103 } else {
87104 const allKeys = new Set < string > ( ) ;
88105 for ( const item of arrayData ) {
You can’t perform that action at this time.
0 commit comments