empty-value
📦 Check if a given value is empty in JS extending his "truthy" and "falsy" nature
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 = ; //false //false //false //false //false //false //false //false //true //true //true //true //true //true //true; //true; //true //true //true var proto = foo: 'bar' ;var obj = Object; //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 {//i don't like functions return typeof value === 'function' ? true : false;}var { return 'bar';} ; //true
License
MIT