Returns true if
value
is falsey. Works for strings, arrays andarguments
objects with a length of0
, and objects with no own enumerable properties are considered falsey.
Install with npm
npm i falsey --save
What makes this lib unique is the option to pass an array of values that should always evuate as "falsey". For example, you might want to allow users to define nil
or nope
to disable something.
var isFalsey = require('falsey');
console.log(isFalsey('');
//=> `true`
All of the following return true
isFalsey(undefined);
isFalsey(null);
isFalsey(false);
!isFalsey(true);
isFalsey(0);
!isFalsey(1);
isFalsey('');
!isFalsey('1');
isFalsey(NaN);
isFalsey({});
!isFalsey({a: 'b'});
isFalsey([]);
!isFalsey([0]);
There are only four "special cases", ['false', 'none', 'nil', 'null]
, and these are easily overridden by passing a value as a second parameter, e.g.
isFalsey(foo, []);
// other examples...
isFalsey('false');
!isFalsey('false', []); // override special cases
!isFalsey('true');
isFalsey('nil');
!isFalsey('nil', []); // override special cases
isFalsey('none');
!isFalsey('none', []); // override special cases
isFalsey('null');
!isFalsey('null', []); // override special cases
Or, pass an array of values that should return true
when evaluated as falsey:
isFalsey(foo, ['no', 'nope', 'nada', 'zilch']);
// you get the point
- is-primitive: Returns
true
if the value is a primitive. - is-number: Returns true if the value is a number. comprehensive tests.
- isobject: Returns true if the value is an object and not an array or null.
- kind-of: Get the native type of a value.
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Install dev dependencies.
npm i -d && npm test
Jon Schlinkert
Copyright (c) 2015 Jon Schlinkert
Released under the MIT license
This file was generated by verb-cli on March 07, 2015.