npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

web-streams-polyfill

v4.0.0

Published

Web Streams, based on the WHATWG spec reference implementation

Downloads

53,682,007

Readme

web-streams-polyfill

Web Streams, based on the WHATWG spec reference implementation.

build status npm version license

Links

Usage

This library comes in multiple variants:

  • web-streams-polyfill: a ponyfill that provides the stream implementations without replacing any globals, targeting ES2015+ environments. Recommended for use in Node 6+ applications, or in web libraries supporting modern browsers.
  • web-streams-polyfill/es5: a ponyfill targeting ES5+ environments. Recommended for use in legacy Node applications, or in web libraries supporting older browsers.
  • web-streams-polyfill/polyfill: a polyfill that replaces the native stream implementations, targeting ES2015+ environments. Recommended for use in web apps supporting modern browsers through a <script> tag.
  • web-streams-polyfill/polyfill/es5: a polyfill targeting ES5+ environments. Recommended for use in web apps supporting older browsers through a <script> tag.

Each variant also includes TypeScript type definitions, compatible with the DOM type definitions for streams included in TypeScript. These type definitions require TypeScript version 4.7 or higher.

In version 4, the list of variants was reworked to have more modern defaults and to reduce the download size of the package. See the migration guide for more information.

Usage as a polyfill:

<!-- option 1: hosted by unpkg CDN -->
<script src="https://unpkg.com/web-streams-polyfill/dist/polyfill.js"></script>
<!-- option 2: self hosted -->
<script src="/path/to/web-streams-polyfill/dist/polyfill.js"></script>
<script>
var readable = new ReadableStream();
</script>

Usage as a Node module:

var streams = require("web-streams-polyfill");
var readable = new streams.ReadableStream();

Usage as a ponyfill from within a ES2015 module:

import { ReadableStream } from "web-streams-polyfill";
const readable = new ReadableStream();

Usage as a polyfill from within an ES2015 module:

import "web-streams-polyfill/polyfill";
const readable = new ReadableStream();

Compatibility

The polyfill and ponyfill variants work in any ES2015-compatible environment.

The polyfill/es5 and ponyfill/es5 variants work in any ES5-compatible environment that has a global Promise. If you need to support older browsers or Node versions that do not have a native Promise implementation (check the support table), you must first include a Promise polyfill (e.g. promise-polyfill).

Async iterable support for ReadableStream is available in all variants, but requires an ES2018-compatible environment or a polyfill for Symbol.asyncIterator.

WritableStreamDefaultController.signal is available in all variants, but requires a global AbortController constructor. If necessary, consider using a polyfill such as abortcontroller-polyfill.

Reading with a BYOB reader is available in all variants, but requires ArrayBuffer.prototype.transfer() or structuredClone() to exist in order to correctly transfer the given view's buffer. If not available, then the buffer won't be transferred during the read.

Tooling compatibility

This package uses subpath exports for its variants. As such, you need Node 12 or higher in order to import or require() such a variant.

When using TypeScript, make sure your moduleResolution is set to "node16", "nodenext" or "bundler".

Compliance

The polyfill implements version 4dc123a (13 Nov 2023) of the streams specification.

The polyfill is tested against the same web platform tests that are used by browsers to test their native implementations. The polyfill aims to pass all tests, although it allows some exceptions for practical reasons:

  • The default (ES2015) variant passes all of the tests, except for the test for the prototype of ReadableStream's async iterator. Retrieving the correct %AsyncIteratorPrototype% requires using an async generator (async function* () {}), which is invalid syntax before ES2018. Instead, the polyfill creates its own version which is functionally equivalent to the real prototype.
  • The ES5 variant passes the same tests as the ES2015 variant, except for various tests about specific characteristics of the constructors, properties and methods. These test failures do not affect the run-time behavior of the polyfill. For example:
    • The name property of down-leveled constructors is incorrect.
    • The length property of down-leveled constructors and methods with optional arguments is incorrect.
    • Not all properties and methods are correctly marked as non-enumerable.
    • Down-leveled class methods are not correctly marked as non-constructable.

Contributors

Thanks to these people for their work on the original polyfill: