aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPriyansh <[email protected]>2022-01-22 20:29:58 -0500
committerPriyansh <[email protected]>2022-01-22 20:29:58 -0500
commit703b4176d84b3f3deadf9c0b86649c29c8c333f9 (patch)
treec0a69a6dc9cbe285bd880c37b23b42b3e3657af3
parent9b744e4ce05b56a1aef94110c027d920a5e10005 (diff)
downloadizuku.js-703b4176d84b3f3deadf9c0b86649c29c8c333f9.tar.xz
izuku.js-703b4176d84b3f3deadf9c0b86649c29c8c333f9.zip
feat: rangeIndex function
-rw-r--r--src/index.ts6
-rw-r--r--src/lib/locate.ts10
-rw-r--r--tests/info.test.ts5
3 files changed, 20 insertions, 1 deletions
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<number>) {
});
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);
+ });
+ });
});