Bakhtina Sofya b84cb877be 1st comm | 2 weeks ago | |
---|---|---|
.. | ||
.github | 2 weeks ago | |
test | 2 weeks ago | |
.editorconfig | 2 weeks ago | |
.eslintrc | 2 weeks ago | |
.nycrc | 2 weeks ago | |
CHANGELOG.md | 2 weeks ago | |
LICENSE | 2 weeks ago | |
README.md | 2 weeks ago | |
index.js | 2 weeks ago | |
package.json | 2 weeks 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