npm

npm’s 2019 JavaScript ecosystem survey analysis is now available! Get your copy here »

attempt-x

1.1.3 • Public • Published

Travis status Dependency status devDependency status npm version

attempt-x

Invokes function, returning an object of the results.

Version: 1.1.3
Author: Xotic750 Xotic750@gmail.com
License: MIT
Copyright: Xotic750

module.exports(fn, [...args])Object

This method attempts to invoke the function, returning either the result or the caught error object. Any additional arguments are provided to the function when it's invoked.

Kind: Exported function
Returns: Object - Returns an object of the result.

Param Type Description
fn function The function to attempt.
[...args] * The arguments to invoke the function with.

Example

var attempt = require('attempt-x');
 
function thrower() {
  throw new Error('Threw');
}
 
attempt(thrower, 1, 2);
// {
//   threw: true,
//   value: // Error('Threw') object
// }
 
function sumArgs(a, b) {
  return a + b;
}
 
attempt(sumArgs, 1, 2);
// {
//   threw: false,
//   value: 3
// }
 
var thisArg = [];
function pusher(a, b) {
  return this.push(a, b);
}
 
attempt.call(thisArg, pusher, 1, 2);
// {
//   threw: false,
//   value: 2
// }
// thisArg => [1, 2];

install

npm i attempt-x

Downloadsweekly downloads

18,155

version

1.1.3

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability