Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonschlinkert/falsey
Like other checkers, returns true if `value` is falsey. Strings, arrays and `arguments` objects with a length of `0`, and objects with no own enumerable properties are considered falsey. Will also check against user-defined "special cases".
https://github.com/jonschlinkert/falsey
false falsey javascript
Last synced: 4 days ago
JSON representation
Like other checkers, returns true if `value` is falsey. Strings, arrays and `arguments` objects with a length of `0`, and objects with no own enumerable properties are considered falsey. Will also check against user-defined "special cases".
- Host: GitHub
- URL: https://github.com/jonschlinkert/falsey
- Owner: jonschlinkert
- License: mit
- Created: 2014-07-09T00:46:49.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-05-15T11:51:19.000Z (over 2 years ago)
- Last Synced: 2024-10-24T06:51:15.136Z (13 days ago)
- Topics: false, falsey, javascript
- Language: JavaScript
- Homepage: https://github.com/jonschlinkert
- Size: 24.4 KB
- Stars: 7
- Watchers: 4
- Forks: 6
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# falsey [![NPM version](https://img.shields.io/npm/v/falsey.svg?style=flat)](https://www.npmjs.com/package/falsey) [![NPM monthly downloads](https://img.shields.io/npm/dm/falsey.svg?style=flat)](https://npmjs.org/package/falsey) [![NPM total downloads](https://img.shields.io/npm/dt/falsey.svg?style=flat)](https://npmjs.org/package/falsey) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/falsey.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/falsey) [![Windows Build Status](https://img.shields.io/appveyor/ci/jonschlinkert/falsey.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/jonschlinkert/falsey)
> Returns true if the given is falsey (according to JavaScript) or matches a 'falsey' keyword.
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save falsey
```## What is this?
This 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.
## Usage
```js
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')); //=> false
```## Examples
Any value that is not falsey (according to JavaScript) _and is not in the list_ of [falsey keywords](#falsey-keywords) will return `false`:
```js
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](#falsey-keywords) will return `true`:
```js
falsey(); //=> true
falsey(''); //=> true
falsey(0); //=> true
falsey(false); //=> true
falsey(NaN); //=> true
falsey(null); //=> true
falsey(undefined); //=> true
falsey(void 0); //=> true
```### Falsey keywords
If a value matches one of the built-in "falsey" keywords (all strings) it will return `true`:
* `0`
* `false`
* `nada`
* `nil`
* `nay`
* `nah`
* `negative`
* `no`
* `none`
* `nope`
* `nul`
* `null`
* `nix`
* `nyet`
* `uh-uh`
* `veto`
* `zero`**Customize falsey keywords**
Pass an array of custom keywords that should return `true` when evaluated as _falsey_:
```js
falsey('zilch', ['no', 'nope', 'nada', 'zilch']); //=> true
```Disable built-in keywords by passing an empty array:
```js
falsey('nil', []); //=> false
```**Extend built-in keywords**
Built-in keywords are exposed on the `.keywords` property so that you may extend them with your own keywords:
```js
falsey('zilch', falsey.keywords.concat(['zilch'])); //=> true
```## Release history
### v1.0
**Breaking changes**
* objects will now always returns `false`
* more words were added to the built-in list of [falsey keywords](#falsey-keywords)## About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
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:
```sh
$ npm install && npm test
```Building docs
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```### Related projects
You might also be interested in these projects:
* [is-number](https://www.npmjs.com/package/is-number): Returns true if the value is a number. comprehensive tests. | [homepage](https://github.com/jonschlinkert/is-number "Returns true if the value is a number. comprehensive tests.")
* [is-primitive](https://www.npmjs.com/package/is-primitive): Returns `true` if the value is a primitive. | [homepage](https://github.com/jonschlinkert/is-primitive "Returns `true` if the value is a primitive. ")
* [isobject](https://www.npmjs.com/package/isobject): Returns true if the value is an object and not an array or null. | [homepage](https://github.com/jonschlinkert/isobject "Returns true if the value is an object and not an array or null.")
* [kind-of](https://www.npmjs.com/package/kind-of): Get the native type of a value. | [homepage](https://github.com/jonschlinkert/kind-of "Get the native type of a value.")### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 12 | [jonschlinkert](https://github.com/jonschlinkert) |
| 9 | [doowb](https://github.com/doowb) |
| 3 | [jesstelford](https://github.com/jesstelford) |### Author
**Jon Schlinkert**
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
* [GitHub Profile](https://github.com/jonschlinkert)
* [Twitter Profile](https://twitter.com/jonschlinkert)### License
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on March 18, 2018._