source: trip-planner-front/node_modules/has-value/README.md@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.4 KB
Line 
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)
2
3> Returns true if a value exists, false if empty. Works with deeply nested values using object paths.
4
5## Install
6
7Install with [npm](https://www.npmjs.com/):
8
9```sh
10$ npm install --save has-value
11```
12
13**Works for:**
14
15* booleans
16* functions
17* numbers
18* strings
19* nulls
20* object
21* arrays
22
23## Usage
24
25Works with property values (supports object-path notation, like `foo.bar`) or a single value:
26
27```js
28var hasValue = require('has-value');
29
30hasValue('foo');
31hasValue({foo: 'bar'}, 'foo');
32hasValue({a: {b: {c: 'foo'}}}, 'a.b.c');
33//=> true
34
35hasValue('');
36hasValue({foo: ''}, 'foo');
37//=> false
38
39hasValue(0);
40hasValue(1);
41hasValue({foo: 0}, 'foo');
42hasValue({foo: 1}, 'foo');
43hasValue({foo: null}, 'foo');
44hasValue({foo: {bar: 'a'}}}, 'foo');
45hasValue({foo: {bar: 'a'}}}, 'foo.bar');
46//=> true
47
48hasValue({foo: {}}}, 'foo');
49hasValue({foo: {bar: {}}}}, 'foo.bar');
50hasValue({foo: undefined}, 'foo');
51//=> false
52
53hasValue([]);
54hasValue([[]]);
55hasValue([[], []]);
56hasValue([undefined]);
57hasValue({foo: []}, 'foo');
58//=> false
59
60hasValue([0]);
61hasValue([null]);
62hasValue(['foo']);
63hasValue({foo: ['a']}, 'foo');
64//=> true
65
66hasValue(function() {})
67hasValue(function(foo) {})
68hasValue({foo: function(foo) {}}, 'foo');
69hasValue({foo: function() {}}, 'foo');
70//=> true
71
72hasValue(true);
73hasValue(false);
74hasValue({foo: true}, 'foo');
75hasValue({foo: false}, 'foo');
76//=> true
77```
78
79## isEmpty
80
81To do the opposite and test for empty values, do:
82
83```js
84function isEmpty(o) {
85 return !hasValue.apply(hasValue, arguments);
86}
87```
88
89## Release history
90
91### v1.0.0
92
93* `zero` always returns true
94* `array` now recurses, so that an array of empty arrays will return `false`
95* `null` now returns true
96
97## About
98
99### Related projects
100
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.")
105
106### Contributing
107
108Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
109
110### Contributors
111
112| **Commits** | **Contributor** |
113| --- | --- |
114| 17 | [jonschlinkert](https://github.com/jonschlinkert) |
115| 2 | [rmharrison](https://github.com/rmharrison) |
116
117### Building docs
118
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.)_
120
121To generate the readme, run the following command:
122
123```sh
124$ npm install -g verbose/verb#dev verb-generate-readme && verb
125```
126
127### Running tests
128
129Running 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:
130
131```sh
132$ npm install && npm test
133```
134
135### Author
136
137**Jon Schlinkert**
138
139* [github/jonschlinkert](https://github.com/jonschlinkert)
140* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
141
142### License
143
144Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
145Released under the [MIT License](LICENSE).
146
147***
148
149_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 19, 2017._
Note: See TracBrowser for help on using the repository browser.