1 # has-value [![NPM version](https://img.shields.io/npm/v/has-value.svg?style=flat)](https://www.npmjs.com/package/has-value) [![NPM monthly downloads](https://img.shields.io/npm/dm/has-value.svg?style=flat)](https://npmjs.org/package/has-value) [![NPM total downloads](https://img.shields.io/npm/dt/has-value.svg?style=flat)](https://npmjs.org/package/has-value) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/has-value.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/has-value)
3 > Returns true if a value exists, false if empty. Works with deeply nested values using object paths.
7 Install with [npm](https://www.npmjs.com/):
10 $ npm install --save has-value
25 Works with property values (supports object-path notation, like `foo.bar`) or a single value:
28 var hasValue = require('has-value');
31 hasValue({foo: 'bar'}, 'foo');
32 hasValue({a: {b: {c: 'foo'}}}, 'a.b.c');
36 hasValue({foo: ''}, 'foo');
41 hasValue({foo: 0}, 'foo');
42 hasValue({foo: 1}, 'foo');
43 hasValue({foo: null}, 'foo');
44 hasValue({foo: {bar: 'a'}}}, 'foo');
45 hasValue({foo: {bar: 'a'}}}, 'foo.bar');
48 hasValue({foo: {}}}, 'foo');
49 hasValue({foo: {bar: {}}}}, 'foo.bar');
50 hasValue({foo: undefined}, 'foo');
56 hasValue([undefined]);
57 hasValue({foo: []}, 'foo');
63 hasValue({foo: ['a']}, 'foo');
66 hasValue(function() {})
67 hasValue(function(foo) {})
68 hasValue({foo: function(foo) {}}, 'foo');
69 hasValue({foo: function() {}}, 'foo');
74 hasValue({foo: true}, 'foo');
75 hasValue({foo: false}, 'foo');
81 To do the opposite and test for empty values, do:
85 return !hasValue.apply(hasValue, arguments);
93 * `zero` always returns true
94 * `array` now recurses, so that an array of empty arrays will return `false`
95 * `null` now returns true
101 * [define-property](https://www.npmjs.com/package/define-property): Define a non-enumerable property on an object. | [homepage](https://github.com/jonschlinkert/define-property "Define a non-enumerable property on an object.")
102 * [get-value](https://www.npmjs.com/package/get-value): Use property paths (`a.b.c`) to get a nested value from an object. | [homepage](https://github.com/jonschlinkert/get-value "Use property paths (`a.b.c`) to get a nested value from an object.")
103 * [set-value](https://www.npmjs.com/package/set-value): Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths. | [homepage](https://github.com/jonschlinkert/set-value "Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.")
104 * [unset-value](https://www.npmjs.com/package/unset-value): Delete nested properties from an object using dot notation. | [homepage](https://github.com/jonschlinkert/unset-value "Delete nested properties from an object using dot notation.")
108 Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
112 | **Commits** | **Contributor** |
114 | 17 | [jonschlinkert](https://github.com/jonschlinkert) |
115 | 2 | [rmharrison](https://github.com/rmharrison) |
119 _(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.)_
121 To generate the readme, run the following command:
124 $ npm install -g verbose/verb#dev verb-generate-readme && verb
129 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:
132 $ npm install && npm test
139 * [github/jonschlinkert](https://github.com/jonschlinkert)
140 * [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
144 Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
145 Released under the [MIT License](LICENSE).
149 _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 19, 2017._