diff options
| author | Priyansh <[email protected]> | 2022-01-19 04:46:26 -0500 |
|---|---|---|
| committer | Priyansh <[email protected]> | 2022-01-19 04:46:26 -0500 |
| commit | a5ff0a01d3c3924a556d84ee6653e4aa7a8e6863 (patch) | |
| tree | d6007f13506d24d6287b26082a021e1cc53ff204 /src/lib | |
| parent | fbd2fa4fd9182429e54bfe96483961a98f10ac04 (diff) | |
| download | izuku.js-a5ff0a01d3c3924a556d84ee6653e4aa7a8e6863.tar.xz izuku.js-a5ff0a01d3c3924a556d84ee6653e4aa7a8e6863.zip | |
feat: add table dep, added printing test and moved display to function
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/display.ts | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/src/lib/display.ts b/src/lib/display.ts index 2247938..591429a 100644 --- a/src/lib/display.ts +++ b/src/lib/display.ts @@ -1,20 +1,27 @@ -import { FrameInterface } from '../interface/frameInterface'; - -export class Display implements FrameInterface { - rowdata: unknown[][] = []; - columns!: string[]; - table(frame: FrameInterface): void { - const maxSizedArrayLength = frame.rowdata.reduce((acc, curr) => { - return acc.length > curr.length ? acc : curr; - }).length; - console.table( - frame.rowdata.map((row) => { - const rowobj: any = {}; - for (let i = 0; i < maxSizedArrayLength; i++) { - rowobj[frame.columns[i]] = row[i] ? row[i] : null; - } - return rowobj; - }) - ); +function getTable( + rowdata: unknown[][], + columns: string[], + indexRow?: any[] +): any[] { + const maxSizedArrayLength = rowdata.reduce((acc, curr) => { + return acc.length > curr.length ? acc : curr; + }).length; + const frameRows: unknown[][] = []; + for (let i = 0; i < rowdata.length; i++) { + const row = rowdata[i]; + const rowLength = row.length; + const rowArray = []; + rowArray.push(indexRow ? indexRow[i] : i); + for (let j = 0; j < maxSizedArrayLength; j++) { + if (j < rowLength) { + rowArray.push(row[j]); + } else { + rowArray.push(''); + } + } + frameRows.push(rowArray); } + return [['Index', ...columns], ...frameRows]; } + +export { getTable }; |
