A JavaScript utility that reliably checks if a value is a finite number, handling edge cases like strings, NaN, and Infinity.
is-number is a JavaScript utility library that reliably checks whether a value is a finite number or a numeric string. It solves the problem of inconsistent number detection in JavaScript, where naive methods like `+value` or `Number()` can produce unexpected results for edge cases like empty strings, arrays, or NaN.
JavaScript and Node.js developers who need robust type validation for user input, parsed data, regex matches, or any scenario where distinguishing numbers from non-numbers is critical.
Developers choose is-number because it provides a performant, battle-tested solution that handles JavaScript's type coercion quirks consistently, reducing bugs and simplifying validation logic compared to manual checks.
JavaScript/Node.js utility. Returns true if the value is a number or string number. Useful for checking regex match results, user input, parsed strings, etc.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Correctly identifies tricky cases like +[] and +'' as non-numbers, avoiding false positives that naive casting methods produce, as highlighted in the README's examples.
Uses .isFinite internally and is 3x-4x faster for non-string/number values compared to previous versions, with benchmarks showing competitive speeds against parseFloat.
Recognizes numeric strings such as '5e3' and '0xff' as valid numbers, making it ideal for parsing user input or regex matches where type coercion is common.
Provides predictable results across different JavaScript runtimes, reducing bugs from inconsistent type checking in browsers or Node.js.
Version 5.0.0 removed support for instanceof checks, and v7.0.0 introduced refactors, which could disrupt projects not carefully managing dependencies or updates.
Only checks for finite numbers; lacks features for validating integers, ranges, or other types, forcing developers to use additional libraries for comprehensive validation.
The README doesn't mention TypeScript definitions, requiring users to rely on community-maintained types or manual declarations, adding setup overhead.