CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
1# web-streams-polyfill2 3Web Streams, based on the WHATWG spec reference implementation.  4 5[![build status](https://api.travis-ci.com/MattiasBuelens/web-streams-polyfill.svg?branch=master)](https://travis-ci.com/MattiasBuelens/web-streams-polyfill)6[![npm version](https://img.shields.io/npm/v/web-streams-polyfill.svg)](https://www.npmjs.com/package/web-streams-polyfill)7[![license](https://img.shields.io/npm/l/web-streams-polyfill.svg)](https://github.com/MattiasBuelens/web-streams-polyfill/blob/master/LICENSE)8 9## Links10 11 - [Official spec][spec]12 - [Reference implementation][ref-impl]13 14## Usage15 16This library comes in multiple variants:17* `web-streams-polyfill`: a polyfill that replaces the native stream implementations.18  Recommended for use in web apps supporting older browsers through a `<script>` tag.19* `web-streams-polyfill/es6`: a polyfill targeting ES2015+ environments.20  Recommended for use in web apps supporting modern browsers through a `<script>` tag.21* `web-streams-polyfill/es2018`: a polyfill targeting ES2018+ environments.22* `web-streams-polyfill/ponyfill`: a [ponyfill] that provides23  the stream implementations without replacing any globals.24  Recommended for use in legacy Node applications, or in web libraries supporting older browsers.25* `web-streams-polyfill/ponyfill/es6`: a ponyfill targeting ES2015+ environments.26  Recommended for use in Node 6+ applications, or in web libraries supporting modern browsers.27* `web-streams-polyfill/ponyfill/es2018`: a ponyfill targeting ES2018+ environments.28  Recommended for use in Node 10+ applications.29 30Each variant also includes TypeScript type definitions, compatible with the DOM type definitions for streams included in TypeScript.31 32Usage as a polyfill:33```html34<!-- option 1: hosted by unpkg CDN -->35<script src="https://unpkg.com/web-streams-polyfill/dist/polyfill.min.js"></script>36<!-- option 2: self hosted -->37<script src="/path/to/web-streams-polyfill/dist/polyfill.min.js"></script>38<script>39var readable = new ReadableStream();40</script>41```42Usage as a Node module:43```js44var streams = require("web-streams-polyfill/ponyfill");45var readable = new streams.ReadableStream();46```47Usage as a ES2015 module:48```js49import { ReadableStream } from "web-streams-polyfill/ponyfill";50const readable = new ReadableStream();51```52 53## Compatibility54 55The `polyfill` and `ponyfill` variants work in any ES5-compatible environment that has a global `Promise`.56If you need to support older browsers or Node versions that do not have a native `Promise` implementation57(check the [support table][promise-support]), you must first include a `Promise` polyfill58(e.g. [promise-polyfill][promise-polyfill]).59 60The `polyfill/es6` and `ponyfill/es6` variants work in any ES2015-compatible environment.61 62The `polyfill/es2018` and `ponyfill/es2018` variants work in any ES2018-compatible environment.63 64[Async iterable support for `ReadableStream`][rs-asynciterator] is available in all variants, but requires an ES2018-compatible environment or a polyfill for `Symbol.asyncIterator`.65 66[`WritableStreamDefaultController.signal`][ws-controller-signal] is available in all variants, but requires a global `AbortController` constructor. If necessary, consider using a polyfill such as [abortcontroller-polyfill].67 68[Reading with a BYOB reader][mdn-byob-read] 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.69 70## Compliance71 72The polyfill implements [version `4dc123a` (13 Nov 2023)][spec-snapshot] of the streams specification.73 74The polyfill is tested against the same [web platform tests][wpt] that are used by browsers to test their native implementations.75The polyfill aims to pass all tests, although it allows some exceptions for practical reasons:76* The `es2018` variant passes all of the tests.77* The `es6` variant passes the same tests as the `es2018` variant, except for the [test for the prototype of `ReadableStream`'s async iterator][wpt-async-iterator-prototype].78  Retrieving the correct `%AsyncIteratorPrototype%` requires using an async generator (`async function* () {}`), which is invalid syntax before ES2018.79  Instead, the polyfill [creates its own version][stub-async-iterator-prototype] which is functionally equivalent to the real prototype.80* The `es5` variant passes the same tests as the `es6` variant, except for various tests about specific characteristics of the constructors, properties and methods.81  These test failures do not affect the run-time behavior of the polyfill.82  For example:83  * The `name` property of down-leveled constructors is incorrect.84  * The `length` property of down-leveled constructors and methods with optional arguments is incorrect.85  * Not all properties and methods are correctly marked as non-enumerable.86  * Down-leveled class methods are not correctly marked as non-constructable.87 88The type definitions are compatible with the built-in stream types of TypeScript 3.3.89 90## Contributors91 92Thanks to these people for their work on [the original polyfill][creatorrr-polyfill]:93 94 - Diwank Singh Tomer ([creatorrr](https://github.com/creatorrr))95 - Anders Riutta ([ariutta](https://github.com/ariutta))96 97[spec]: https://streams.spec.whatwg.org98[ref-impl]: https://github.com/whatwg/streams99[ponyfill]: https://github.com/sindresorhus/ponyfill100[promise-support]: https://kangax.github.io/compat-table/es6/#test-Promise101[promise-polyfill]: https://www.npmjs.com/package/promise-polyfill102[rs-asynciterator]: https://streams.spec.whatwg.org/#rs-asynciterator103[ws-controller-signal]: https://streams.spec.whatwg.org/#ws-default-controller-signal104[abortcontroller-polyfill]: https://www.npmjs.com/package/abortcontroller-polyfill105[mdn-byob-read]: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader/read106[spec-snapshot]: https://streams.spec.whatwg.org/commit-snapshots/4dc123a6e7f7ba89a8c6a7975b021156f39cab52/107[wpt]: https://github.com/web-platform-tests/wpt/tree/2a298b616b7c865917d7198a287310881cbfdd8d/streams108[wpt-async-iterator-prototype]: https://github.com/web-platform-tests/wpt/blob/2a298b616b7c865917d7198a287310881cbfdd8d/streams/readable-streams/async-iterator.any.js#L24109[stub-async-iterator-prototype]: https://github.com/MattiasBuelens/web-streams-polyfill/blob/v2.0.0/src/target/es5/stub/async-iterator-prototype.ts110[creatorrr-polyfill]: https://github.com/creatorrr/web-streams-polyfill111