JSPM

true-bool

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 22
  • Score
    100M100P100Q47665F
  • License MIT

Convert value to boolean(like Python bool).

Package Exports

  • true-bool

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (true-bool) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

true-bool

Convert any value to boolean(like Python bool()).

description

Zero-dependency module that converts any type value to boolean.
Empty objects, arrays, maps, sets - are converted to false.

var bool = require('true-bool');

bool(false); // false
bool(null); // false
bool(undefined); // false
bool(''); // false
bool(0); // false
bool(-0); // false
bool(+0); // false
bool([]); // false
bool({}); // false
bool(NaN); // false
bool(new Map()); // false
bool(new Set()); // false
bool(true); // true
bool('foo'); // true
bool(1); // true
bool(-1); // true
bool([1, 2]); // true
bool({'foo': 'bar'}); // true
bool(new Map([['foo', 'bar']])); // true
bool(new Set([1,2,3])); // true

install

npm install true-bool

update

npm update true-bool

uninstall

npm uninstall true-bool

example

var bool = require('true-bool');

function foo(v) {
    if (bool(v)) {
        operate(v);
    } else {
        throw new Error('Argument must be non-empty value!');
    }
}

license

MIT