Socket
Book a DemoInstallSign in
Socket

array-from-async

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-from-async

An implementation for Array.fromAsync, which dumps an async iterator into an array.

latest
Source
npmnpm
Version
3.0.0
Version published
Weekly downloads
1.6K
236.91%
Maintainers
2
Weekly downloads
 
Created
Source

Array.fromAsync polyfill

TC39 is considering a new standard Array.fromAsync convenience method. This is a standalone polyfill for that.

Requirements

This polyfill requires ES 2018 (which must include support for async iterators).

Installation

In Node:

npm install array-from-async

…then:

import fromAsync from 'array-from-async';

In web browsers or Deno:

import fromAsync from '//unpkg.com/array-from-async';

Description

This is a standalone implementation of the proposed Array.fromAsync function. Unlike typical polyfills/shims, it does not mutate the global Array constructor; instead, it exports an equivalent function.

Similarly to Array.from, fromAsync would be a static method of the Array built-in class, with one required argument and two optional arguments: (items, mapfn, thisArg).

But instead of converting an iterable to an array, it converts an async iterable to a promise that will resolve to an array.

async function * f () {
  for (let i = 0; i < 4; i++)
    yield i * 2;
}

// Resolves to `[0, 2, 4, 6]`.
await fromAsync(f());

For more information, see the Array.fromAsync explainer.

Keywords

polyfill

FAQs

Package last updated on 09 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts