promisie

3.0.1 • Public • Published

Promisie

Coverage Status Build Status NPM version Downloads Per Month npm Join the chat at https://gitter.im/typesettin/promisie

Download Stats

Promisie is an extension of the ES6 native Promise class that provides helpful static methods that are seen in many other Promise libraries

Promisie Logo

Version

2.0.0-alpha.0

Installation

Because Promisie uses native ES6 Promises, classes and spread operators you must be running Node v6.0.0 or above

$ npm i promisie

Usage

/*
Because Promisie is an extension of the Promise class it also acts as a Promise constructor and shares all prototype methods, but adds promisify and promisifyAll static methods
*/
const Promisie = require('promisie'),
    fs = require('fs');
var readFileAsync = Promisie.promisify(fs.readFile);
readFileAsync('/some/file/path').then(fileData => { ... });
var asyncFs = Promisie.promisifyAll(fs);
asyncFs.readFileAsync('/some/file/path').then(fileData => { ... });
/*
Promisie also exposes a "try" method which works just like "then" but conveniently wrapped in a try/catch block
 */
readFileAsync('/some/file/path')
    .try(data => {
        return data.some.fake.property; //Cant't read property ... of undefined
    })
    .catch(e => { ... });
/*
This would normally halt the execution of your async code because of an unhandled error but the "try" method properly rejects with the error
 */
/*
Promisie also has a series static method which runs and array of functions in series passing the result of each function to the next function.
Additionally there are pipe and compose static methods which return a function expecting arguments that will be passed to the first function in the series (compose reverses the order of the functions it is passed)
*/
let array_of_functions = [fn, fn1, fn2, fn3];
Promisie.series(array_of_functions)
    .then(result => {
        //result is the resolved value of the last function in the array
    })
let pipe = Promisie.pipe(array_of_functions);
pipe('some', 'random', 'arguments')
    .then(result => {
        //result is still the resolved value of the last function in the array with the difference being the first function will be passed the arguments of pipe()
    })
/*
Promisie now has many more helpful methods:
- .map
- .each
- .parallel
- .doWhilst
- .iterate
- .settle
- .all
- .retry
See documentation for more details and test for usage
*/

Notes

Testing

$ npm i promisie
cd ./node_modules/promisie
$ npm i
$ npm test

For generating documentation

$ grunt doc
$ jsdoc2md utility/**/*.js index.js > doc/api.md

Todos

  • Add more prototype and static methods
    • Filter
    • Reduce
    • Queue

License

MIT

Package Sidebar

Install

npm i promisie

Weekly Downloads

35

Version

3.0.1

License

MIT

Unpacked Size

1.26 MB

Total Files

97

Last publish

Collaborators

  • yawetse
  • janbialostok