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