@worker-tools/json-stream
Version:
Utilities for working with streaming JSON in Worker Runtimes such as Cloudflare Workers, Deno Deploy and Service Workers.
30 lines • 1 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.JSONStringifyStream = void 0;
// deno-lint-ignore-file no-explicit-any
const json_stringify_js_1 = require("./json-stringify.js");
class JSONStringifyStream extends TransformStream {
constructor() {
let first;
super({
start(controller) {
first = true;
controller.enqueue('[');
},
async transform(obj, controller) {
if (!first)
controller.enqueue(',');
else
first = false;
for await (const chunk of (0, json_stringify_js_1.jsonStringifyGenerator)(obj)) {
controller.enqueue(chunk);
}
},
flush(controller) {
controller.enqueue(']');
},
});
}
}
exports.JSONStringifyStream = JSONStringifyStream;
//# sourceMappingURL=json-stringify-stream.js.map
;