From 0385d7f65c7bee470e86d5689f4eb28d4aa82d33 Mon Sep 17 00:00:00 2001 From: Lingkai Shen Date: Wed, 26 Jun 2019 13:16:41 -0400 Subject: [PATCH] Papaparse: Fix NODE_STREAM_INPUT for TypeScript/next test (#36419) * separate type and value for NODE_STREAM_INPUT * add test for NODE_STREAM_INPUT * format --- types/papaparse/index.d.ts | 3 ++- types/papaparse/papaparse-tests.ts | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/types/papaparse/index.d.ts b/types/papaparse/index.d.ts index 372df6a737..6b2ae0a1b5 100644 --- a/types/papaparse/index.d.ts +++ b/types/papaparse/index.d.ts @@ -24,7 +24,7 @@ export function parse(file: File, config?: ParseConfig): ParseResult; export function parse(stream: NodeJS.ReadableStream, config?: ParseConfig): ParseResult; -export function parse(stream: typeof NODE_STREAM_INPUT, config?: ParseConfig): NodeJS.ReadWriteStream; +export function parse(stream: NODE_STREAM_INPUT_TYPE, config?: ParseConfig): NodeJS.ReadWriteStream; /** * Unparses javascript data objects and returns a csv string @@ -55,6 +55,7 @@ export const WORKERS_SUPPORTED: boolean; export let SCRIPT_PATH: string; // When passed to Papa Parse a Readable stream is returned. +declare type NODE_STREAM_INPUT_TYPE = 1; export const NODE_STREAM_INPUT = 1; /** diff --git a/types/papaparse/papaparse-tests.ts b/types/papaparse/papaparse-tests.ts index a22ea5b14d..ab84fd5f1d 100644 --- a/types/papaparse/papaparse-tests.ts +++ b/types/papaparse/papaparse-tests.ts @@ -33,26 +33,28 @@ Papa.parse("3,3,3", { dynamicTyping: (field: string | number): boolean => /headerName/i.test(field.toString()) }); -Papa.parse("3,3,3", { - dynamicTyping: {'headerName': true} +Papa.parse('3,3,3', { + dynamicTyping: { headerName: true }, }); -Papa.parse("3,3,3", { - dynamicTyping: {5: true} +Papa.parse('3,3,3', { + dynamicTyping: { 5: true }, }); var file = new File(null, null, null); Papa.parse(file, { - transform: function(value, field) { - - }, - complete: function (a, b) { + transform: function(value, field) {}, + complete: function(a, b) { a.meta.fields; b.name; - } + }, }); +// .pipe to make sure it returns a stream +Papa.parse(Papa.NODE_STREAM_INPUT, { +}).pipe + const readable = new Readable() const rows = [ "1,2,3",