07bb2a4652911f31993f4c21f22fdf49eee23080954281f9894624a1c70956d4d298585dce3fc4ee312ee321e916a77c010519ee020a87ce77cb4a42e3e7ac 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # has-values [![NPM version](https://img.shields.io/npm/v/has-values.svg?style=flat)](https://www.npmjs.com/package/has-values) [![NPM downloads](https://img.shields.io/npm/dm/has-values.svg?style=flat)](https://npmjs.org/package/has-values) [![Build Status](https://img.shields.io/travis/jonschlinkert/has-values.svg?style=flat)](https://travis-ci.org/jonschlinkert/has-values)
  2. > Returns true if any values exist, false if empty. Works for booleans, functions, numbers, strings, nulls, objects and arrays.
  3. ## Install
  4. Install with [npm](https://www.npmjs.com/):
  5. ```sh
  6. $ npm install has-values --save
  7. ```
  8. ## Usage
  9. ```js
  10. var hasValue = require('has-values');
  11. hasValue('a');
  12. //=> true
  13. hasValue('');
  14. //=> false
  15. hasValue(1);
  16. //=> true
  17. hasValue(0);
  18. //=> false
  19. hasValue(0, true); // treat zero as a value
  20. //=> true
  21. hasValue({a: 'a'}});
  22. //=> true
  23. hasValue({}});
  24. //=> false
  25. hasValue(['a']);
  26. //=> true
  27. hasValue([]);
  28. //=> false
  29. hasValue(function(foo) {}); // function length/arity
  30. //=> true
  31. hasValue(function() {});
  32. //=> false
  33. hasValue(true);
  34. hasValue(false);
  35. //=> true
  36. ```
  37. ## isEmpty
  38. To test for empty values, do:
  39. ```js
  40. function isEmpty(o, isZero) {
  41. return !hasValue(o, isZero);
  42. }
  43. ```
  44. ## Related projects
  45. You might also be interested in these projects:
  46. * [has-value](https://www.npmjs.com/package/has-value): Returns true if a value exists, false if empty. Works with deeply nested values using… [more](https://www.npmjs.com/package/has-value) | [homepage](https://github.com/jonschlinkert/has-value)
  47. * [is-plain-object](https://www.npmjs.com/package/is-plain-object): Returns true if an object was created by the `Object` constructor. | [homepage](https://github.com/jonschlinkert/is-plain-object)
  48. * [isobject](https://www.npmjs.com/package/isobject): Returns true if the value is an object and not an array or null. | [homepage](https://github.com/jonschlinkert/isobject)
  49. ## Contributing
  50. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/has-values/issues/new).
  51. ## Building docs
  52. Generate readme and API documentation with [verb](https://github.com/verbose/verb):
  53. ```sh
  54. $ npm install verb && npm run docs
  55. ```
  56. Or, if [verb](https://github.com/verbose/verb) is installed globally:
  57. ```sh
  58. $ verb
  59. ```
  60. ## Running tests
  61. Install dev dependencies:
  62. ```sh
  63. $ npm install -d && npm test
  64. ```
  65. ## Author
  66. **Jon Schlinkert**
  67. * [github/jonschlinkert](https://github.com/jonschlinkert)
  68. * [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
  69. ## License
  70. Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
  71. Released under the [MIT license](https://github.com/jonschlinkert/has-values/blob/master/LICENSE).
  72. ***
  73. _This file was generated by [verb](https://github.com/verbose/verb), v, on March 27, 2016._