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.

README.md 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # has-values [![NPM version](https://img.shields.io/npm/v/has-values.svg?style=flat)](https://www.npmjs.com/package/has-values) [![NPM monthly downloads](https://img.shields.io/npm/dm/has-values.svg?style=flat)](https://npmjs.org/package/has-values) [![NPM total downloads](https://img.shields.io/npm/dt/has-values.svg?style=flat)](https://npmjs.org/package/has-values) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/has-values.svg?style=flat&label=Travis)](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 --save has-values
  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({a: 'a'}});
  20. //=> true
  21. hasValue({});
  22. hasValue({foo: undefined});
  23. //=> false
  24. hasValue({foo: null});
  25. //=> true
  26. hasValue(['a']);
  27. //=> true
  28. hasValue([]);
  29. hasValue([[], []]);
  30. hasValue([[[]]]);
  31. //=> false
  32. hasValue(['foo']);
  33. hasValue([0]);
  34. //=> true
  35. hasValue(function(foo) {});
  36. //=> true
  37. hasValue(function() {});
  38. //=> true
  39. hasValue(true);
  40. //=> true
  41. hasValue(false);
  42. //=> true
  43. ```
  44. ## isEmpty
  45. To test for empty values, do:
  46. ```js
  47. function isEmpty(o, isZero) {
  48. return !hasValue(o, isZero);
  49. }
  50. ```
  51. ## Release history
  52. ### v1.0.0
  53. * `zero` always returns true
  54. * `array` now recurses, so that an array of empty arrays will return `false`
  55. * `null` now returns true
  56. ## About
  57. ### Related projects
  58. * [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://github.com/jonschlinkert/has-value) | [homepage](https://github.com/jonschlinkert/has-value "Returns true if a value exists, false if empty. Works with deeply nested values using object paths.")
  59. * [is-number](https://www.npmjs.com/package/is-number): Returns true if the value is a number. comprehensive tests. | [homepage](https://github.com/jonschlinkert/is-number "Returns true if the value is a number. comprehensive tests.")
  60. * [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 "Returns true if an object was created by the `Object` constructor.")
  61. * [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 "Returns true if the value is an object and not an array or null.")
  62. * [kind-of](https://www.npmjs.com/package/kind-of): Get the native type of a value. | [homepage](https://github.com/jonschlinkert/kind-of "Get the native type of a value.")
  63. ### Contributing
  64. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
  65. ### Building docs
  66. _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
  67. To generate the readme, run the following command:
  68. ```sh
  69. $ npm install -g verbose/verb#dev verb-generate-readme && verb
  70. ```
  71. ### Running tests
  72. Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
  73. ```sh
  74. $ npm install && npm test
  75. ```
  76. ### Author
  77. **Jon Schlinkert**
  78. * [github/jonschlinkert](https://github.com/jonschlinkert)
  79. * [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
  80. ### License
  81. Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
  82. Released under the [MIT License](LICENSE).
  83. ***
  84. _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 19, 2017._