Skip to content

aicest/from-async

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

from-async

NPM Version Codecov

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.

Install

npm i from-async
# or
pnpm add from-async
# or
yarn add from-async

Usage

import { fromAsync } from 'from-async'

async function* asyncGen() {
  yield 'a'
  yield 'b'
  yield 'c'
}

const array = await fromAsync(asyncGen())

console.log(array) // ['a', 'b', 'c']

API

fromAsync(iterable)

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.

fromAsync(iterable, project, thisArg?)

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 as project(value, index) for each item.
  • thisArg: Optional this value used when calling project.
  • Returns: A promise that resolves to an array of mapped values, preserving input order.

License

MIT

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors