@stdlib/assert-is-truthy
v0.2.2
Published
Test if a value is truthy.
Downloads
45
Readme
isTruthy
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
See Also
@stdlib/assert-is-falsy
: test if a value is falsy.
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
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.