Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
@stdlib/assert-is-function
Advanced tools
@stdlib/assert-is-function is a utility package that provides functionality to check if a value is a function. This can be useful in various scenarios where type checking is necessary to ensure that a value can be invoked as a function.
Basic Function Check
This feature allows you to check if a given value is a function. It returns `true` if the value is a function and `false` otherwise.
const isFunction = require('@stdlib/assert-is-function');
console.log(isFunction(function() {})); // true
console.log(isFunction(null)); // false
Arrow Function Check
This feature supports checking if an arrow function is a function. It returns `true` for arrow functions.
const isFunction = require('@stdlib/assert-is-function');
console.log(isFunction(() => {})); // true
Class Method Check
This feature allows you to check if a class method is a function. It returns `true` for class methods.
const isFunction = require('@stdlib/assert-is-function');
class MyClass {
myMethod() {}
}
console.log(isFunction(MyClass.prototype.myMethod)); // true
lodash.isfunction is a utility function from the Lodash library that checks if a value is classified as a Function object. It is similar to @stdlib/assert-is-function but is part of the larger Lodash utility library, which provides a wide range of utility functions for common programming tasks.
is-function is a lightweight npm package that checks if a given value is a function. It is similar to @stdlib/assert-is-function in its core functionality but is a standalone package without additional utilities.
type-detect is a library that provides type detection for JavaScript values. It can be used to check if a value is a function among other types. It offers more comprehensive type checking compared to @stdlib/assert-is-function, which focuses solely on function detection.
Test if a value is a function.
npm install @stdlib/assert-is-function
var isFunction = require( '@stdlib/assert-is-function' );
Tests if a value
is a function
.
function beep() {
console.log( 'beep' );
}
var bool = isFunction( beep );
// returns true
var isFunction = require( '@stdlib/assert-is-function' );
var bool = isFunction( function foo() {} );
// returns true
bool = isFunction( 'beep' );
// returns false
bool = isFunction( 5 );
// returns false
bool = isFunction( true );
// returns false
bool = isFunction( null );
// returns false
bool = isFunction( [] );
// returns false
bool = isFunction( {} );
// returns false
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
See LICENSE.
Copyright © 2016-2022. The Stdlib Authors.
0.0.8 (2022-02-16)
No changes reported for this release.
</section> <!-- /.release --> <section class="release" id="v0.0.7">FAQs
Test if a value is a function.
The npm package @stdlib/assert-is-function receives a total of 446,287 weekly downloads. As such, @stdlib/assert-is-function popularity was classified as popular.
We found that @stdlib/assert-is-function demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 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.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.