Giter VIP home page Giter VIP logo

promisie's Introduction

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

promisie's People

Contributors

actions-user avatar janbialostok avatar renovate-bot avatar yawetse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.