Socket
Socket
Sign inDemoInstall

has-value

Package Overview
Dependencies
6
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.2.0

LICENSE

36

index.js
/*!
* has-value <https://github.com/jonschlinkert/has-value>
*
* Copyright (c) 2014 Jon Schlinkert, contributors.
* Licensed under the MIT License
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*/

@@ -10,28 +10,14 @@

module.exports = function hasValue(o, noZero) {
if (o === null || o === undefined) {
return false;
}
var get = require('get-value');
var hasValues = require('has-values');
if (typeof o === 'boolean') {
return true;
module.exports = function (o, path, fn) {
var len = arguments.length;
if (len === 1 || (len === 2 && typeof path === 'boolean')) {
return hasValues.apply(hasValues, arguments);
}
if (typeof o === 'number') {
if (o === 0 && noZero === true) {
return false;
}
return true;
if (len === 3 && typeof fn === 'boolean') {
return hasValues(get.apply(get, arguments), fn);
}
if (o.length !== undefined) {
return o.length !== 0;
}
for (var key in o) {
if (o.hasOwnProperty(key)) {
return true;
}
}
return false;
return hasValues(get.apply(get, arguments));
};
{
"name": "has-value",
"description": "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.",
"version": "0.1.0",
"description": "Returns true if a value exists, false if empty. Works with deeply nested values using object paths.",
"version": "0.2.0",
"homepage": "https://github.com/jonschlinkert/has-value",

@@ -17,7 +17,8 @@ "author": {

},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/jonschlinkert/has-value/blob/master/LICENSE-MIT"
}
"license": {
"type": "MIT",
"url": "https://github.com/jonschlinkert/has-value/blob/master/LICENSE"
},
"files": [
"index.js"
],

@@ -29,8 +30,11 @@ "main": "index.js",

"scripts": {
"test": "mocha -R spec"
"test": "mocha"
},
"dependencies": {
"get-value": "^1.1.1",
"has-values": "^0.1.2"
},
"devDependencies": {
"mocha": "*",
"should": "^4.0.4",
"verb": ">= 0.2.6"
"should": "^4.0.4"
},

@@ -37,0 +41,0 @@ "keywords": [

@@ -1,24 +0,47 @@

# has-value [![NPM version](https://badge.fury.io/js/has-value.svg)](http://badge.fury.io/js/has-value)
# has-value [![NPM version](https://badge.fury.io/js/has-value.svg)](http://badge.fury.io/js/has-value) [![Build Status](https://travis-ci.org/jonschlinkert/has-value.svg)](https://travis-ci.org/jonschlinkert/has-value)
> Returns true if a value exists, false if empty. Works with deeply nested values using object paths.
> 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.
**Works for:**
## Install
#### Install with [npm](npmjs.org):
- booleans
- functions
- numbers (pass `true` as the last arg to treat zero as a value instead of falsey)
- strings
- nulls
- object
- arrays
```bash
npm i has-value --save-dev
```
<!-- toc -->
## Run tests
- [Related projects](#related-projects)
- [Usage](#usage)
- [isEmpty](#isempty)
- [Contributing](#contributing)
- [Running tests](#running-tests)
- [Author](#author)
- [License](#license)
<!-- tocstop -->
## Install with [npm](npmjs.org)
```bash
npm test
npm i has-value --save
```
## Related projects
{%= related(['get-value', 'set-value', 'get-property', 'get-object']) %}
## Usage
Works with nested object paths or a single value:
```js
var hasValue = require('has-value');
hasValue({a: {b: {c: 'foo'}}} 'a.b.c');
//=> true
hasValue('a');

@@ -36,3 +59,3 @@ //=> true

hasValue(0, true); // treat zero as a value
hasValue(0, true); // pass `true` as the last arg to treat zero as a value
//=> true

@@ -63,2 +86,22 @@

## isEmpty
To do the opposite and test for empty values, do:
```js
function isEmpty(o, isZero) {
return !hasValue.apply(hasValue, arguments);
}
```
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/has-value/issues)
## Running tests
Install dev dependencies.
```bash
npm i -d && npm test
```
## Author

@@ -72,3 +115,3 @@

## License
Copyright (c) 2014 Jon Schlinkert, contributors.
Copyright (c) 2014-2015 Jon Schlinkert
Released under the MIT license

@@ -78,2 +121,2 @@

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 21, 2014._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 25, 2015._
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