Socket
Socket
Sign inDemoInstall

is-callable

Package Overview
Dependencies
0
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    is-callable

Is this JS value callable? Works with Functions and GeneratorFunctions, despite ES6 @@toStringTag.


Version published
Weekly downloads
37M
decreased by-1.01%
Maintainers
1
Install size
26.1 kB
Created
Weekly downloads
 

Package description

What is is-callable?

The is-callable npm package is used to determine if a value is callable, meaning it can be called as a function. This is useful for type-checking in JavaScript where the typeof operator can be insufficient for certain cases, such as distinguishing between callable and non-callable objects.

What are is-callable's main functionalities?

Check if a value is callable

This feature allows you to check if various types of values are callable, including regular functions, async functions, arrow functions, and classes. It also correctly identifies non-callable objects like regex literals and plain objects.

const isCallable = require('is-callable');

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

Other packages similar to is-callable

Changelog

Source

v1.2.6 - 2022-09-14

Commits

  • [Fix] work for document.all in Firefox 3 and IE 6-8 015132a
  • [Test] skip function toString check for nullish values 8698116
  • [readme] add "supported engines" section 0442207
  • [Tests] skip one of the fixture objects in FF 3.6 a501141
  • [Tests] allow class constructor tests to fail in FF v45 - v54, which has undetectable classes b12e4a4
  • [Fix] Safari 4: regexes should not be considered callable 4b732ff
  • [Fix] properly recognize document.all in Safari 4 3193735

Readme

Source

is-callable Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

Is this JS value callable? Works with Functions and GeneratorFunctions, despite ES6 @@toStringTag.

Supported engines

Automatically tested in every minor version of node.

Manually tested in:

  • Safari: v4 - v15 (4, 5, 5.1, 6.0.5, 6.2, 7.1, 8, 9.1.3, 10.1.2, 11.1.2, 12.1, 13.1.2, 14.1.2, 15.3, 15.6.1)
    • Note: Safari 9 has class, but Function.prototype.toString hides that progeny and makes them look like functions, so class constructors will be reported by this package as callable, when they are not in fact callable.
  • Chrome: v15 - v81, v83 - v106(every integer version)
    • Note: This includes Edge v80+ and Opera v15+, which matches Chrome
  • Firefox: v3, v3.6, v4 - v105 (every integer version)
    • Note: Firefox v45 - v54 has class, but Function.prototype.toString hides that progeny and makes them look like functions, so class constructors will be reported by this package as callable, when they are not in fact callable.
  • IE: v6 - v11(every integer version
  • Opera: v11.1, v11.5, v11.6, 12?, v12.1, v12.12?, v12.14, v12.15, v12.16, v15+ v15+ matches Chrome

Example

var isCallable = require('is-callable');
var assert = require('assert');

assert.notOk(isCallable(undefined));
assert.notOk(isCallable(null));
assert.notOk(isCallable(false));
assert.notOk(isCallable(true));
assert.notOk(isCallable([]));
assert.notOk(isCallable({}));
assert.notOk(isCallable(/a/g));
assert.notOk(isCallable(new RegExp('a', 'g')));
assert.notOk(isCallable(new Date()));
assert.notOk(isCallable(42));
assert.notOk(isCallable(NaN));
assert.notOk(isCallable(Infinity));
assert.notOk(isCallable(new Number(42)));
assert.notOk(isCallable('foo'));
assert.notOk(isCallable(Object('foo')));

assert.ok(isCallable(function () {}));
assert.ok(isCallable(function* () {}));
assert.ok(isCallable(x => x * x));

Install

Install with

npm install is-callable

Tests

Simply clone the repo, npm install, and run npm test

Keywords

FAQs

Last updated on 15 Sep 2022

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