c1388c953ed2e637ac1c5fddc2404cbc3cc086e9ce302323a0b736e2bd5c623a1614794c9fc6e8f3d36936c58716b938fe36bf0dcf6aa9fb26be1581893644 3.5 KB

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