Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
is-async-function
Advanced tools
The is-async-function npm package is designed to help developers determine if a given function is an asynchronous function. This can be particularly useful in scenarios where the behavior of code needs to be altered based on whether a function is asynchronous or not, such as in dynamic function execution, middleware handling, or in libraries that need to support both synchronous and asynchronous operations.
Checking if a function is asynchronous
This feature allows you to check if a given function is an async function. The package exports a single function that takes one argument (the function to check) and returns a boolean indicating whether the function is asynchronous. This is useful for dynamically handling functions based on their nature.
const isAsyncFunction = require('is-async-function');
async function foo() {};
console.log(isAsyncFunction(foo)); // true
function bar() {};
console.log(isAsyncFunction(bar)); // false
The is-promise package checks if a value is a Promise, which is a related but different check compared to is-async-function. While is-async-function checks the nature of the function itself, is-promise checks the return value of a function to determine if it's a Promise. This distinction is crucial in understanding and handling asynchronous operations in JavaScript.
kind-of is a more general utility for checking the type of a value in JavaScript, which includes support for identifying functions and promises among many other types. Compared to is-async-function, kind-of offers a broader range of type checks but does not specifically focus on distinguishing between synchronous and asynchronous functions. It's more versatile but less specialized.
Is this a native async function
?
var isAsyncFunction = require('is-async-function');
assert(!isAsyncFunction(function () {}));
assert(!isAsyncFunction(null));
assert(!isAsyncFunction(function* () { yield 42; return Infinity; }));
assert(isAsyncFunction(async function () {}));
Simply clone the repo, npm install
, and run npm test
FAQs
Determine if a function is a native async function.
The npm package is-async-function receives a total of 12,642,927 weekly downloads. As such, is-async-function popularity was classified as popular.
We found that is-async-function demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.