Registry / data / isnumber

isnumber

JSON →
library1.0.0jsnpmunverified

The `isNumber` package provides a minimal, single-line utility function to determine if a value represents a finite number. Currently at version 1.0.0, this package is highly stable with an extremely infrequent release cadence, reflecting its narrow and well-defined scope (last published 13 years ago). Its key differentiator lies in its approach to type coercion: unlike `Number.isFinite()` which strictly checks the type, `isNumber` uses `parseFloat()` to first attempt to parse the input into a number. It then verifies that the parsed result is a finite number and not `NaN`. This makes it suitable for scenarios where number-like strings (e.g., "123.45") should be treated as valid numbers, but it also introduces specific behaviors for other complex types that are not strictly numbers or strings.

npm install isnumber
INSTALL
IMPORT
SIG · ISNUMBER
I
isnumber
datajavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

isNumber
import isNumber from 'isnumber'
import { isNumber } from 'isnumber'
The package uses CommonJS `module.exports = function(...)` which translates to a default import in ESM contexts. Named imports will fail.
isNumber (CommonJS)
const isNumber = require('isnumber')
Standard CommonJS import for Node.js environments. This is how the package is originally structured and shown in the README.
Type of isNumber
type IsNumberFn = typeof isNumber;
For TypeScript users, the function's type can be inferred directly. The package does not ship separate type definitions, so rely on inference or a global `@types/isnumber` if available (none officially shipped).

Demonstrates `isNumber` with various inputs, highlighting its string parsing and unique handling of single-element arrays.

import isNumber from 'isnumber'; console.log('--- Valid Numbers (including coerced strings) ---'); console.log('isNumber(13):', isNumber(13)); // true console.log('isNumber("1241.12"):', isNumber("1241.12")); // true console.log('isNumber(0xff):', isNumber(0xff)); // true (0xff is 255) console.log('isNumber("5e3"):', isNumber("5e3")); // true (5e3 is 5000) console.log('\n--- Invalid Numbers ---'); console.log('isNumber(Infinity):', isNumber(Infinity)); // false console.log('isNumber("cat"):', isNumber("cat")); // false console.log('isNumber({foo: "bar"}):', isNumber({foo: "bar"})); // false console.log('isNumber(NaN):', isNumber(NaN)); // false console.log('isNumber(null):', isNumber(null)); // false console.log('isNumber(undefined):', isNumber(undefined)); // false console.log('isNumber(""):', isNumber("")); // false console.log('isNumber([]):', isNumber([])); // false console.log('\n--- Common Gotchas ---'); console.log('isNumber([1]):', isNumber([1])); // true (due to parseFloat([1]) === 1) console.log('isNumber(new Number(42)):', isNumber(new Number(42))); // true (Number objects are parsed correctly)
Debug
Known issues
gotchaThe `isNumber` function performs internal type coercion using `parseFloat()`. This means that values which are not strictly numbers or strings can sometimes be coerced into a valid number. For example, `isNumber([1])` returns `true` because `parseFloat([1])` evaluates to `1`.
fix
If strict type checking for `number` primitives is required, use `typeof value === 'number' && Number.isFinite(value)` instead. Understand the `parseFloat()` behavior for non-string/non-number inputs if you intend to use `isNumber`.
affects: >=1.0.0
gotcha`isNumber` behaves differently from the native `Number.isFinite()`. While `isNumber("123")` returns `true` by parsing the string, `Number.isFinite("123")` returns `false` as it does not coerce non-number types. Be aware of this distinction when choosing a utility.
fix
Choose the utility that matches your intended coercion behavior. For strict type and value checking, use `Number.isFinite()`. For forgiving string-to-number parsing, `isNumber` is appropriate.
affects: >=1.0.0
deprecatedThe `isnumber` package has not been updated in 13 years (since August 2013). While its functionality is simple and stable, it may not be actively maintained or respond to modern JavaScript ecosystem changes or new edge cases. Consider using more actively maintained alternatives or native JavaScript methods if long-term support is critical.
fix
Evaluate newer, similar packages like `is-number` (by jonschlinkert or ultirequiem) which offer more recent updates, broader test coverage, or specific type-guard features, or rely on built-in `Number.isFinite()` and explicit parsing functions.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: isnumber_1.isNumber is not a function
Attempting to use `import { isNumber } from 'isnumber'` for a package that provides a default export (CommonJS `module.exports`).
fix
Change the import statement to `import isNumber from 'isnumber';` to correctly import the default export.
ReferenceError: require is not defined (in ESM context)
Using `const isNumber = require('isnumber')` in a modern ES Module (ESM) environment where `require` is not globally available.
fix
For ESM environments, use `import isNumber from 'isnumber';`. If you must use `require` in ESM, consider a CommonJS wrapper or a bundler that handles interoperability.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
isnumber — npm install isnumber · libregistry