isNumber

Check if the given value is a number.

Usage Scenarios

  • Type Checking: Verify if a value is a number before mathematical operations.
  • Input Validation: Validate numeric user input or API responses.
  • Type Narrowing: Narrow variable types in TypeScript.

Examples

import { isNumber } from 'funtool';

isNumber(123); // ✅ true
isNumber('123'); // ❌ false
isNumber(NaN); // ✅ true
isNumber(Infinity); // ✅ true

Signature

function isNumber(v: any): boolean

Parameters

  • v (any): The value to test if it is a number.

Returns

  • (boolean): Returns true if the value is a number, otherwise returns false.