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.

59 lines
1.9 KiB

4 years ago
  1. # is-callable <sup>[![Version Badge][2]][1]</sup>
  2. [![Build Status][3]][4]
  3. [![dependency status][5]][6]
  4. [![dev dependency status][7]][8]
  5. [![License][license-image]][license-url]
  6. [![Downloads][downloads-image]][downloads-url]
  7. [![npm badge][11]][1]
  8. [![browser support][9]][10]
  9. Is this JS value callable? Works with Functions and GeneratorFunctions, despite ES6 @@toStringTag.
  10. ## Example
  11. ```js
  12. var isCallable = require('is-callable');
  13. var assert = require('assert');
  14. assert.notOk(isCallable(undefined));
  15. assert.notOk(isCallable(null));
  16. assert.notOk(isCallable(false));
  17. assert.notOk(isCallable(true));
  18. assert.notOk(isCallable([]));
  19. assert.notOk(isCallable({}));
  20. assert.notOk(isCallable(/a/g));
  21. assert.notOk(isCallable(new RegExp('a', 'g')));
  22. assert.notOk(isCallable(new Date()));
  23. assert.notOk(isCallable(42));
  24. assert.notOk(isCallable(NaN));
  25. assert.notOk(isCallable(Infinity));
  26. assert.notOk(isCallable(new Number(42)));
  27. assert.notOk(isCallable('foo'));
  28. assert.notOk(isCallable(Object('foo')));
  29. assert.ok(isCallable(function () {}));
  30. assert.ok(isCallable(function* () {}));
  31. assert.ok(isCallable(x => x * x));
  32. ```
  33. ## Tests
  34. Simply clone the repo, `npm install`, and run `npm test`
  35. [1]: https://npmjs.org/package/is-callable
  36. [2]: http://versionbadg.es/ljharb/is-callable.svg
  37. [3]: https://travis-ci.org/ljharb/is-callable.svg
  38. [4]: https://travis-ci.org/ljharb/is-callable
  39. [5]: https://david-dm.org/ljharb/is-callable.svg
  40. [6]: https://david-dm.org/ljharb/is-callable
  41. [7]: https://david-dm.org/ljharb/is-callable/dev-status.svg
  42. [8]: https://david-dm.org/ljharb/is-callable#info=devDependencies
  43. [9]: https://ci.testling.com/ljharb/is-callable.png
  44. [10]: https://ci.testling.com/ljharb/is-callable
  45. [11]: https://nodei.co/npm/is-callable.png?downloads=true&stars=true
  46. [license-image]: http://img.shields.io/npm/l/is-callable.svg
  47. [license-url]: LICENSE
  48. [downloads-image]: http://img.shields.io/npm/dm/is-callable.svg
  49. [downloads-url]: http://npm-stat.com/charts.html?package=is-callable