Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ts-is-number

paxa188748MIT1.1.0TypeScript support: included

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.

cast, check, coerce, coercion, finite, integer, is, isnan, is-nan, is-num, is-number, isnumber, isfinite, istype, kind, math, nan, num, number, numeric, parseFloat, parseInt, test, type, typeof, value

readme

ts-is-number

Workflow Codecov NPM Monthly Downloads Install Size Known Vulnerabilities

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