Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

to-bool

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

to-bool

Convert types to boolean.

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
increased by14.85%
Maintainers
1
Weekly downloads
 
Created
Source

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.");
}

Keywords

FAQs

Package last updated on 20 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc