Returns true if the given is falsey (according to JavaScript) or matches a 'falsey' keyword.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your ❤️ and support.
Install with npm:
$ npm install --save falseyThis is intended to be a fun way of accepting alternatives to false or "no" in CLI prompts, web forms, etc. For example, you might want to allow users to define nil or nope to disable something.
const falsey = require('falsey');
console.log(falsey()); //=> true
console.log(falsey(false)); //=> true
console.log(falsey('nil')); //=> true
console.log(falsey('nope')); //=> true
console.log(falsey('yes')); //=> falseAny value that is not falsey (according to JavaScript) and is not in the list of falsey keywords will return false:
falsey('abc');
falsey(true);
falsey(1);
falsey('1');
falsey({});
falsey([]);Any value that is falsey (according to JavaScript) or is in the list of falsey keywords will return true:
falsey(); //=> true
falsey(''); //=> true
falsey(0); //=> true
falsey(false); //=> true
falsey(NaN); //=> true
falsey(null); //=> true
falsey(undefined); //=> true
falsey(void 0); //=> trueIf a value matches one of the built-in "falsey" keywords (all strings) it will return true:
0falsenadanilnaynahnegativenononenopenulnullnixnyetuh-uhvetozero
Customize falsey keywords
Pass an array of custom keywords that should return true when evaluated as falsey:
falsey('zilch', ['no', 'nope', 'nada', 'zilch']); //=> trueDisable built-in keywords by passing an empty array:
falsey('nil', []); //=> falseExtend built-in keywords
Built-in keywords are exposed on the .keywords property so that you may extend them with your own keywords:
falsey('zilch', falsey.keywords.concat(['zilch'])); //=> trueBreaking changes
- objects will now always returns
false - more words were added to the built-in list of falsey keywords
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
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 testBuilding 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 && verbYou might also be interested in these projects:
- is-number: Returns true if the value is a number. comprehensive tests. | homepage
- is-primitive: Returns
trueif 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
| Commits | Contributor |
|---|---|
| 12 | jonschlinkert |
| 9 | doowb |
| 3 | jesstelford |
Jon Schlinkert
Copyright © 2018, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on March 18, 2018.