Checks if the given value is Number (opens in a new tab) and it is finite.
⚠️
It only coerces the string value, not other types like null, boolean, etc.
Syntax
import { isNum } from '@opentf/std';
isNum(value: unknown, coerce = false): boolean;
Examples
// Invalid cases
// *************
isNum(undefined) //=> false
isNum(null) //=> false
isNum(true) //=> false
isNum(false) //=> false
isNum('') //=> false
isNum('a') //=> false
isNum('1') //=> false
isNum(1n) //=> false
isNum([]) //=> false
isNum({}) //=> false
isNum(Symbol(1)) //=> false
isNum(NaN) //=> false
isNum(Infinity) //=> false
isNum('1__000', true) //=> false
// Valid cases
// ***********
isNum(0) //=> true
isNum(-0) //=> true
isNum(1) //=> true
isNum(1.5) //=> true
isNum('1', true) //=> true
isNum('-1.1', true) //=> true
isNum(1_000) //=> true
isNum('1_000', true) //=> true
isNum(0xff) //=> true
isNum(0b11111111) //=> true
isNum(0.255e3) //=> true
isNum(Math.PI) //=> true