
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
@stdlib/assert-is-probability
Advanced tools
Test if a value is a probability.
A probability is defined as a numeric value on the interval [0,1]
.
npm install @stdlib/assert-is-probability
var isProbability = require( '@stdlib/assert-is-probability' );
Tests if a value
is a probability.
var Number = require( '@stdlib/number-ctor' );
var bool = isProbability( 0.5 );
// returns true
bool = isProbability( new Number( 0.5 ) );
// returns true
bool = isProbability( 3.14 );
// returns false
bool = isProbability( -5.0 );
// returns false
bool = isProbability( NaN );
// returns false
bool = isProbability( null );
// returns false
Tests if a value
is a primitive probability.
var Number = require( '@stdlib/number-ctor' );
var bool = isProbability.isPrimitive( 0.33 );
// returns true
bool = isProbability.isPrimitive( new Number( 0.33 ) );
// returns false
Tests if a value
is a Number
object having a value which is a probability.
var Number = require( '@stdlib/number-ctor' );
var bool = isProbability.isObject( 0.11 );
// returns false
bool = isProbability.isObject( new Number( 0.11 ) );
// returns true
var Number = require( '@stdlib/number-ctor' );
var isProbability = require( '@stdlib/assert-is-probability' );
var bool = isProbability( 0.5 );
// returns true
bool = isProbability( new Number( 0.5 ) );
// returns true
bool = isProbability( 0.0 );
// returns true
bool = isProbability( 1.0 );
// returns true
bool = isProbability( 3.14 );
// returns false
bool = isProbability( -5.0 );
// returns false
bool = isProbability( NaN );
// returns false
bool = isProbability( '0.5' );
// returns false
bool = isProbability( null );
// returns false
@stdlib/assert/is-number
: test if a value is a number.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.
See LICENSE.
Copyright © 2016-2022. The Stdlib Authors.
0.0.7 (2022-02-16)
No changes reported for this release.
</section> <!-- /.release --> <section class="release" id="v0.0.6">FAQs
Test if a value is a probability.
The npm package @stdlib/assert-is-probability receives a total of 5,310 weekly downloads. As such, @stdlib/assert-is-probability popularity was classified as popular.
We found that @stdlib/assert-is-probability demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.