From 16ae13d2eab6bd54a8537fa581209c90f8dcbe6f Mon Sep 17 00:00:00 2001 From: Benjamin Fischer Date: Sun, 26 Jul 2020 01:27:09 +0200 Subject: [PATCH] refactor(table): reformat table --- packages/table/lib/table.ts | 46 +++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/packages/table/lib/table.ts b/packages/table/lib/table.ts index 043bb379..e1bb0ec9 100644 --- a/packages/table/lib/table.ts +++ b/packages/table/lib/table.ts @@ -84,13 +84,6 @@ export class Table extends Array { return this; } - public indent( width: number, override: boolean = true ): this { - if ( override || typeof this.options.indent === 'undefined' ) { - this.options.indent = width; - } - return this; - } - public maxCellWidth( width: number | number[], override: boolean = true ): this { if ( override || typeof this.options.maxCellWidth === 'undefined' ) { this.options.maxCellWidth = width; @@ -105,6 +98,13 @@ export class Table extends Array { return this; } + public indent( width: number, override: boolean = true ): this { + if ( override || typeof this.options.indent === 'undefined' ) { + this.options.indent = width; + } + return this; + } + public padding( padding: number | number[], override: boolean = true ): this { if ( override || typeof this.options.padding === 'undefined' ) { this.options.padding = padding; @@ -132,14 +132,6 @@ export class Table extends Array { return this.slice(); } - public getIndent(): number { - return this.options.indent; - } - - public getBorder(): boolean { - return this.options.border === true; - } - public getMaxCellWidth(): number | number[] { return this.options.maxCellWidth; } @@ -148,21 +140,35 @@ export class Table extends Array { return this.options.minCellWidth; } + public getIndent(): number { + return this.options.indent; + } + public getPadding(): number | number[] { return this.options.padding; } + public getBorder(): boolean { + return this.options.border === true; + } + public hasHeaderBorder(): boolean { - return this.headerRow instanceof Row && this.headerRow.hasBorder(); + return this.getBorder() || ( + this.headerRow instanceof Row && this.headerRow.hasBorder() + ); } public hasBodyBorder(): boolean { - return this.getBorder() || this.some( row => - row instanceof Row ? row.hasBorder() : row.some( cell => - cell instanceof Cell ? cell.getBorder : false ) ); + return this.getBorder() || + this.some( row => + row instanceof Row ? row.hasBorder() : + row.some( cell => + cell instanceof Cell ? cell.getBorder : false + ) + ); } public hasBorder(): boolean { - return this.getBorder() || this.hasHeaderBorder() || this.hasBodyBorder(); + return this.hasHeaderBorder() || this.hasBodyBorder(); } }