Socket
Socket
Sign inDemoInstall

@stdlib/assert-is-number

Package Overview
Dependencies
4
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stdlib/assert-is-number


Version published
Maintainers
4
Created

Package description

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

Readme

Source

isNumber

NPM version Build Status Coverage Status dependencies

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 );
// returns true

bool = isNumber( new Number( 3.14 ) );
// returns true

bool = isNumber( NaN );
// returns true

bool = isNumber( null );
// returns false
isNumber.isPrimitive( value )

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
isNumber.isObject( value )

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

Examples

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

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 © 2016-2021. The Stdlib Authors.

Keywords

FAQs

Last updated on 14 Jun 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc