🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

attempt-x

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
a

attempt-x

Invokes function, returning an object of the results.

2.1.2
latest
87

Supply Chain Security

100

Vulnerability

100

Quality

77

Maintenance

100

License

AI-detected possible typosquat

Supply chain risk

There is a package with a similar name that is downloaded much more often.

Did you mean

jotai-x

Dependencies have 7 high alerts.

Socket optimized override available

Version published
Weekly downloads
6.8K
-3.04%
Maintainers
1
Weekly downloads
 
Created
Issues
21

Travis status Dependency status devDependency status npm version jsDelivr hits bettercodehub score Coverage Status

attempt-x

Invokes function, returning an object of the results.

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.

ParamTypeDescription
fnfunctionThe function to attempt.
[...args]*The arguments to invoke the function with.

Example

import attempt from '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
// }

const thisArg = [];
function pusher(a, b) {
  return this.push(a, b);
}

attempt.call(thisArg, pusher, 1, 2);
// {
//   threw: false,
//   value: 2
// }
// thisArg => [1, 2];

FAQs

Package last updated on 28 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts