@stdlib/assert-is-truthy

Test if a value is truthy.

Usage no npm install needed!

<script type="module">
  import stdlibAssertIsTruthy from 'https://cdn.skypack.dev/@stdlib/assert-is-truthy';
</script>

README

isTruthy

NPM version Build Status Coverage Status

Test if a value is truthy.

Installation

npm install @stdlib/assert-is-truthy

Usage

var isTruthy = require( '@stdlib/assert-is-truthy' );

isTruthy( value )

Tests if a value is a value which translates to true when evaluated in a boolean context.

var bool = isTruthy( true );
// returns true

bool = isTruthy( [] );
// returns true

bool = isTruthy( false );
// returns false

bool = isTruthy( '' );
// returns false

bool = isTruthy( 0 );
// returns false

bool = isTruthy( NaN );
// returns false

bool = isTruthy( null );
// returns false

bool = isTruthy( void 0 );
// returns false

Examples

var isTruthy = require( '@stdlib/assert-is-truthy' );

var bool = isTruthy( true );
// returns true

bool = isTruthy( 'beep' );
// returns true

bool = isTruthy( 5 );
// returns true

bool = isTruthy( [] );
// returns true

bool = isTruthy( {} );
// returns true

bool = isTruthy( function foo() {} );
// returns true

bool = isTruthy( false );
// returns false

bool = isTruthy( 0 );
// returns false

bool = isTruthy( NaN );
// returns false

bool = isTruthy( '' );
// returns false

bool = isTruthy( void 0 );
// returns false

bool = isTruthy( null );
// returns false

Notice

This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

Community

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2022. The Stdlib Authors.