1 | # ts-is-number
|
2 |
|
3 | ![Workflow](https://github.com/paxa1887/ts-is-number/actions/workflows/main.yml/badge.svg)
|
4 | [![Codecov](https://codecov.io/gh/paxa1887/ts-is-number/graph/badge.svg?token=S6U22KXOKW)](https://codecov.io/gh/paxa1887/ts-is-number) [![NPM Monthly Downloads](https://img.shields.io/npm/dm/ts-is-number.svg?style=flat)](https://www.npmjs.com/package/ts-is-number)
|
5 | [![Install Size](https://packagephobia.com/badge?p=ts-is-number)](https://packagephobia.com/result?p=ts-is-number) [![Known Vulnerabilities](https://snyk.io/test/github/paxa1887/ts-is-number/badge.svg)](https://snyk.io/test/github/paxa1887/ts-is-number)
|
6 |
|
7 | 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.
|
8 |
|
9 | # Usage:
|
10 |
|
11 | Here's how you can import and use the isValidNumber function in your TypeScript or JavaScript project:
|
12 |
|
13 | ```JavaScript
|
14 | import isValidNumber from 'ts-is-number';
|
15 | console.log(isValidNumber(123));
|
16 | ```
|
17 |
|
18 | # Overview
|
19 |
|
20 | ## Method:
|
21 |
|
22 | isValidNumber(num: string | number | boolean | object | null | undefined): boolean
|
23 |
|
24 | ### Parameters
|
25 |
|
26 | - `num`: The input parameter which can be a string, number, boolean, object, null, or undefined.
|
27 |
|
28 | ### Returns
|
29 |
|
30 | 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.
|
31 |
|
32 | ### Examples
|
33 |
|
34 | ```JavaScript
|
35 | console.log(isValidNumber(123)); // returns true
|
36 | console.log(isValidNumber('123')); // returns true
|
37 | console.log(isValidNumber('123a')); // returns false
|
38 | console.log(isValidNumber(NaN)); // returns false
|
39 | console.log(isValidNumber(undefined)); // returns false
|
40 | ```
|