Gathering detailed insights and metrics for has-value
Gathering detailed insights and metrics for has-value
Gathering detailed insights and metrics for has-value
Gathering detailed insights and metrics for has-value
has-values
Returns true if any values exist, false if empty. Works for booleans, functions, numbers, strings, nulls, objects and arrays.
union-value
Set an array of unique values as the property of an object. Supports setting deeply nested properties using using object-paths/dot notation.
set-value
Set nested properties on an object using dot notation.
is-accessor-descriptor
Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
Returns true if a value exists, false if empty. Works with deeply nested values using object paths.
npm install has-value
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.2
Supply Chain
97
Quality
74.9
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
8,703,990,919
Last Day
3,772,031
Last Week
19,697,522
Last Month
71,441,679
Last Year
1,192,135,632
26 Stars
38 Commits
6 Forks
4 Watching
1 Branches
4 Contributors
Minified
Minified + Gzipped
Latest Version
2.0.2
Package Id
has-value@2.0.2
Size
3.57 kB
NPM Version
5.6.0
Node Version
9.7.1
Publised On
03 Mar 2018
Cumulative downloads
Total Downloads
Last day
-2.9%
3,772,031
Compared to previous day
Last week
0.4%
19,697,522
Compared to previous week
Last month
-24.9%
71,441,679
Compared to previous month
Last year
-23.1%
1,192,135,632
Compared to previous year
2
2
Returns true if a value exists, false if empty. Works with deeply nested values using object paths.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install with npm:
1$ npm install --save has-value
Breaking changes in v2.0! See the release history for details.
1const has = require('has-value'); 2 3console.log(has()) //=> true 4console.log(has('foo')) //=> true
Works for:
isEmpty
To do the opposite and test for empty values, do:
1const isEmpty = (...args) => !has(...args);
1console.log(has({ foo: { bar: ['a'] } }, 'foo.bar')); //=> true 2console.log(has({ foo: { bar: [0] } }, 'foo.bar')); //=> true 3console.log(has({ foo: { bar: [[[]]] } }, 'foo.bar')); //=> false 4console.log(has({ foo: { bar: [[], []] } }, 'foo.bar')); //=> false 5console.log(has({ foo: { bar: [] } }, 'foo.bar')); //=> false
1console.log(has({ foo: { bar: true } }, 'foo.bar')); //=> true 2console.log(has({ foo: { bar: false } }, 'foo.bar')); //=> true
1console.log(has({ foo: { bar: new Buffer() } }, 'foo.bar')); //=> false 2console.log(has({ foo: { bar: new Buffer('foo') } }, 'foo.bar')); //=> true
Dates are always true.
1console.log(has({ foo: { bar: new Date() } }, 'foo.bar')); //=> true
Returns false
if err.message
is an empty string.
1console.log(has({ foo: { bar: new Error() } }, 'foo.bar')); //=> false 2console.log(has({ foo: { bar: new Error('foo') } }, 'foo.bar')); //=> true
Functions are always true.
1console.log(has({ foo: { bar: function(foo) {} } }, 'foo.bar')); //=> true 2console.log(has({ foo: { bar: function() {} } }, 'foo.bar')); //=> true
1console.log(has({ foo: { bar: new Map() } }, 'foo.bar')); //=> false 2console.log(has({ foo: { bar: new Map([['foo', 'bar']]) } }, 'foo.bar')); //=> true
null
is always true, as it's assumed that this is a user-defined value, versus undefined
which is not.
1console.log(has({ foo: { bar: null } }, 'foo.bar')); //=> true
1console.log(has({ foo: { bar: {} } }, 'foo.bar')); //=> false 2console.log(has({ foo: { bar: { a: 'a' }} } }, 'foo.bar')); //=> true 3console.log(has({ foo: { bar: { foo: undefined } } }, 'foo.bar')); //=> false 4console.log(has({ foo: { bar: { foo: null } } }, 'foo.bar')); //=> true
1console.log(has({ foo: { bar: 1 } }, 'foo.bar')); //=> true 2console.log(has({ foo: { bar: 0 } }, 'foo.bar')); //=> true
1console.log(has({ foo: { bar: new RegExp() } }, 'foo.bar')); //=> false 2console.log(has({ foo: { bar: new RegExp('foo') } }, 'foo.bar')); //=> true
1console.log(has({ foo: { bar: new Set() } }, 'foo.bar')); //=> false 2console.log(has({ foo: { bar: new Set(['foo', 'bar']) } }, 'foo.bar')); //=> true
1console.log(has({ foo: { bar: 'a' } }, 'foo.bar')); //=> true 2console.log(has({ foo: { bar: '' } }, 'foo.bar')); //=> false
1console.log(has({ foo: { bar: } }, 'foo.bar')); //=> false 2console.log(has({ foo: { bar: void 0 } }, 'foo.bar')); //=> false 3console.log(has({ foo: { bar: undefined } }, 'foo.bar')); //=> false
Breaking changes
zero
always returns truearray
now recurses, so that an array of empty arrays will return false
null
now returns truePull requests and stars are always welcome. For bugs and feature requests, please create an issue.
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:
1$ npm install && npm test
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
1$ npm install -g verbose/verb#dev verb-generate-readme && verb
You might also be interested in these projects:
'a.b.c'
) paths. | homepageCommits | Contributor |
---|---|
32 | jonschlinkert |
2 | rmharrison |
1 | wtgtybhertgeghgtwtg |
Jon Schlinkert
Copyright © 2018, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on March 03, 2018.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 3/27 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-01-13
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More