no-throw

1.0.1 • Public • Published

no-throw

NPM version Build Status Dependency Status Coverage percentage

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 (< 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

/no-throw/

    Package Sidebar

    Install

    npm i no-throw

    Weekly Downloads

    0

    Version

    1.0.1

    License

    none

    Last publish

    Collaborators

    • voltrevo