@tobius/istruthy

Determine if a given value is "truthy" (likely to represent boolean true).

Usage no npm install needed!

<script type="module">
  import tobiusIstruthy from 'https://cdn.skypack.dev/@tobius/istruthy';
</script>

README

isTruthy

Determine if a given value is "truthy" (likely to represent boolean true).

Install

[~] npm i @tobius/istruthy

Supported by Node.js version 4, 6, 8, 10, 12, 14, and 16.

Usage

const isTruthy = require('isTruthy');

// true
console.log([
    isTruthy('1'),
    isTruthy('1.0'),
    isTruthy('active'),
    isTruthy('on'),
    isTruthy('true'),
    isTruthy(1),
    isTruthy(1.0),
    isTruthy(true),
]);

// false
console.log([
    isTruthy('-1'),
    isTruthy('-1.5'),
    isTruthy('-100'),
    isTruthy('-100.5'),
    isTruthy('0'),
    isTruthy('0.0'),
    isTruthy('1.5'),
    isTruthy('100'),
    isTruthy('100.5'),
    isTruthy('Infinity'),
    isTruthy('NaN'),
    isTruthy('false'),
    isTruthy('inactive'),
    isTruthy('null'),
    isTruthy('off'),
    isTruthy('undefined'),
    isTruthy(-1),
    isTruthy(-1.5),
    isTruthy(-100),
    isTruthy(-100.5),
    isTruthy(0),
    isTruthy(0.0),
    isTruthy(1.5),
    isTruthy(100),
    isTruthy(100.5),
    isTruthy(Infinity),
    isTruthy(NaN),
    isTruthy(false),
    isTruthy(null),
    isTruthy(undefined),
]);

License

This software library is licensed under the MIT License.