UNPKG

624 BPlain TextView Raw
1// deno-lint-ignore-file no-explicit-any
2import { jsonStringifyGenerator } from './json-stringify.js'
3
4export class JSONStringifyStream extends TransformStream<any, string> {
5 constructor() {
6 let first: boolean;
7 super({
8 start(controller) {
9 first = true;
10 controller.enqueue('[')
11 },
12 async transform(obj, controller) {
13 if (!first) controller.enqueue(','); else first = false;
14 for await (const chunk of jsonStringifyGenerator(obj)) {
15 controller.enqueue(chunk)
16 }
17 },
18 flush(controller) {
19 controller.enqueue(']')
20 },
21 })
22 }
23}