web-stream-replace
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

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

Package Sidebar

Install

npm i web-stream-replace

Weekly Downloads

31

Version

0.1.2

License

MIT

Unpacked Size

20 kB

Total Files

12

Last publish

Collaborators

  • neolegends