ts-is-number
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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

Package Sidebar

Install

npm i ts-is-number

Weekly Downloads

2

Version

1.1.0

License

MIT

Unpacked Size

9.51 kB

Total Files

8

Last publish

Collaborators

  • paxa1887