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
38M
increased by0.09%
Maintainers
1
Install size
20.7 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.5 - 2022-09-11

Commits

  • [actions] reuse common workflows 5bb4b32
  • [meta] better eccheck command b9bd597
  • [meta] use npmignore to autogenerate an npmignore file 3192d38
  • [Fix] for HTML constructors, always use tryFunctionObject even in pre-toStringTag browsers 3076ea2
  • [Dev Deps] update eslint, @ljharb/eslint-config, available-typed-arrays, object-inspect, safe-publish-latest, tape 8986746
  • [meta] add auto-changelog 7dda9d0
  • [Fix] properly report document.all da90b2b
  • [actions] update codecov uploader c8f847c
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, object-inspect, tape 899ae00
  • [Dev Deps] update eslint, @ljharb/eslint-config, es-value-fixtures, object-inspect, tape 344e913
  • [meta] remove greenkeeper config 737dce5
  • [meta] npmignore coverage output 680a883
<!-- auto-changelog-above -->

1.2.4 / 2021-08-05

  • [Fix] use has-tostringtag approach to behave correctly in the presence of symbol shams
  • [readme] fix repo URLs
  • [readme] add actions and codecov badges
  • [readme] remove defunct badges
  • [meta] ignore eclint checking coverage output
  • [meta] use prepublishOnly script for npm 7+
  • [actions] use node/install instead of node/run; use codecov action
  • [actions] remove unused workflow file
  • [Tests] run nyc on all tests; use tape runner
  • [Tests] use available-typed-arrays, for-each, has-symbols, object-inspect
  • [Dev Deps] update available-typed-arrays, eslint, @ljharb/eslint-config, aud, object-inspect, tape

1.2.3 / 2021-01-31

  • [Fix] document.all is callable (do not use document.all!)
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, tape
  • [Tests] migrate tests to Github Actions
  • [actions] add "Allow Edits" workflow
  • [actions] switch Automatic Rebase workflow to pull_request_target event

1.2.2 / 2020-09-21

  • [Fix] include actual fix from 579179e
  • [Dev Deps] update eslint

1.2.1 / 2020-09-09

  • [Fix] phantomjs‘ Reflect.apply does not throw properly on a bad array-like
  • [Dev Deps] update eslint, @ljharb/eslint-config
  • [meta] fix eclint error

1.2.0 / 2020-06-02

  • [New] use Reflect.apply‑based callability detection
  • [readme] add install instructions (#55)
  • [meta] only run aud on prod deps
  • [Dev Deps] update eslint, @ljharb/eslint-config, tape, make-arrow-function, make-generator-function; add aud, safe-publish-latest, make-async-function
  • [Tests] add tests for function proxies (#53, #25)

1.1.5 / 2019-12-18

  • [meta] remove unused Makefile and associated utilities
  • [meta] add funding field; add FUNDING.yml
  • [Dev Deps] update eslint, @ljharb/eslint-config, semver, tape, covert, rimraf
  • [Tests] use shared travis configs
  • [Tests] use eccheck over editorconfig-tools
  • [Tests] use npx aud instead of nsp or npm audit with hoops
  • [Tests] remove jscs
  • [actions] add automatic rebasing / merge commit blocking

1.1.4 / 2018-07-02

  • [Fix] improve class and arrow function detection (#30, #31)
  • [Tests] on all latest node minors; improve matrix
  • [Dev Deps] update all dev deps

1.1.3 / 2016-02-27

  • [Fix] ensure “class “ doesn’t screw up “class” detection
  • [Tests] up to node v5.7, v4.3
  • [Dev Deps] update to eslint v2, @ljharb/eslint-config, jscs

1.1.2 / 2016-01-15

  • [Fix] Make sure comments don’t screw up “class” detection (#4)
  • [Tests] up to node v5.3
  • [Tests] Add parallelshell, run both --es-staging and stock tests at once
  • [Dev Deps] update tape, jscs, nsp, eslint, @ljharb/eslint-config
  • [Refactor] convert isNonES6ClassFn into isES6ClassFn

1.1.1 / 2015-11-30

  • [Fix] do not throw when a non-function has a function in its [[Prototype]] (#2)
  • [Dev Deps] update tape, eslint, @ljharb/eslint-config, jscs, nsp, semver
  • [Tests] up to node v5.1
  • [Tests] no longer allow node 0.8 to fail.
  • [Tests] fix npm upgrades in older nodes

1.1.0 / 2015-10-02

  • [Fix] Some browsers report TypedArray constructors as typeof object
  • [New] return false for "class" constructors, when possible.
  • [Tests] up to io.js v3.3, node v4.1
  • [Dev Deps] update eslint, editorconfig-tools, nsp, tape, semver, jscs, covert, make-arrow-function
  • [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG

1.0.4 / 2015-01-30

  • If @@toStringTag is not present, use the old-school Object#toString test.

1.0.3 / 2015-01-29

  • Add tests to ensure arrow functions are callable.
  • Refactor to aid optimization of non-try/catch code.

1.0.2 / 2015-01-29

  • Fix broken package.json

1.0.1 / 2015-01-29

  • Add early exit for typeof not "function"

1.0.0 / 2015-01-29

  • Initial release.

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.

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 06 Aug 2021

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