From 3e5ddf7a401ab987742f2d464a4a4dc89e226a9c Mon Sep 17 00:00:00 2001 From: Fredrik Olsson <51903586+frdrkolsson@users.noreply.github.com> Date: Mon, 7 Oct 2024 13:45:20 +0200 Subject: [PATCH 1/2] Allow readString config to be optional Config should not be required for readString --- src/readString.ts | 2 +- test/readString.spec.ts | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/readString.ts b/src/readString.ts index 705c388..63b14b5 100644 --- a/src/readString.ts +++ b/src/readString.ts @@ -4,7 +4,7 @@ import { ReadStringConfig } from './model'; export function readString( csvString: string | typeof NODE_STREAM_INPUT, - config: ReadStringConfig & { + config?: ReadStringConfig & { download?: false | undefined; complete(results: ParseResult): void; }, diff --git a/test/readString.spec.ts b/test/readString.spec.ts index 122fb01..84e1a71 100644 --- a/test/readString.spec.ts +++ b/test/readString.spec.ts @@ -1,10 +1,8 @@ import expect from 'expect'; import { readString } from '../src/readString'; -// eslint-disable-next-line no-undef describe('readString', () => { - // eslint-disable-next-line no-undef - it('should return an array as expected', function () { + it('should return an array as expected', function() { const fixtures = `Column 1,Column 2,Column 3,Column 4 1-1,1-2,1-3,1-4 2-1,2-2,2-3,2-4 @@ -19,10 +17,37 @@ describe('readString', () => { ]; readString(fixtures, { worker: true, - complete: (results) => { + complete: (results: { data: string[][]; }) => { expect(Array.isArray(results.data)).toBe(true); expect(results.data).toEqual(expected); }, }); }); + + it('should return an array as expected even without config', function() { + const fixtures = `Column 1,Column 2,Column 3,Column 4 +1-1,1-2,1-3,1-4 +2-1,2-2,2-3,2-4 +3-1,3-2,3-3,3-4 +4,5,6,7`; + const expected = { + "data": [ + ["Column 1", "Column 2", "Column 3", "Column 4"], + ["1-1", "1-2", "1-3", "1-4"], + ["2-1", "2-2", "2-3", "2-4"], + ["3-1", "3-2", "3-3", "3-4"], + ["4", "5", "6", "7"] + ], + "errors": [], + "meta": { + "aborted": false, + "cursor": 91, + "delimiter": ",", + "linebreak": "\n", + "truncated": false + } + }; + const result = readString(fixtures); + expect(result).toEqual(expected); + }); }); From d5af6d1a6431818d13b6abbecc6b30d9cea47136 Mon Sep 17 00:00:00 2001 From: Fredrik Olsson <51903586+frdrkolsson@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:48:56 +0200 Subject: [PATCH 2/2] Update test/readString.spec.ts Co-authored-by: Gustav Ehrenborg --- test/readString.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/readString.spec.ts b/test/readString.spec.ts index 84e1a71..5051c1d 100644 --- a/test/readString.spec.ts +++ b/test/readString.spec.ts @@ -24,7 +24,7 @@ describe('readString', () => { }); }); - it('should return an array as expected even without config', function() { + it('should return an array as expected without config', function() { const fixtures = `Column 1,Column 2,Column 3,Column 4 1-1,1-2,1-3,1-4 2-1,2-2,2-3,2-4