Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Returns true if any values exist, false if empty. Works for booleans, functions, numbers, strings, nulls, objects and arrays.
The has-values npm package is a utility that checks if a value exists and is not empty. It can be used to validate objects, arrays, strings, and other data types to ensure they contain meaningful data.
Check if a string has a value
This feature allows you to check if a string is non-empty. It returns true if the string has a value and false if it is empty.
const hasValues = require('has-values');
console.log(hasValues('hello')); // true
console.log(hasValues('')); // false
Check if an array has values
This feature checks if an array contains any elements. It returns true if the array has elements and false if it is empty.
const hasValues = require('has-values');
console.log(hasValues([1, 2, 3])); // true
console.log(hasValues([])); // false
Check if an object has values
This feature checks if an object has any properties. It returns true if the object has properties and false if it is empty.
const hasValues = require('has-values');
console.log(hasValues({a: 1, b: 2})); // true
console.log(hasValues({})); // false
Check if a nested object has values
This feature checks if a nested object contains any values. It returns true if the nested object has values and false if it is empty.
const hasValues = require('has-values');
console.log(hasValues({a: {b: 2}})); // true
console.log(hasValues({a: {}})); // false
Lodash is a popular utility library that provides a wide range of functions for manipulating and validating data. It includes methods like _.isEmpty, which can be used to check if a value is empty, similar to has-values.
Underscore is another utility library that offers a variety of functions for working with arrays, objects, and other data types. It includes the _.isEmpty method, which serves a similar purpose to has-values by checking if a value is empty.
Validator is a library focused on string validation and sanitization. It includes functions like isEmpty, which can be used to check if a string is empty, similar to the functionality provided by 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 with npm:
$ npm install --save has-values
const 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([])); //=> false
console.log(has(true)); //=> true
console.log(has(false)); //=> true
console.log(has(new Buffer())); //=> false
console.log(has(new Buffer('foo'))); //=> true
Dates are always true.
console.log(has(new Date())); //=> true
Returns false
if err.message
is an empty string.
console.log(has(new Error())); //=> false
console.log(has(new Error('foo'))); //=> true
Functions are always true.
console.log(has(function(foo) {})); //=> true
console.log(has(function() {})); //=> true
console.log(has(new Map())); //=> false
console.log(has(new Map([['foo', 'bar']]))); //=> true
null
is always true, as it's assumed that this is a user-defined value, versus undefined
which is not.
console.log(has(null)); //=> true
console.log(has({})); //=> false
console.log(has({ a: 'a' }})); //=> true
console.log(has({ foo: undefined })); //=> false
console.log(has({ foo: null })); //=> true
console.log(has(1)); //=> true
console.log(has(0)); //=> true
console.log(has(new RegExp())); //=> false
console.log(has(new RegExp('foo'))); //=> true
console.log(has(new Set())); //=> false
console.log(has(new Set(['foo', 'bar']))); //=> true
console.log(has('a')); //=> true
console.log(has('')); //=> false
console.log(has()); //=> false
console.log(has(void 0)); //=> false
console.log(has(undefined)); //=> false
regex
and buffer
Map
and Set
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:
$ 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:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
You 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.
FAQs
Returns true if any values exist, false if empty. Works for booleans, functions, numbers, strings, nulls, objects and arrays.
The npm package has-values receives a total of 13,352,743 weekly downloads. As such, has-values popularity was classified as popular.
We found that has-values demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.