npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@alwatr/is-number

v5.7.21

Published

A simple utility to Check the value is number or can convert to a number, for example string ' 123 ' can be converted to 123.

Downloads

3,461

Readme

is-number

A lightweight, high-performance utility to check if a value is a number or can be converted to a number.

Installation

yarn add @alwatr/is-number
# or
npm install @alwatr/is-number

Usage

import {isNumber, toNumber, isFiniteNumber} from '@alwatr/is-number';

// Check if a value is a number
isNumber(123);       // true
isNumber('123');     // true
isNumber('abc');     // false

// Convert a value to a number if possible
toNumber(123);       // 123
toNumber('123');     // 123 
toNumber('abc');     // null

// Check if a value is a finite number (without type coercion)
isFiniteNumber(123); // true
isFiniteNumber(Infinity); // false
isFiniteNumber('123'); // false (no coercion)

API

isNumber(value: unknown): boolean

Checks if the value is a number or can be converted to a number.

toNumber(value: unknown): number | null

Converts the value to a number if possible, otherwise returns null.

isFiniteNumber(value: unknown): boolean

A cross-browser polyfill for Number.isFinite. Unlike the global isFinite, this doesn't coerce values to numbers before checking.

Why is this needed?

JavaScript type behavior can be confusing. This library helps to simplify number validation:

console.log(typeof '123');     // 'string'
console.log(+[]);              // 0
console.log(+'');              // 0
console.log(+'   ');           // 0
console.log(typeof NaN);       // 'number'
console.log(typeof Infinity);  // 'number'

isNumber Examples

Returns true

isNumber(5e3);               // true
isNumber(0xff);              // true
isNumber(-1.1);              // true
isNumber(0);                 // true
isNumber(1);                 // true
isNumber(1.1);               // true
isNumber('-1.1');            // true
isNumber('0');               // true
isNumber('0xff');            // true
isNumber('1');               // true
isNumber('1.1');             // true
isNumber('5e3');             // true
isNumber('012');             // true
isNumber(' 123 ');           // true

Returns false

isNumber(Infinity);          // false
isNumber(NaN);               // false
isNumber(null);              // false
isNumber(undefined);         // false
isNumber('');                // false
isNumber('   ');             // false
isNumber('foo');             // false
isNumber('123foo');          // false
isNumber([1]);               // false
isNumber([]);                // false
isNumber(function () {});    // false
isNumber({});                // false

toNumber Examples

Returns a number

toNumber(5e3);               // 5000
toNumber(0xff);              // 255
toNumber(-1.1);              // -1.1
toNumber(0);                 // 0
toNumber(1);                 // 1
toNumber('-1.1');            // -1.1
toNumber('0');               // 0
toNumber('0xff');            // 255
toNumber('5e3');             // 5000
toNumber(' 123 ');           // 123

Returns null

toNumber(Infinity);          // null
toNumber(NaN);               // null
toNumber(null);              // null
toNumber(undefined);         // null
toNumber('');                // null
toNumber('   ');             // null
toNumber('foo');             // null
toNumber('123foo');          // null
toNumber([1]);               // null
toNumber([]);                // null
toNumber(function () {});    // null
toNumber({});                // null

Sponsors

The following companies, organizations, and individuals support Nanolib ongoing maintenance and development. Become a Sponsor to get your logo on our README and website.

Contributing

Contributions are welcome! Please read our contribution guidelines before submitting a pull request.