Socket
Socket
Sign inDemoInstall

has-values

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    has-values

Returns true if any values exist, false if empty. Works for booleans, functions, numbers, strings, nulls, objects and arrays.


Version published
Weekly downloads
24M
decreased by-2.79%
Maintainers
1
Install size
5.09 kB
Created
Weekly downloads
 

Readme

Source

has-values NPM version Build Status

Returns true if a value exists, false if empty. Works for booleans, functions, numbers, strings, nulls, objects and arrays. Other libs do this, but I needed one that would optionally not treat zero as empty. Also, this works with booleans and other values that other libs fail to test properly.

Install with npm

npm i has-values --save

Running tests

Install dev dependencies.

npm i -d && npm test

Usage

var hasValue = require('has-values');

hasValue('a');
//=> true

hasValue('');
//=> false

hasValue(1);
//=> true

hasValue(0);
//=> false

hasValue(0, true); // treat zero as a value
//=> true

hasValue({a: 'a'}});
//=> true

hasValue({}});
//=> false

hasValue(['a']);
//=> true

hasValue([]);
//=> false

hasValue(function(foo) {}); // function length/arity
//=> true

hasValue(function() {});
//=> false

hasValue(true);
hasValue(false);
//=> true

isEmpty

To test for empty values, do:

function isEmpty(o, isZero) {
  return !hasValue(o, isZero);
}

Author

Jon Schlinkert

License

Copyright (c) 2015 Jon Schlinkert
Released under the MIT license


This file was generated by verb-cli on March 24, 2015.

Keywords

FAQs

Last updated on 27 Mar 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc