Tim van der Lippe | 16aca39 | 2020-11-13 11:37:13 | [diff] [blame] | 1 | # is-callable <sup>[![Version Badge][2]][1]</sup> |
| 2 | |
Tim van der Lippe | bc3a0b7 | 2021-11-08 15:22:37 | [diff] [blame] | 3 | [![github actions][actions-image]][actions-url] |
| 4 | [![coverage][codecov-image]][codecov-url] |
Tim van der Lippe | 16aca39 | 2020-11-13 11:37:13 | [diff] [blame] | 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 | |
Tim van der Lippe | 16aca39 | 2020-11-13 11:37:13 | [diff] [blame] | 12 | Is this JS value callable? Works with Functions and GeneratorFunctions, despite ES6 @@toStringTag. |
| 13 | |
| 14 | ## Example |
| 15 | |
| 16 | ```js |
| 17 | var isCallable = require('is-callable'); |
| 18 | var assert = require('assert'); |
| 19 | |
| 20 | assert.notOk(isCallable(undefined)); |
| 21 | assert.notOk(isCallable(null)); |
| 22 | assert.notOk(isCallable(false)); |
| 23 | assert.notOk(isCallable(true)); |
| 24 | assert.notOk(isCallable([])); |
| 25 | assert.notOk(isCallable({})); |
| 26 | assert.notOk(isCallable(/a/g)); |
| 27 | assert.notOk(isCallable(new RegExp('a', 'g'))); |
| 28 | assert.notOk(isCallable(new Date())); |
| 29 | assert.notOk(isCallable(42)); |
| 30 | assert.notOk(isCallable(NaN)); |
| 31 | assert.notOk(isCallable(Infinity)); |
| 32 | assert.notOk(isCallable(new Number(42))); |
| 33 | assert.notOk(isCallable('foo')); |
| 34 | assert.notOk(isCallable(Object('foo'))); |
| 35 | |
| 36 | assert.ok(isCallable(function () {})); |
| 37 | assert.ok(isCallable(function* () {})); |
| 38 | assert.ok(isCallable(x => x * x)); |
| 39 | ``` |
| 40 | |
| 41 | ## Install |
| 42 | |
| 43 | Install with |
| 44 | |
| 45 | ``` |
| 46 | npm install is-callable |
| 47 | ``` |
| 48 | |
| 49 | ## Tests |
| 50 | |
| 51 | Simply clone the repo, `npm install`, and run `npm test` |
| 52 | |
| 53 | [1]: https://npmjs.org/package/is-callable |
Tim van der Lippe | bc3a0b7 | 2021-11-08 15:22:37 | [diff] [blame] | 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 |
Tim van der Lippe | 16aca39 | 2020-11-13 11:37:13 | [diff] [blame] | 59 | [11]: https://nodei.co/npm/is-callable.png?downloads=true&stars=true |
Tim van der Lippe | bc3a0b7 | 2021-11-08 15:22:37 | [diff] [blame] | 60 | [license-image]: https://img.shields.io/npm/l/is-callable.svg |
Tim van der Lippe | 16aca39 | 2020-11-13 11:37:13 | [diff] [blame] | 61 | [license-url]: LICENSE |
Tim van der Lippe | bc3a0b7 | 2021-11-08 15:22:37 | [diff] [blame] | 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 |