From 4cd46002cc22ca2369ad098545ba75d38ce39863 Mon Sep 17 00:00:00 2001 From: David Worms Date: Fri, 26 May 2023 12:11:59 +0200 Subject: [PATCH] build(csv-parse): build and write test after info ts definition --- packages/csv-parse/dist/cjs/index.d.cts | 4 ++++ packages/csv-parse/dist/esm/index.d.ts | 4 ++++ packages/csv-parse/test/api.types.sync.ts | 5 +++-- packages/csv-parse/test/api.types.ts | 23 ++++++++++++++++++++++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/csv-parse/dist/cjs/index.d.cts b/packages/csv-parse/dist/cjs/index.d.cts index f16b9d314..d082c7133 100644 --- a/packages/csv-parse/dist/cjs/index.d.cts +++ b/packages/csv-parse/dist/cjs/index.d.cts @@ -234,6 +234,10 @@ export interface Info { * Number of non uniform records when `relax_column_count` is true. */ readonly invalid_field_length: number; + /** + * Normalized verion of `options.columns` when `options.columns` is true, boolean otherwise. + */ + readonly columns: boolean | { name: string }[] | { disabled: true }[]; } export type CsvErrorCode = diff --git a/packages/csv-parse/dist/esm/index.d.ts b/packages/csv-parse/dist/esm/index.d.ts index f16b9d314..d082c7133 100644 --- a/packages/csv-parse/dist/esm/index.d.ts +++ b/packages/csv-parse/dist/esm/index.d.ts @@ -234,6 +234,10 @@ export interface Info { * Number of non uniform records when `relax_column_count` is true. */ readonly invalid_field_length: number; + /** + * Normalized verion of `options.columns` when `options.columns` is true, boolean otherwise. + */ + readonly columns: boolean | { name: string }[] | { disabled: true }[]; } export type CsvErrorCode = diff --git a/packages/csv-parse/test/api.types.sync.ts b/packages/csv-parse/test/api.types.sync.ts index 05804166a..afccfd19f 100644 --- a/packages/csv-parse/test/api.types.sync.ts +++ b/packages/csv-parse/test/api.types.sync.ts @@ -79,12 +79,13 @@ describe('API Types', () => { it('Info', () => { const info: Info = { + bytes: 1, + columns: true, comment_lines: 1, empty_lines: 1, + invalid_field_length: 1, lines: 1, records: 1, - bytes: 1, - invalid_field_length: 1, }; return info; }) diff --git a/packages/csv-parse/test/api.types.ts b/packages/csv-parse/test/api.types.ts index fbd63e7ee..82fbeb7a5 100644 --- a/packages/csv-parse/test/api.types.ts +++ b/packages/csv-parse/test/api.types.ts @@ -88,7 +88,7 @@ describe('API Types', () => { describe('Info', () => { const fakeinfo = { - bytes: 1, + bytes: 1, columns: true, comment_lines: 1, empty_lines: 1, invalid_field_length: 1, lines: 1, records: 1 } @@ -128,6 +128,27 @@ describe('API Types', () => { const invalid_field_length: number = info.invalid_field_length invalid_field_length }) + + it('columns may be a boolean or an array', () => { + // Boolean + const infoBoolean: Info = { + bytes: 1, columns: true, + comment_lines: 1, empty_lines: 1, + invalid_field_length: 1, lines: 1, records: 1 + } + // Array with name = + const infoName: Info = { + bytes: 1, columns: [{name: 'a column'}], + comment_lines: 1, empty_lines: 1, + invalid_field_length: 1, lines: 1, records: 1 + } + // Array with disabled = true + const infoDisabled: Info = { + bytes: 1, columns: [{disabled: true}], + comment_lines: 1, empty_lines: 1, + invalid_field_length: 1, lines: 1, records: 1 + } + }) })