Skip to content

Commit

Permalink
refactor(table): reformat table
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Jul 26, 2020
1 parent df18516 commit 16ae13d
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions packages/table/lib/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ export class Table<T extends IRow = IRow> extends Array<T> {
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;
Expand All @@ -105,6 +98,13 @@ export class Table<T extends IRow = IRow> extends Array<T> {
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;
Expand Down Expand Up @@ -132,14 +132,6 @@ export class Table<T extends IRow = IRow> extends Array<T> {
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;
}
Expand All @@ -148,21 +140,35 @@ export class Table<T extends IRow = IRow> extends Array<T> {
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();
}
}

0 comments on commit 16ae13d

Please sign in to comment.