Socket
Socket
Sign inDemoInstall

is-function

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    is-function

is that thing a function? Use this module to find out


Version published
Weekly downloads
3.8M
increased by2.98%
Maintainers
1
Install size
5.07 kB
Created
Weekly downloads
 

Package description

What is is-function?

The is-function npm package is a simple utility used for checking if a given value is a function. It is particularly useful in JavaScript environments where determining the type of an object can sometimes be less straightforward due to the dynamic nature of the language. This package provides a reliable way to ensure that a variable holds a function before attempting to invoke it, thus preventing runtime errors in code.

What are is-function's main functionalities?

Function Type Checking

This feature allows developers to check if a variable is a function. It supports various types of functions including regular functions, async functions, and arrow functions. It returns true if the variable is a function and false otherwise. This is particularly useful for validating callbacks or any variable that is expected to be a function before invoking it.

const isFunction = require('is-function');

console.log(isFunction(function() {})); // true
console.log(isFunction(async () => {})); // true
console.log(isFunction(() => {})); // true
console.log(isFunction(class MyClass {})); // false
console.log(isFunction({})); // false

Other packages similar to is-function

Readme

Source

is-function

browser support

Is that thing a function? Use this module to find out.

API

module.exports = function isFunction(fn) -> Boolean

Return true if fn is a function, otherwise false.

Why not typeof fn === 'function'

Because certain old browsers misreport the type of RegExp objects as functions.

Acknowledgements

I stole this from https://github.com/ljharb/object-keys

License

MIT

Keywords

FAQs

Last updated on 22 Apr 2020

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc