85e1f89b91d98948328412631c6c1a78d6a354899958f1eb84223fc6786704a4d48820df098b9e9fc5708b4a1394a8c217ae4e93d8147faace9e3625b1a937 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # defined <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
  2. [![github actions][actions-image]][actions-url]
  3. [![coverage][codecov-image]][codecov-url]
  4. [![License][license-image]][license-url]
  5. [![Downloads][downloads-image]][downloads-url]
  6. [![npm badge][npm-badge-png]][package-url]
  7. return the first argument that is `!== undefined`
  8. Most of the time when I chain together `||`s, I actually just want the first
  9. item that is not `undefined`, not the first non-falsy item.
  10. This module is like the defined-or (`//`) operator in perl 5.10+.
  11. # example
  12. ``` js
  13. var defined = require('defined');
  14. var opts = { y : false, w : 4 };
  15. var x = defined(opts.x, opts.y, opts.w, 100);
  16. console.log(x);
  17. ```
  18. ```
  19. $ node example/defined.js
  20. false
  21. ```
  22. The return value is `false` because `false` is the first item that is
  23. `!== undefined`.
  24. # methods
  25. ``` js
  26. var defined = require('defined')
  27. ```
  28. ## var x = defined(a, b, c...)
  29. Return the first item in the argument list `a, b, c...` that is `!== undefined`.
  30. If all the items are `=== undefined`, return undefined.
  31. # install
  32. With [npm](https://npmjs.org) do:
  33. ```
  34. npm install defined
  35. ```
  36. # license
  37. MIT
  38. [package-url]: https://npmjs.org/package/defined
  39. [npm-version-svg]: https://versionbadg.es/inspect-js/defined.svg
  40. [deps-svg]: https://david-dm.org/inspect-js/defined.svg
  41. [deps-url]: https://david-dm.org/inspect-js/defined
  42. [dev-deps-svg]: https://david-dm.org/inspect-js/defined/dev-status.svg
  43. [dev-deps-url]: https://david-dm.org/inspect-js/defined#info=devDependencies
  44. [npm-badge-png]: https://nodei.co/npm/defined.png?downloads=true&stars=true
  45. [license-image]: https://img.shields.io/npm/l/defined.svg
  46. [license-url]: LICENSE
  47. [downloads-image]: https://img.shields.io/npm/dm/defined.svg
  48. [downloads-url]: https://npm-stat.com/charts.html?package=defined
  49. [codecov-image]: https://codecov.io/gh/inspect-js/defined/branch/main/graphs/badge.svg
  50. [codecov-url]: https://app.codecov.io/gh/inspect-js/defined/
  51. [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/defined
  52. [actions-url]: https://github.com/inspect-js/defined/actions