# promised-array

> Array combined with Promise, chainable, asynchronous methods and callbacks ready for async/await.

Latest version **1.1.2** (published 2019-09-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install promised-array
pnpm add promised-array
yarn add promised-array
bun add promised-array
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2019-09-26 |
| First published | 2019-01-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 0 |
| Unpacked size | 91.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Ferdinand Prantl |
| Maintainers | prantlf |
| Keywords | array, asynchronous, promise |

## Links

- npm: https://www.npmjs.com/package/promised-array
- Repository: https://github.com/prantlf/promised-array
- Homepage: https://github.com/prantlf/promised-array#readme
- Issues: https://github.com/prantlf/promised-array/issues
- npm.io page: https://npm.io/package/promised-array

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2019-09-26
- 1.1.1 — 2019-06-07
- 1.1.0 — 2019-03-10
- 1.0.0 — 2019-01-20
- 0.0.1 — 2019-01-20

## README

# PromisedArray

[![NPM version](https://badge.fury.io/js/promised-array.png)](http://badge.fury.io/js/promised-array)
[![Build Status](https://travis-ci.org/prantlf/promised-array.png)](https://travis-ci.org/prantlf/promised-array)
[![Coverage Status](https://coveralls.io/repos/github/prantlf/promised-array/badge.svg?branch=master)](https://coveralls.io/github/prantlf/promised-array?branch=master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a93e689283b447bfb8684f957f32ba50)](https://www.codacy.com/app/prantlf/promised-array?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=prantlf/promised-array&amp;utm_campaign=Badge_Grade)
[![devDependency Status](https://david-dm.org/prantlf/promised-array/dev-status.svg)](https://david-dm.org/prantlf/promised-array#info=devDependencies)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

[![NPM Downloads](https://nodei.co/npm/promised-array.png?downloads=true&stars=true)](https://www.npmjs.com/package/promised-array)

`PromisedArray` combines the interface of `Promise` and `Array`.

* It is a native `Promise`. You can use it in a promise chain and with the `await` operator.
* It includes all members of `Array.prototype`. They will apply to the array, which the promise resolves to and they return a promise to the result of the original method.
* Methods of `Array.prototype`, which expect callbacks, accept also asynchronous callbacks. They will wait, until the callback's promise resolves and continue with the result.
* No need to mark the callback by the `async` keyword, if they don't use teh `await` keyword and just return a promise.
* Callback execution possible either sequentially or concurrently.
* No dependencies on other modules.

**Warnig:** still in the development.

### Table of Contents

- [Synopsis](#synopsis)
- [Description](#description)

## Synopsis

```js
// Print an array of names of items with the specified keys.
new PromisedArray([1, 2, 3])
  .map(key => fetch('https://server.com/items/' + key))
  .map(response => response.json().name)
  .then(names => console.log(names))
  .catch(error => console.error(error))
````

## Description

`PromisedArray` is a function object with the prototype combined from
`Promise` and `Array`. Instances can be constructed either from an array
or from a promise resolving to an array.

```js
// Print names of all items.
const promise = fetch('https://server.com/items')
  .then(response => response.json())
PromisedArray
  .fromPromise(promise)
  .forEach({ name } => console.log(name))
  .catch(console.error)
```

Methods of the `PromisedArray` prototype, which share their names with
their corresponding methods of the original `Array` prototype, have the
same semantics and guarantees the same order of processing array items.
They return the same result, only wrapped in a `PromisedArray` instance,
if it is an array, or in a stqndqrd promise in other cases.
Methods, which accept callbacks as parameters, check, if the result of
the callback is a promise or not. If it is, they wait for its resolution
and continue with the result. If the promise gets rejected, the whole
result promise will be rejected and the loop over array items aborted.

Methods which end with `Concurrently` execute callbacks for every array
item concurrently and wait for resulution of all promises for callback
call results, before they process the results. The order callback
execution may differ from the original method from the `Array` prototype.
If the method returns an array, order of results in that array is guaranteed
to be the same as the original method from the `Array` prototype would
return.

## License

Copyright (c) 2019 Ferdinand Prantl

Licensed under the MIT license.

[Node.js]: http://nodejs.org/
[NPM]: https://www.npmjs.com/

---
_Source: https://npm.io/package/promised-array · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
