You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
吴治霖
c1d37358dd
|
1 year ago | |
---|---|---|
.. | ||
.github | 1 year ago | |
test | 1 year ago | |
.editorconfig | 1 year ago | |
.eslintrc | 1 year ago | |
.nycrc | 1 year ago | |
CHANGELOG.md | 1 year ago | |
LICENSE | 1 year ago | |
README.md | 1 year ago | |
index.js | 1 year ago | |
package.json | 1 year ago |
README.md
is-callable
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
, butFunction.prototype.toString
hides that progeny and makes them look like functions, soclass
constructors will be reported by this package as callable, when they are not in fact callable.
- Note: Safari 9 has
- 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
, butFunction.prototype.toString
hides that progeny and makes them look like functions, soclass
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.
- Note: v45 - v54 has
- 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