https://github.com/perry-mitchell/to-bool
Convert types to boolean.
https://github.com/perry-mitchell/to-bool
bool boolean convert-data convert-types
Last synced: 9 months ago
JSON representation
Convert types to boolean.
- Host: GitHub
- URL: https://github.com/perry-mitchell/to-bool
- Owner: perry-mitchell
- License: mit
- Created: 2015-07-20T09:47:43.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-07-20T10:27:58.000Z (over 10 years ago)
- Last Synced: 2025-03-31T07:22:32.622Z (10 months ago)
- Topics: bool, boolean, convert-data, convert-types
- Language: JavaScript
- Size: 129 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# To-Bool
Convert data types to boolean.
## About
This is a very basic utility library to help convert the basic JS data types to boolean. Each type is treated differently:
* *Boolean* is returned as-is
* *Function* is assumed to be true
* *Number* is true for greater-or-less-than 0
* *Object* is just cast to boolean (`!!`), which works for `null` (as `typeof null === "object"`)
* *String* is converted to lower-case and compared to `"true"` or `"1"`
* *Symbol* is currently treated as always-true
* *Undefined* is always false
If none of these types match the passed item, a `TypeError` is thrown.
## Usage
Usage is super easy:
```
var toBool = require("to-bool");
if (toBool(someVariable)) {
console.log("It's true.");
}
```