Fix typing parse fn with NODE_STREAM_INPUT arg (#30251)

As stated in the Papaparse documentation
(https://github.com/mholt/PapaParse#papa-parse-for-node), calling Papa.parse
with NODE_STREAM_INPUT argument returns a Duplex that is both readable and
writable. This is for the use case of piping a ReadableStream through Papa CSV
parsing and continuing the stream chain.
This commit is contained in:
Janne Liuhtonen
2018-11-03 15:56:06 +00:00
committed by John Reilly
parent 882b31e47f
commit 59131a29cb
2 changed files with 15 additions and 2 deletions
+2 -1
View File
@@ -7,6 +7,7 @@
// Alberto Restifo <https://github.com/albertorestifo>
// Behind The Math <https://github.com/BehindTheMath>
// 3af <https://github.com/3af>
// Janne Liuhtonen <https://github.com/jliuhtonen>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
@@ -23,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.ReadableStream;
export function parse(stream: typeof NODE_STREAM_INPUT, config?: ParseConfig): NodeJS.ReadWriteStream;
/**
* Unparses javascript data objects and returns a csv string
+13 -1
View File
@@ -9,6 +9,7 @@ import {
ParseMeta,
ParseResult
} from "papaparse";
import { Readable } from "stream";
/**
* Parsing
@@ -40,8 +41,19 @@ Papa.parse(file, {
}
});
const readable = new Readable()
const rows = [
"1,2,3",
"4,5,6"
]
Papa.parse(Papa.NODE_STREAM_INPUT);
rows.forEach(r => {
readable.push(r);
});
const papaStream: NodeJS.ReadWriteStream = Papa.parse(Papa.NODE_STREAM_INPUT);
readable.pipe(papaStream);
/**
* Unparsing