|
4 years ago | |
---|---|---|
.. | ||
node_modules/kind-of | 4 years ago | |
LICENSE | 4 years ago | |
README.md | 4 years ago | |
index.js | 4 years ago | |
package.json | 4 years ago |
README.md
falsey

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
Install with npm:
$ npm install --save falsey
What makes this lib unique (and fun) is the option to pass an array of values that should always evuate as "falsey".
This is useful for CLI prompts, web forms, etc. For example, you might want to allow users to define nil
or nope
to disable something.
Usage
var isFalsey = require('falsey');
console.log(isFalsey('nil');
//=> `true`
Examples
All of the following return true
isFalsey(undefined);
isFalsey(null);
isFalsey(false);
isFalsey(0);
isFalsey('');
isFalsey(NaN);
isFalsey({});
isFalsey([]);
All of the following return false
:
isFalsey('foo');
isFalsey(true);
isFalsey(50);
isFalsey('10');
isFalsey({a: 'b'});
isFalsey([0]);
Special cases
There are several additional "falsey" words built in, but these can be overridden or turned off by passing a value as the second argument.
Built-in additional falsey keywords
none
nil
nope
no
nada
0
false
Disable additions
isFalsey('nil', []);
//=> false
Customize additions
Pass one or more keywords that should return true
when evaluated as falsey:
isFalsey('zilch', ['no', 'nope', 'nada', 'zilch']);
//=> true
Extend additions
Built-in keywords are exposed on the .keywords
property. These can be used to extend the defaults:
isFalsey('zilch', isFalsey.keywords.concat(['zilch']));
//=> true
About
Related projects
- is-number: Returns true if the value is a number. comprehensive tests. | homepage
- is-primitive: Returns
true
if the value is a primitive. | homepage - isobject: Returns true if the value is an object and not an array or null. | homepage
- kind-of: Get the native type of a value. | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Building docs
(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
Running tests
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
Author
Jon Schlinkert
License
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on September 11, 2017.