[d565449] | 1 | # is-callable <sup>[![Version Badge][2]][1]</sup>
|
---|
| 2 |
|
---|
| 3 | [![github actions][actions-image]][actions-url]
|
---|
| 4 | [![coverage][codecov-image]][codecov-url]
|
---|
| 5 | [![dependency status][5]][6]
|
---|
| 6 | [![dev dependency status][7]][8]
|
---|
| 7 | [![License][license-image]][license-url]
|
---|
| 8 | [![Downloads][downloads-image]][downloads-url]
|
---|
| 9 |
|
---|
| 10 | [![npm badge][11]][1]
|
---|
| 11 |
|
---|
| 12 | Is this JS value callable? Works with Functions and GeneratorFunctions, despite ES6 @@toStringTag.
|
---|
| 13 |
|
---|
| 14 | ## Supported engines
|
---|
| 15 | Automatically tested in every minor version of node.
|
---|
| 16 |
|
---|
| 17 | Manually tested in:
|
---|
| 18 | - Safari: v4 - v15 <sub>(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)</sub>
|
---|
| 19 | - 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.
|
---|
| 20 | - Chrome: v15 - v81, v83 - v106<sub>(every integer version)</sub>
|
---|
| 21 | - Note: This includes Edge v80+ and Opera v15+, which matches Chrome
|
---|
| 22 | - Firefox: v3, v3.6, v4 - v105 <sub>(every integer version)</sub>
|
---|
| 23 | - 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.
|
---|
| 24 | - Note: in v42 - v63, `Function.prototype.toString` throws on HTML element constructors, or a Proxy to a function
|
---|
| 25 | - Note: in v20 - v35, HTML element constructors are not callable, despite having typeof `function`.
|
---|
| 26 | - Note: in v19, `document.all` is not callable.
|
---|
| 27 | - IE: v6 - v11<sub>(every integer version</sub>
|
---|
| 28 | - Opera: v11.1, v11.5, v11.6, v12.1, v12.14, v12.15, v12.16, v15+ <sub>v15+ matches Chrome</sub>
|
---|
| 29 |
|
---|
| 30 | ## Example
|
---|
| 31 |
|
---|
| 32 | ```js
|
---|
| 33 | var isCallable = require('is-callable');
|
---|
| 34 | var assert = require('assert');
|
---|
| 35 |
|
---|
| 36 | assert.notOk(isCallable(undefined));
|
---|
| 37 | assert.notOk(isCallable(null));
|
---|
| 38 | assert.notOk(isCallable(false));
|
---|
| 39 | assert.notOk(isCallable(true));
|
---|
| 40 | assert.notOk(isCallable([]));
|
---|
| 41 | assert.notOk(isCallable({}));
|
---|
| 42 | assert.notOk(isCallable(/a/g));
|
---|
| 43 | assert.notOk(isCallable(new RegExp('a', 'g')));
|
---|
| 44 | assert.notOk(isCallable(new Date()));
|
---|
| 45 | assert.notOk(isCallable(42));
|
---|
| 46 | assert.notOk(isCallable(NaN));
|
---|
| 47 | assert.notOk(isCallable(Infinity));
|
---|
| 48 | assert.notOk(isCallable(new Number(42)));
|
---|
| 49 | assert.notOk(isCallable('foo'));
|
---|
| 50 | assert.notOk(isCallable(Object('foo')));
|
---|
| 51 |
|
---|
| 52 | assert.ok(isCallable(function () {}));
|
---|
| 53 | assert.ok(isCallable(function* () {}));
|
---|
| 54 | assert.ok(isCallable(x => x * x));
|
---|
| 55 | ```
|
---|
| 56 |
|
---|
| 57 | ## Install
|
---|
| 58 |
|
---|
| 59 | Install with
|
---|
| 60 |
|
---|
| 61 | ```
|
---|
| 62 | npm install is-callable
|
---|
| 63 | ```
|
---|
| 64 |
|
---|
| 65 | ## Tests
|
---|
| 66 |
|
---|
| 67 | Simply clone the repo, `npm install`, and run `npm test`
|
---|
| 68 |
|
---|
| 69 | [1]: https://npmjs.org/package/is-callable
|
---|
| 70 | [2]: https://versionbadg.es/inspect-js/is-callable.svg
|
---|
| 71 | [5]: https://david-dm.org/inspect-js/is-callable.svg
|
---|
| 72 | [6]: https://david-dm.org/inspect-js/is-callable
|
---|
| 73 | [7]: https://david-dm.org/inspect-js/is-callable/dev-status.svg
|
---|
| 74 | [8]: https://david-dm.org/inspect-js/is-callable#info=devDependencies
|
---|
| 75 | [11]: https://nodei.co/npm/is-callable.png?downloads=true&stars=true
|
---|
| 76 | [license-image]: https://img.shields.io/npm/l/is-callable.svg
|
---|
| 77 | [license-url]: LICENSE
|
---|
| 78 | [downloads-image]: https://img.shields.io/npm/dm/is-callable.svg
|
---|
| 79 | [downloads-url]: https://npm-stat.com/charts.html?package=is-callable
|
---|
| 80 | [codecov-image]: https://codecov.io/gh/inspect-js/is-callable/branch/main/graphs/badge.svg
|
---|
| 81 | [codecov-url]: https://app.codecov.io/gh/inspect-js/is-callable/
|
---|
| 82 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-callable
|
---|
| 83 | [actions-url]: https://github.com/inspect-js/is-callable/actions
|
---|