What is @stdlib/assert-is-number?
@stdlib/assert-is-number is a utility package that provides functions to check if a value is a number. It includes checks for different types of numbers such as finite numbers, integers, and NaN values.
What are @stdlib/assert-is-number's main functionalities?
isNumber
The `isNumber` function checks if a value is a number. It returns `true` if the value is a number and `false` otherwise.
const isNumber = require('@stdlib/assert-is-number');
console.log(isNumber(5)); // true
console.log(isNumber('5')); // false
isFinite
The `isFinite` function checks if a value is a finite number. It returns `true` if the value is finite and `false` otherwise.
const isFinite = require('@stdlib/assert-is-number').isFinite;
console.log(isFinite(5)); // true
console.log(isFinite(Infinity)); // false
isInteger
The `isInteger` function checks if a value is an integer. It returns `true` if the value is an integer and `false` otherwise.
const isInteger = require('@stdlib/assert-is-number').isInteger;
console.log(isInteger(5)); // true
console.log(isInteger(5.5)); // false
isNaN
The `isNaN` function checks if a value is NaN (Not-a-Number). It returns `true` if the value is NaN and `false` otherwise.
const isNaN = require('@stdlib/assert-is-number').isNaN;
console.log(isNaN(NaN)); // true
console.log(isNaN(5)); // false
Other packages similar to @stdlib/assert-is-number
is-number
The `is-number` package provides a simple utility to check if a value is a number. It is similar to `@stdlib/assert-is-number` but with fewer features. It mainly focuses on checking if a value is a number and does not include checks for finite numbers, integers, or NaN values.
lodash
Lodash is a utility library that provides a wide range of functions for common programming tasks, including type checking. The `_.isNumber` function in Lodash can be used to check if a value is a number. While Lodash offers more comprehensive functionality beyond type checking, it is heavier and includes many features that may not be necessary if you only need number validation.
validator
The `validator` package is a library for string validation and sanitization. It includes a function `isNumeric` that checks if a string contains only numbers. While it is not as comprehensive as `@stdlib/assert-is-number` for number validation, it is useful for validating numeric strings.
About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
isNumber
Test if a value is a number.
Installation
npm install @stdlib/assert-is-number
Usage
var isNumber = require( '@stdlib/assert-is-number' );
isNumber( value )
Tests if a value
is a number
.
var Number = require( '@stdlib/number-ctor' );
var bool = isNumber( 3.14 );
bool = isNumber( new Number( 3.14 ) );
bool = isNumber( NaN );
bool = isNumber( null );
isNumber.isPrimitive( value )
Tests if a value
is a primitive number
.
var Number = require( '@stdlib/number-ctor' );
var bool = isNumber.isPrimitive( 3.14 );
bool = isNumber.isPrimitive( NaN );
bool = isNumber.isPrimitive( new Number( 3.14 ) );
isNumber.isObject( value )
Tests if a value
is a Number
object.
var Number = require( '@stdlib/number-ctor' );
var bool = isNumber.isObject( 3.14 );
bool = isNumber.isObject( new Number( 3.14 ) );
Examples
var Number = require( '@stdlib/number-ctor' );
var isNumber = require( '@stdlib/assert-is-number' );
var bool = isNumber( 5 );
bool = isNumber( new Number( 5 ) );
bool = isNumber( NaN );
bool = isNumber( '5' );
bool = isNumber( null );
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.

License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.
0.2.2 (2024-07-27)
No changes reported for this release.
</section>
<!-- /.release -->
<section class="release" id="v0.2.1">