1.0.3 • Published 2 years ago

promises-to-array v1.0.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

PromiseArray

Change array of promises to promise of array. Works out-of-the-box with Node, React and Angular.

It should also work with anything else, as it doesn't rely on any library.

image

Usage

View on NPM

Install from NPM:

npm i promises-to-array
import { ArrayOfPromisesToPromiseArray } from "promises-to-array"

// Assumes yourPromises is an array of Promises<AnyType>, for example
// from making many fetch requests

const promiseOfArray=ArrayOfPromisesToPromiseArray(yourPromises)

Example

import { ArrayOfPromisesToPromiseArray } from "promises-to-array"

const one: Promise<number> = new Promise((resolve, reject) => { resolve(1) })
const two: Promise<number> = new Promise((resolve, reject) => { resolve(2) })
const three: Promise<number> = new Promise((resolve, reject) => { resolve(3) })
const four: Promise<number> = new Promise((resolve, reject) => { resolve(4) })
const five: Promise<number> = new Promise((resolve, reject) => { resolve(5) })

const testingArray: Array<Promise<number>> = [
    one, two, three,
    four, five
]

ArrayOfPromisesToPromiseArray<number>(testingArray)
    .then(wholeArray => {
        // Do whatever with regular .map , .filter ...
        console.log(wholeArray.filter(x => x > 3))
    })

Example 2

image

image

image

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago