A minimal ponyfill for Array.fromAsync.
It converts async iterables, sync iterables, and array-like objects into arrays.
Prefer the native Array.fromAsync when available.
npm i from-async
# or
pnpm add from-async
# or
yarn add from-asyncimport { fromAsync } from 'from-async'
async function* asyncGen() {
yield 'a'
yield 'b'
yield 'c'
}
const array = await fromAsync(asyncGen())
console.log(array) // ['a', 'b', 'c']function fromAsync<T>(
iterable: AsyncIterable<T> | Iterable<T> | ArrayLike<T>
): Promise<Awaited<T>[]>iterable: An async iterable, sync iterable, or array-like object.- Returns: A promise that resolves to an array of values, preserving input order.
function fromAsync<T, U>(
iterable: AsyncIterable<T> | Iterable<T> | ArrayLike<T>,
project: (value: Awaited<T>, index: number) => U,
thisArg?: unknown
): Promise<Awaited<U>[]>iterable: An async iterable, sync iterable, or array-like object.project: Called asproject(value, index)for each item.thisArg: Optionalthisvalue used when callingproject.- Returns: A promise that resolves to an array of mapped values, preserving input order.
MIT