diff options
Diffstat (limited to 'src/lib/locate.ts')
| -rw-r--r-- | src/lib/locate.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lib/locate.ts b/src/lib/locate.ts new file mode 100644 index 0000000..b176e07 --- /dev/null +++ b/src/lib/locate.ts @@ -0,0 +1,29 @@ +interface Izuku { + rowdata: unknown[][]; + columns: string[]; +} +/** + * 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 + */ +export function getSingleColumnDetails(iz: Izuku, column: number | string) { + let extractedColumn: any[] = []; + let columnName = ''; + if (typeof column === 'string') { + extractedColumn = iz.rowdata.map((row) => { + return row[iz.columns.indexOf(column)]; + }); + columnName = column; + } + if (typeof column === 'number') { + extractedColumn = iz.rowdata.map((row) => { + return row[column]; + }); + columnName = iz.columns[column] + ? iz.columns[column] + : `column${column + 1}`; + } + extractedColumn = extractedColumn.map((item) => [item]); + return { rowd: extractedColumn, rowh: [columnName] }; +} |
