promise-disarm :bomb:
Utilities for making promises return errors instead of throwing them... and just like disarming actual bombs THIS IS POTENTIALLY UNSAFE, BE WARNED. Make sure you actually handle the errors somehow.
If the provided promise does not reject, it will just resolve as usual.
If anything other than a promise is provided, it will return a promise that resolve to whatever was provided.
Usage example
import { disarm, disarmAll } from 'promise-disarm';
const promise = new Promise(_, reject) => reject(new Error())
disarm(promise).then(result => {
console.log(result instanceof Error);
});
disarmAll([promise, promise]).then(result => {
console.log(result.every(item => item instanceof Error));
});
Development scripts
build
: transpiles and minifies all code in ./src
into ./lib
using babel;lint
: lints code in ./src
using eslint
;precommit
: (automatic) runs linter before every commit;prepublish
: (automatic) runs tests before attempting to publish the package;test
: runs tests in __tests__
using jest
.
Note: scripts assume you use yarn
, because you should ;)
Forked from vspedr/jables
Prueba de bomba, prueba de bala - Kontrust