no-throw
v1.0.1
Published
Wraps a function and makes it return {error, value} instead of throwing.
Downloads
3
Readme
no-throw
Wraps a function and makes it return {error, value} instead of throwing.
Install
$ npm install --save no-throw
Usage
'use strict';
var noThrow = require('no-throw');
var sqrt = function(n) {
if (n < 0) {
throw new Error('Encountered a complication.');
}
return Math.sqrt(n);
};
console.log(
noThrow(sqrt)( -1), // { error: <Error...>, value: undefined }
noThrow(sqrt)(100) // { error: undefined, value: 10 }
);
License
MIT © Andrew Morris