Returns true if any values exist, false if empty. Works for booleans, functions, numbers, strings, nulls, objects and arrays.
Installations
npm install has-values
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=6
Node Version
9.1.0
NPM Version
5.6.0
Score
99.5
Supply Chain
99.6
Quality
75.3
Maintenance
100
Vulnerability
100
License
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
jonschlinkert
Download Statistics
Total Downloads
8,715,044,731
Last Day
3,784,718
Last Week
19,765,856
Last Month
71,682,654
Last Year
1,195,218,541
GitHub Statistics
23 Stars
21 Commits
5 Forks
3 Watching
1 Branches
2 Contributors
Bundle Size
2.82 kB
Minified
986.00 B
Minified + Gzipped
Package Meta Information
Latest Version
2.0.1
Package Id
has-values@2.0.1
Size
3.39 kB
NPM Version
5.6.0
Node Version
9.1.0
Publised On
31 Jan 2018
Total Downloads
Cumulative downloads
Total Downloads
8,715,044,731
Last day
-2.9%
3,784,718
Compared to previous day
Last week
0.3%
19,765,856
Compared to previous week
Last month
-24.8%
71,682,654
Compared to previous month
Last year
-23%
1,195,218,541
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
2
has-values
Returns true if any values exist, false if empty. Works for booleans, functions, numbers, strings, nulls, objects and arrays.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install
Install with npm:
1$ npm install --save has-values
Usage
1const has = require('has-values');
Create an isEmpty
function by returning the inverse of the result from has-values:
1const isEmpty = val => !has(val);
Supported types
Arrays
1console.log(has(['a'])); //=> true 2console.log(has([0])); //=> true 3console.log(has([[[]]])); //=> false 4console.log(has([[], []])); //=> false 5console.log(has([])); //=> false
Booleans
1console.log(has(true)); //=> true
2console.log(has(false)); //=> true
Buffers
1console.log(has(new Buffer())); //=> false
2console.log(has(new Buffer('foo'))); //=> true
Dates
Dates are always true.
1console.log(has(new Date())); //=> true
Errors
Returns false
if err.message
is an empty string.
1console.log(has(new Error())); //=> false 2console.log(has(new Error('foo'))); //=> true
Functions
Functions are always true.
1console.log(has(function(foo) {})); //=> true 2console.log(has(function() {})); //=> true
Maps
1console.log(has(new Map())); //=> false 2console.log(has(new Map([['foo', 'bar']]))); //=> true
Null
null
is always true, as it's assumed that this is a user-defined value, versus undefined
which is not.
1console.log(has(null)); //=> true
Objects
1console.log(has({})); //=> false
2console.log(has({ a: 'a' }})); //=> true
3console.log(has({ foo: undefined })); //=> false
4console.log(has({ foo: null })); //=> true
Numbers
1console.log(has(1)); //=> true
2console.log(has(0)); //=> true
Regular expressions
1console.log(has(new RegExp())); //=> false 2console.log(has(new RegExp('foo'))); //=> true
Sets
1console.log(has(new Set())); //=> false
2console.log(has(new Set(['foo', 'bar']))); //=> true
Strings
1console.log(has('a')); //=> true 2console.log(has('')); //=> false
Undefined
1console.log(has()); //=> false
2console.log(has(void 0)); //=> false
3console.log(has(undefined)); //=> false
Release history
v2.0.0
- no longer supports numbers as a string
- optimizations
- adds support for
regex
andbuffer
v1.0.0
- adds support for
Map
andSet
zero
always returns truearray
now recurses, so that an array of empty arrays will returnfalse
null
now returns true
About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running Tests
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
Building docs
(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
Related projects
You might also be interested in these projects:
- has-value: Returns true if a value exists, false if empty. Works with deeply nested values using… more | homepage
- is-number: Returns true if the value is a number. comprehensive tests. | homepage
- is-plain-object: Returns true if an object was created by the
Object
constructor. | homepage - isobject: Returns true if the value is an object and not an array or null. | homepage
- kind-of: Get the native type of a value. | homepage
Author
Jon Schlinkert
License
Copyright © 2018, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on January 30, 2018.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/21 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-01-20
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 MoreOther packages similar to has-values
has-value
Returns true if a value exists, false if empty. Works with deeply nested values using object paths.
@types/has-values
TypeScript definitions for has-values
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.