caoge c760052ff9 机车状态修改 | 8 months ago | |
---|---|---|
.. | ||
.github | 8 months ago | |
test | 8 months ago | |
.editorconfig | 8 months ago | |
.eslintrc | 8 months ago | |
.nycrc | 8 months ago | |
CHANGELOG.md | 8 months ago | |
LICENSE | 8 months ago | |
README.md | 8 months ago | |
index.js | 8 months ago | |
package.json | 8 months ago |
Is this JS value callable? Works with Functions and GeneratorFunctions, despite ES6 @@toStringTag.
Automatically tested in every minor version of node.
Manually tested in:
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.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.Function.prototype.toString
throws on HTML element constructors, or a Proxy to a functionfunction
.document.all
is not callable.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