
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
@stdlib/assert-is-number
Advanced tools
@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.
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
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 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.
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.
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!
Test if a value is a number.
npm install @stdlib/assert-is-number
var isNumber = require( '@stdlib/assert-is-number' );
Tests if a value
is a number
.
var Number = require( '@stdlib/number-ctor' );
var bool = isNumber( 3.14 );
// returns true
bool = isNumber( new Number( 3.14 ) );
// returns true
bool = isNumber( NaN );
// returns true
bool = isNumber( null );
// returns false
Tests if a value
is a primitive number
.
var Number = require( '@stdlib/number-ctor' );
var bool = isNumber.isPrimitive( 3.14 );
// returns true
bool = isNumber.isPrimitive( NaN );
// returns true
bool = isNumber.isPrimitive( new Number( 3.14 ) );
// returns false
Tests if a value
is a Number
object.
var Number = require( '@stdlib/number-ctor' );
var bool = isNumber.isObject( 3.14 );
// returns false
bool = isNumber.isObject( new Number( 3.14 ) );
// returns true
var Number = require( '@stdlib/number-ctor' );
var isNumber = require( '@stdlib/assert-is-number' );
var bool = isNumber( 5 );
// returns true
bool = isNumber( new Number( 5 ) );
// returns true
bool = isNumber( NaN );
// returns true
bool = isNumber( '5' );
// returns false
bool = isNumber( null );
// returns false
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-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">FAQs
Test if a value is a number.
We found that @stdlib/assert-is-number 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
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.