is-callable

中文文档
1.2.7发布于 2022/09/24MITCommonJS零依赖近 30 天下载 4.3亿

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

原始使用文档
文档目录4 节
  1. Supported engines
  2. Example
  3. Install
  4. Tests

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: 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.
    • Note: in v42 - v63, Function.prototype.toString throws on HTML element constructors, or a Proxy to a function
    • Note: in v20 - v35, HTML element constructors are not callable, despite having typeof function.
    • Note: in v19, document.all is not callable.
  • IE: v6 - v11(every integer version
  • Opera: v11.1, v11.5, v11.6, v12.1, 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

版本与发布记录

is-callable 共发布 19 个版本,首次发布于 2015/01/29;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.7latest2022/09/244 年前
1.2.62022/09/154 年前
1.2.52022/09/124 年前
1.2.42021/08/065 年前
1.2.32021/02/015 年前
1.2.22020/09/226 年前

关于 is-callable 的常见问题

is-callable 是什么?

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

如何安装 is-callable?

在项目目录运行 npm install is-callable,或使用 pnpm add / yarn add / bun add。

is-callable 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/is-callable 是否存在。

is-callable 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

is-callable 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 0.4。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

is-callable 可以商用吗?

is-callable 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

is-callable 的下载量有多少?

根据 npm 官方下载统计,is-callable 在 2026/10/05 – 2026/11/03 这 30 天内被下载 433,560,416 次,日均约 14,452,014 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

is-callable 还在维护吗?

最新版本 1.2.7 发布于 2022/09/24(4 年前);至今共发布 19 个版本,其中过去 12 个月发布了 0 个;首次发布于 2015/01/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。