aboutsummaryrefslogtreecommitdiff
path: root/src/lib/display.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/display.ts')
-rw-r--r--src/lib/display.ts89
1 files changed, 46 insertions, 43 deletions
diff --git a/src/lib/display.ts b/src/lib/display.ts
index c33df70..4349aa5 100644
--- a/src/lib/display.ts
+++ b/src/lib/display.ts
@@ -41,29 +41,30 @@ function getTable(
*/
export function show(this: Frame): void {
if (this.rowdata.length === 0) {
- throw new Error('Set data before printing');
- }
- const numberOfRows = this.rowdata.length;
- if (numberOfRows < 7) {
- console.log(table(getTable(this.rowdata, this.columns)));
+ console.log('No data found');
} else {
- const firstThreeRows = this.rowdata.slice(0, 3);
- const lastThreeRows = this.rowdata.slice(numberOfRows - 3);
- const middleRow = [];
- for (let i = 0; i < this.columns.length; i++) {
- middleRow.push('...');
+ const numberOfRows = this.rowdata.length;
+ if (numberOfRows < 7) {
+ console.log(table(getTable(this.rowdata, this.columns)));
+ } else {
+ const firstThreeRows = this.rowdata.slice(0, 3);
+ const lastThreeRows = this.rowdata.slice(numberOfRows - 3);
+ const middleRow = [];
+ for (let i = 0; i < this.columns.length; i++) {
+ middleRow.push('...');
+ }
+ const indexRow = [
+ 0,
+ 1,
+ 2,
+ '...',
+ numberOfRows - 3,
+ numberOfRows - 2,
+ numberOfRows - 1
+ ];
+ const combinedRow = [...firstThreeRows, [...middleRow], ...lastThreeRows];
+ console.log(table(getTable(combinedRow, this.columns, indexRow)));
}
- const indexRow = [
- 0,
- 1,
- 2,
- '...',
- numberOfRows - 3,
- numberOfRows - 2,
- numberOfRows - 1
- ];
- const combinedRow = [...firstThreeRows, [...middleRow], ...lastThreeRows];
- console.log(table(getTable(combinedRow, this.columns, indexRow)));
}
}
@@ -75,17 +76,18 @@ export function show(this: Frame): void {
*/
export function head(this: Frame, n = 5): void {
if (this.rowdata.length === 0) {
- throw new Error('Set data before printing');
- }
- // Check if n is greater than the number of rows
- if (n > this.rowdata.length) {
- n = this.rowdata.length;
- }
+ console.log('No data found');
+ } else {
+ // Check if n is greater than the number of rows
+ if (n > this.rowdata.length) {
+ n = this.rowdata.length;
+ }
- // Generate the index row
- const indexRow = this.rowdata.map((row, index) => index);
- const data = this.rowdata.slice(0, n);
- console.log(table(getTable(data, this.columns, indexRow)));
+ // Generate the index row
+ const indexRow = this.rowdata.map((row, index) => index);
+ const data = this.rowdata.slice(0, n);
+ console.log(table(getTable(data, this.columns, indexRow)));
+ }
}
/**
@@ -96,17 +98,18 @@ export function head(this: Frame, n = 5): void {
*/
export function tail(this: Frame, n = 5): void {
if (this.rowdata.length === 0) {
- throw new Error('Set data before printing');
- }
- // Check if n is greater than the number of rows
- if (n > this.rowdata.length) {
- n = this.rowdata.length;
- }
+ console.log('No data found');
+ } else {
+ // Check if n is greater than the number of rows
+ if (n > this.rowdata.length) {
+ n = this.rowdata.length;
+ }
- // Generate the index row
- const indexRow = this.rowdata.map((row, index) => index);
- const data = this.rowdata.slice(this.rowdata.length - n);
- // Slice the index row to match the data
- const slicedIndexRow = indexRow.slice(indexRow.length - n);
- console.log(table(getTable(data, this.columns, slicedIndexRow)));
+ // Generate the index row
+ const indexRow = this.rowdata.map((row, index) => index);
+ const data = this.rowdata.slice(this.rowdata.length - n);
+ // Slice the index row to match the data
+ const slicedIndexRow = indexRow.slice(indexRow.length - n);
+ console.log(table(getTable(data, this.columns, slicedIndexRow)));
+ }
}