ts-is-number
v1.1.0
Published
The ts-is-number a utility npm package that checks if a given input is a valid finite number or a string that can be converted to a valid finite number.
Downloads
49
Maintainers
Readme
ts-is-number
The ts-is-number a utility npm package that checks if a given input is a valid finite number or a string that can be converted to a valid finite number.
Usage:
Here's how you can import and use the isValidNumber function in your TypeScript or JavaScript project:
import isValidNumber from 'ts-is-number';
console.log(isValidNumber(123));
Overview
Method:
isValidNumber(num: string | number | boolean | object | null | undefined): boolean
Parameters
num
: The input parameter which can be a string, number, boolean, object, null, or undefined.
Returns
Returns true if the input is a valid finite number or a string that can successfully be converted to a valid finite number, otherwise returns false.
Examples
console.log(isValidNumber(123)); // returns true
console.log(isValidNumber('123')); // returns true
console.log(isValidNumber('123a')); // returns false
console.log(isValidNumber(NaN)); // returns false
console.log(isValidNumber(undefined)); // returns false