Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
is-callable
Advanced tools
Package description
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.
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
The is-function package is similar to is-callable in that it checks if a given value is a function. However, it may not handle all the cases that is-callable does, such as ES6 classes or callable objects.
Lodash provides a method called isFunction which is part of the larger lodash utility library. It is similar to is-callable but is part of a larger set of utility functions and may not distinguish between all types of callable entities as is-callable does.
Changelog
v1.2.5 - 2022-09-11
5bb4b32
eccheck
command b9bd597
npmignore
to autogenerate an npmignore file 3192d38
tryFunctionObject
even in pre-toStringTag browsers 3076ea2
eslint
, @ljharb/eslint-config
, available-typed-arrays
, object-inspect
, safe-publish-latest
, tape
8986746
auto-changelog
7dda9d0
document.all
da90b2b
c8f847c
eslint
, @ljharb/eslint-config
, aud
, object-inspect
, tape
899ae00
eslint
, @ljharb/eslint-config
, es-value-fixtures
, object-inspect
, tape
344e913
737dce5
680a883
has-tostringtag
approach to behave correctly in the presence of symbol shamsprepublishOnly
script for npm 7+node/install
instead of node/run
; use codecov
actionnyc
on all tests; use tape
runneravailable-typed-arrays
, for-each
, has-symbols
, object-inspect
available-typed-arrays
, eslint
, @ljharb/eslint-config
, aud
, object-inspect
, tape
document.all
is callable (do not use document.all
!)eslint
, @ljharb/eslint-config
, aud
, tape
pull_request_target
eventeslint
eslint
, @ljharb/eslint-config
Reflect.apply
‑based callability detectionaud
on prod depseslint
, @ljharb/eslint-config
, tape
, make-arrow-function
, make-generator-function
; add aud
, safe-publish-latest
, make-async-function
funding
field; add FUNDING.ymleslint
, @ljharb/eslint-config
, semver
, tape
, covert
, rimraf
eccheck
over editorconfig-tools
npx aud
instead of nsp
or npm audit
with hoopsjscs
class
and arrow function detection (#30, #31)node
v5.7
, v4.3
eslint
v2, @ljharb/eslint-config
, jscs
node
v5.3
parallelshell
, run both --es-staging
and stock tests at oncetape
, jscs
, nsp
, eslint
, @ljharb/eslint-config
isNonES6ClassFn
into isES6ClassFn
tape
, eslint
, @ljharb/eslint-config
, jscs
, nsp
, semver
node
v5.1
typeof object
io.js
v3.3
, node
v4.1
eslint
, editorconfig-tools
, nsp
, tape
, semver
, jscs
, covert
, make-arrow-function
Readme
Is this JS value callable? Works with Functions and GeneratorFunctions, despite ES6 @@toStringTag.
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 with
npm install is-callable
Simply clone the repo, npm install
, and run npm test
FAQs
Is this JS value callable? Works with Functions and GeneratorFunctions, despite ES6 @@toStringTag.
The npm package is-callable receives a total of 30,518,161 weekly downloads. As such, is-callable popularity was classified as popular.
We found that is-callable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.