1.2.1 • Published 5 years ago

promdash v1.2.1

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

Promdash

Coverage Status Build Status NPM Version Dependencies License

Lodash implementation in ES6 Promises.

NPM

NPM

API

Lodash on the instance

All functions listed in the lodash API are added to the Promise class.

import Promdash from 'promdash';

let promise = new Promdash(resolve => resolve([0, 1, 2, 3, 4]));

promise
  .filter()
  .map(x => x + 1)
  .rest()
  .then(console.log); // [3, 4, 5]

Lodash on the class

Lodash is also available statically:

import Promdash from 'promdash';

Promdash
  .filter([0, promise1, 2, promise3, 4])
  .map(x => x + 1)
  .rest()
  .then(console.log); // [3, 4, 5]

.then(Promise[])

Every Promdash method, including then(), resolves arrays of promises.

import Promdash from 'promdash';

Promdash
  .rest(promises)
  // resolves all promses... then
  .map(item => doSomethingAsyncronous(item))
  // again, resolves all promises
  .then(console.log);

// This is equivalent to doing:
Promise
  .all(promises)
  .then(items => Promise.all(_.rest(items))
  .then(items => Promise.all(_.map(items, item => doSomethingAsyncronous(item))))
  .then(console.log);

.from()

If you need to need to convert an instance of Promise in to an instance of Promdash, use the .from() function:

import Promdash from 'promdash';
import reqwest from 'reqwest';

let promise = reqwest.get('/some-data.json');
Promdash.from(promise).map(item => item + 2);

How?

Simply an extended Promise class that has a then method for every lodash function.

The lodash version is completely up to you. If you install lodash before installing promdash, promdash will pick up whatever version of lodash you're using. If you just install promdash, it will use the latest, stable version of lodash.

Installation

npm i promdash
1.2.1

5 years ago

1.2.0

7 years ago

1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago