Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

empty-value

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

empty-value

Check if a given value is empty in JS extending his "truthy" and "falsy" nature

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
264
decreased by-5.38%
Maintainers
1
Weekly downloads
 
Created
Source

empty-value

:package: Check if a given value is empty in JS extending his "truthy" and "falsy" nature

Status

Build Status

Installation

Using npm

npm install --save empty-value
The following values are considered to be empty:
  • NaN
  • 0 (0 as an integer)
  • 0.0 (0 as a float)
  • "0" (0 as a string)
  • null
  • false
  • undefined
  • "" (an empty string)
  • " " (an string with only spaces)
  • array( ) / [ ] (an empty array)
  • { } (an empty object / no direct keys)

Usage

var empty = require('empty-value');

empty(true) //false
empty(12345) //false
empty(-12345) //false
empty('Lorem Ipsum is simply dummy text') //false
empty([1, 2, 3]) //false
empty({ foo: 'bar' }) //false
empty('{ "id" : 1 }') //false
empty(function () { }) //false

empty(NaN) //true
empty(0) //true
empty(0.0) //true
empty(null) //true
empty(false) //true
empty(undefined) //true
empty('0') //true
empty(''); //true
empty(' '); //true
empty([]) //true
empty({ }) //true

var proto = { foo: 'bar' };
var obj = Object.create(proto);
empty(obj) //true  Note: foo is not a directly property of obj
Using hooks

If empty can't guess the correct answer (IE: value is a function) before return FALSE you could use your own hook. See example bellow:

var myEmptyHook = function (value) {//i don't like functions
  return typeof value === 'function' ? true : false;
}
var func = function () {
  return 'bar';
}

empty(func, myEmptyHook); //true
License

MIT

Keywords

FAQs

Package last updated on 12 Apr 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc