web-stream-replace
v0.1.2
Published
Replace strings in a Web Streams API TransformStream
Downloads
175
Readme
web-stream-replace
Search & replace strings in a Web Streams API TransformStream.
Outputs either strings or UTF-8 encoded Uint8Array
s.
Installation
npm install --save web-stream-replace
Example
import { replace } from "web-stream-replace";
const greet = (name: string) => replace("World", name, { output: "string" });
const output = () => {
let buf = "";
return new WritableStream<string>({
write(chunk) {
buf += chunk;
},
close() {
console.log(buf);
},
});
};
const hello = new ReadableStream({
start(controller) {
controller.enqueue("Hello, World!");
controller.close();
},
});
const transformed = hello.pipeThrough(greet("Netlify"));
await transformed.pipeTo(output());