What is @stdlib/assert-is-function?
@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.
What are @stdlib/assert-is-function's main functionalities?
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
Other packages similar to @stdlib/assert-is-function
lodash.isfunction
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-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
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.
About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
isFunction
Test if a value is a function.
Installation
npm install @stdlib/assert-is-function
Usage
var isFunction = require( '@stdlib/assert-is-function' );
isFunction( value )
Tests if a value
is a function
.
function beep() {
console.log( 'beep' );
}
var bool = isFunction( beep );
Examples
var isFunction = require( '@stdlib/assert-is-function' );
var bool = isFunction( function foo() {} );
bool = isFunction( 'beep' );
bool = isFunction( 5 );
bool = isFunction( true );
bool = isFunction( null );
bool = isFunction( [] );
bool = isFunction( {} );
Notice
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.
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.