0.1.2 • Published 4 years ago

web-stream-replace v0.1.2

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

web-stream-replace

Search & replace strings in a Web Streams API TransformStream.

Outputs either strings or UTF-8 encoded Uint8Arrays.

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());
0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago