package
Returns true if any values exist, false if empty. Works for booleans, functions, numbers, strings, nulls, objects and arrays.
npm install has-valuesGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 2 packages.
22.3 kB
Includes dependencies.
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 with npm:
$ npm install --save has-valuesconst has = require('has-values');Create an isEmpty function by returning the inverse of the result from has-values:
const isEmpty = val => !has(val);console.log(has(['a'])); //=> true
console.log(has([0])); //=> true
console.log(has([[[]]])); //=> false
console.log(has([[], []])); //=> false
console.log(has([])); //=> falseconsole.log(has(true)); //=> true
console.log(has(false)); //=> trueconsole.log(has(new Buffer())); //=> false
console.log(has(new Buffer('foo'))); //=> trueDates are always true.
console.log(has(new Date())); //=> trueReturns false if err.message is an empty string.
console.log(has(new Error())); //=> false
console.log(has(new Error('foo'))); //=> trueFunctions are always true.
console.log(has(function(foo) {})); //=> true
console.log(has(function() {})); //=> trueconsole.log(has(new Map())); //=> false
console.log(has(new Map([['foo', 'bar']]))); //=> truenull is always true, as it's assumed that this is a user-defined value, versus undefined which is not.
console.log(has(null)); //=> trueconsole.log(has({})); //=> false
console.log(has({ a: 'a' }})); //=> true
console.log(has({ foo: undefined })); //=> false
console.log(has({ foo: null })); //=> trueconsole.log(has(1)); //=> true
console.log(has(0)); //=> trueconsole.log(has(new RegExp())); //=> false
console.log(has(new RegExp('foo'))); //=> trueconsole.log(has(new Set())); //=> false
console.log(has(new Set(['foo', 'bar']))); //=> trueconsole.log(has('a')); //=> true
console.log(has('')); //=> falseconsole.log(has()); //=> false
console.log(has(void 0)); //=> false
console.log(has(undefined)); //=> falseregex and bufferMap and Setzero always returns truearray now recurses, so that an array of empty arrays will return falsenull 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:
$ npm install && npm testYou might also be interested in these projects:
Object constructor. | homepageJon Schlinkert
Copyright © 2018, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on January 30, 2018.