Promises, Promises Everywhere
A utility library that is all about JavaScript Promises!
About
I am always fascinated with things you can manipulate by using Promises. However, I was repeating my Promise conventions in every project or even multiple modules within the same project. Therefore, I decided that I should just write it once and use it as a library across all my projects.
Utilities
fake
A method that mimics an async function behavior. It takes an options configuration object as parameter, and returns either a resolved, or reject, promise.
Usage:
; // with async/await { const myPromiseResponse = await ;}
aggregate
A method that accepts a keyByArguments map, and a callback function. It will return an object where every key will contain the resolved or rejected promise from the callback function.
Usage:
const callbackFunction = async { const response = await ; return response;}; { const keyByArgs = first: id: '123' filter: false second: id: '234' filter: true ; const myPromiseResponse = await ;}
wrap
A method that accepts a callback function, and wraps it with a Promise so it can be used within any async/await function closure.
Usage:
const savePost = { return ;}; { const saveBlogPost = ; const savedBlogPost = await ; return savedBlogPost;}
Special Thanks
The people who are responsible for TSDX. A great utility to help you bootstrap a new npm library with TypeScript, Rollup and Jest testing framework. See TSDX on Github.