diff options
| author | Priyansh <[email protected]> | 2022-01-20 20:07:40 -0500 |
|---|---|---|
| committer | Priyansh <[email protected]> | 2022-01-20 20:07:40 -0500 |
| commit | af142395129bd8d15833400b23767da8aa51c08d (patch) | |
| tree | 55e2c6c3cbf0a34abac1a44ac003942d3107c21d /src/lib | |
| parent | 90b10c4022f41849d05b42ea9b29af5de5a21e32 (diff) | |
| download | izuku.js-af142395129bd8d15833400b23767da8aa51c08d.tar.xz izuku.js-af142395129bd8d15833400b23767da8aa51c08d.zip | |
feat: support for getting rows
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/locate.ts | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/src/lib/locate.ts b/src/lib/locate.ts index 55ba374..733ba9f 100644 --- a/src/lib/locate.ts +++ b/src/lib/locate.ts @@ -9,10 +9,7 @@ interface Izuku { * @param column: the column index or name to be checked * @returns true if the column exists */ -export function checkIfColumnExists( - frame: Izuku, - column: number | string -): boolean { +function checkIfColumnExists(frame: Izuku, column: number | string): boolean { if (typeof column === 'number') { return column < frame.columns.length; } else if (typeof column === 'string') { @@ -23,6 +20,16 @@ export function checkIfColumnExists( } /** + * checkIfRowExists - check if a row exists in the frame + * @param frame: the frame to be checked + * @param row: the row index to be checked + * @returns true if the row exists + */ +function checkIfRowExists(frame: Izuku, row: number): boolean { + return row < frame.rowdata.length; +} + +/** * column returns a single column of the frame, option is either the column name or the column index * @param column: the column to be returned * @returns a single column of the frame as array of arrays @@ -74,3 +81,32 @@ export function getMultipleColumnDetails( }); return { rowd: transposedColumns, rowh: columnNames }; } + +/** + * getSingleRowDetails - returns a single row of the frame + * @param row: the row to be returned + * @returns a single row of the frame as array of arrays + * @throws Error if the row does not exist + * @throws Error if the row is not a number + */ +export function getSingleRowDetails(iz: Izuku, row: number) { + if (checkIfRowExists(iz, row)) { + return { rowd: [iz.rowdata[row]], rowh: iz.columns }; + } else { + throw new Error(`Row ${row} does not exist`); + } +} + +/** + * getMultipleRowDetails - returns multiple rows of the frame + * @param rows: an array of row indexes + * @returns an array of arrays containing the rows + */ +export function getMultipleRowDetails(iz: Izuku, rows: Array<number>) { + const extractedRows: any[][] = []; + rows.forEach((row) => { + const rowDetails = getSingleRowDetails(iz, row); + extractedRows.push(rowDetails.rowd[0]); + }); + return { rowd: extractedRows, rowh: iz.columns }; +} |
