From 703b4176d84b3f3deadf9c0b86649c29c8c333f9 Mon Sep 17 00:00:00 2001 From: Priyansh Date: Sat, 22 Jan 2022 20:29:58 -0500 Subject: feat: rangeIndex function --- src/index.ts | 6 +++++- src/lib/locate.ts | 10 ++++++++++ tests/info.test.ts | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 7c10f85..acb613d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,8 @@ import { getMultipleColumnDetails, getSingleColumnDetails, getSingleRowDetails, - getMultipleRowDetails + getMultipleRowDetails, + rangeIndex } from './lib/locate'; import { show, head, tail } from './lib/display'; import { getSize, info } from './lib/info'; @@ -57,6 +58,9 @@ class Izuku { public flatten = () => { return flatten(this.rowdata); }; + public rangeIndex = (index: number) => { + return rangeIndex(this, index); + }; } class Frame extends Izuku { diff --git a/src/lib/locate.ts b/src/lib/locate.ts index 733ba9f..46d4712 100644 --- a/src/lib/locate.ts +++ b/src/lib/locate.ts @@ -1,3 +1,4 @@ +import { flatten } from './data'; interface Izuku { rowdata: unknown[][]; columns: string[]; @@ -110,3 +111,12 @@ export function getMultipleRowDetails(iz: Izuku, rows: Array) { }); return { rowd: extractedRows, rowh: iz.columns }; } + +/** + * rangeIndex returns the element at the specified index of the complete frame + * @param index: the index of the element to be returned + * @returns the element at the specified index of the complete frame + */ +export function rangeIndex(iz: Izuku, index: number): any { + return flatten(iz.rowdata)[index]; +} diff --git a/tests/info.test.ts b/tests/info.test.ts index a710246..d1ec2e4 100644 --- a/tests/info.test.ts +++ b/tests/info.test.ts @@ -22,4 +22,9 @@ describe('info.ts', () => { frame.info(); }); }); + describe('Print the element at rangeIndex 32', () => { + it('should print the element at rangeIndex 32', () => { + expect(frame.rangeIndex(32)).to.equal(null); + }); + }); }); -- cgit v1.2.3