Giter Site home page Giter Site logo

isomorphic-streams's Introduction

isomorphic-streams

Node.js CI NPM version license TypeScript types

Isomorphic WHATWG Streams API package for browser and Node.js

This package has

  • zero dependencies
  • provides TypeScript typings
  • supports ReadableStream, WritableStream and TransformStream

Table of Contents

Install

Use either

yarn add isomorphic-streams

or

npm install isomorphic-streams

Usage

In the browser: Instead of using the global ReadbaleStream or window.ReadableStream, import from this package instead.

In Node.js: Instead of importing node:stream/web or requiring stream/web, import from this package instead.

The following code will work in both Node.js and the browser:

import { ReadableStream } from "isomorphic-streams";

const SECOND = 1000;

const stream = new ReadableStream({
  start(controller) {
    setInterval(() => {
      controller.enqueue(Date.now());
    }, SECOND);
  },
});

for await (const value of stream) {
  console.log(value);
}

More examples

Contributing

This project is open to feedback and contributions, please open an issue.

isomorphic-streams follows the Contributor Covenant Code of Conduct.

License

MIT © 2021 Konstantin Möllers, see LICENSE.

isomorphic-streams's People

Contributors

argon-dev avatar ksm2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

isomorphic-streams's Issues

Missing type declaration for static method `from`

Hello,

Nice work, it's great to be able to use streaming in a library that might be used in either the back or front end.

One minor thing, the type declaration for the class ReadableStream is missing the static method from. It should look something like:

export class ReadableStream<T> {
  // ...
  static from(iterable: Iterable<T> | AsyncIterable<T>): ReadableStream<T>
  // ...
}

Cheers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.