From 6785f6532e2be1df6df6ec888b52ee1b5d2466fe Mon Sep 17 00:00:00 2001 From: Herman Klushin Date: Wed, 19 May 2021 23:20:13 +0300 Subject: [PATCH] RowFormatter should be heritable --- packages/format/src/formatter/RowFormatter.ts | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/format/src/formatter/RowFormatter.ts b/packages/format/src/formatter/RowFormatter.ts index bb5066ab..368cd117 100644 --- a/packages/format/src/formatter/RowFormatter.ts +++ b/packages/format/src/formatter/RowFormatter.ts @@ -9,19 +9,19 @@ type RowFormatterTransform = (row: I, cb: RowTrans type RowFormatterCallback = (error: Error | null, data?: RowArray) => void; export class RowFormatter { - private static isRowHashArray(row: Row): row is RowHashArray { + protected static isRowHashArray(row: Row): row is RowHashArray { if (Array.isArray(row)) { return Array.isArray(row[0]) && row[0].length === 2; } return false; } - private static isRowArray(row: Row): row is RowArray { + protected static isRowArray(row: Row): row is RowArray { return Array.isArray(row) && !this.isRowHashArray(row); } // get headers from a row item - private static gatherHeaders(row: Row): string[] { + protected static gatherHeaders(row: Row): string[] { if (RowFormatter.isRowHashArray(row)) { // lets assume a multi-dimesional array with item 0 being the header return row.map((it): string => it[0]); @@ -33,7 +33,7 @@ export class RowFormatter { } // eslint-disable-next-line @typescript-eslint/no-shadow - private static createTransform( + protected static createTransform( transformFunction: RowTransformFunction, ): RowFormatterTransform { if (isSyncTransform(transformFunction)) { @@ -52,19 +52,19 @@ export class RowFormatter { }; } - private readonly formatterOptions: FormatterOptions; + protected readonly formatterOptions: FormatterOptions; - private readonly fieldFormatter: FieldFormatter; + protected readonly fieldFormatter: FieldFormatter; - private readonly shouldWriteHeaders: boolean; + protected readonly shouldWriteHeaders: boolean; - private _rowTransform?: RowFormatterTransform; + protected _rowTransform?: RowFormatterTransform; - private headers: string[] | null; + protected headers: string[] | null; - private hasWrittenHeaders: boolean; + protected hasWrittenHeaders: boolean; - private rowCount = 0; + protected rowCount = 0; public constructor(formatterOptions: FormatterOptions) { this.formatterOptions = formatterOptions; @@ -129,7 +129,7 @@ export class RowFormatter { // check if we need to write header return true if we should also write a row // could be false if headers is true and the header row(first item) is passed in - private checkHeaders(row: Row): { headers?: string[] | null; shouldFormatColumns: boolean } { + protected checkHeaders(row: Row): { headers?: string[] | null; shouldFormatColumns: boolean } { if (this.headers) { // either the headers were provided by the user or we have already gathered them. return { shouldFormatColumns: true, headers: this.headers }; @@ -147,7 +147,7 @@ export class RowFormatter { } // todo change this method to unknown[] - private gatherColumns(row: Row): string[] { + protected gatherColumns(row: Row): string[] { if (this.headers === null) { throw new Error('Headers is currently null'); } @@ -171,14 +171,14 @@ export class RowFormatter { return this.headers.map((header, i): string => row[i]); } - private callTransformer(row: I, cb: RowTransformCallback): void { + protected callTransformer(row: I, cb: RowTransformCallback): void { if (!this._rowTransform) { return cb(null, (row as unknown) as O); } return this._rowTransform(row, cb); } - private formatColumns(columns: string[], isHeadersRow: boolean): string { + protected formatColumns(columns: string[], isHeadersRow: boolean): string { const formattedCols = columns .map((field, i): string => this.fieldFormatter.format(field, i, isHeadersRow)) .join(this.formatterOptions.delimiter);