This commit is contained in:
Jerry Kurian
2019-08-15 11:54:50 -04:00
parent 3a1fbf44d7
commit a40b1bf38c
38 changed files with 1981 additions and 2616 deletions

View File

@@ -0,0 +1,22 @@
import { Transform } from "stream";
import { JsonValue, JsonParseOptions } from "../definitions";
/**
* Return a ReadWrite stream that stringifies the streamed chunks to JSON
*/
export function stringify(
options: JsonParseOptions = { pretty: false },
): NodeJS.ReadWriteStream {
return new Transform({
readableObjectMode: true,
writableObjectMode: true,
transform(chunk: JsonValue, encoding, callback) {
callback(
undefined,
options.pretty
? JSON.stringify(chunk, null, 2)
: JSON.stringify(chunk),
);
},
});
}