UNPKG

2.25 kBMarkdownView Raw
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
12Is this JS value callable? Works with Functions and GeneratorFunctions, despite ES6 @@toStringTag.
13
14## Example
15
16```js
17var isCallable = require('is-callable');
18var assert = require('assert');
19
20assert.notOk(isCallable(undefined));
21assert.notOk(isCallable(null));
22assert.notOk(isCallable(false));
23assert.notOk(isCallable(true));
24assert.notOk(isCallable([]));
25assert.notOk(isCallable({}));
26assert.notOk(isCallable(/a/g));
27assert.notOk(isCallable(new RegExp('a', 'g')));
28assert.notOk(isCallable(new Date()));
29assert.notOk(isCallable(42));
30assert.notOk(isCallable(NaN));
31assert.notOk(isCallable(Infinity));
32assert.notOk(isCallable(new Number(42)));
33assert.notOk(isCallable('foo'));
34assert.notOk(isCallable(Object('foo')));
35
36assert.ok(isCallable(function () {}));
37assert.ok(isCallable(function* () {}));
38assert.ok(isCallable(x => x * x));
39```
40
41## Install
42
43Install with
44
45```
46npm install is-callable
47```
48
49## Tests
50
51Simply clone the repo, `npm install`, and run `npm test`
52
53[1]: https://npmjs.org/package/is-callable
54[2]: https://versionbadg.es/inspect-js/is-callable.svg
55[5]: https://david-dm.org/inspect-js/is-callable.svg
56[6]: https://david-dm.org/inspect-js/is-callable
57[7]: https://david-dm.org/inspect-js/is-callable/dev-status.svg
58[8]: https://david-dm.org/inspect-js/is-callable#info=devDependencies
59[11]: https://nodei.co/npm/is-callable.png?downloads=true&stars=true
60[license-image]: https://img.shields.io/npm/l/is-callable.svg
61[license-url]: LICENSE
62[downloads-image]: https://img.shields.io/npm/dm/is-callable.svg
63[downloads-url]: https://npm-stat.com/charts.html?package=is-callable
64[codecov-image]: https://codecov.io/gh/inspect-js/is-callable/branch/main/graphs/badge.svg
65[codecov-url]: https://app.codecov.io/gh/inspect-js/is-callable/
66[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-callable
67[actions-url]: https://github.com/inspect-js/is-callable/actions