Validation/Since
1.38.0isPositive
Checks whether a value is a positive number.
isPositive(value):booleanBehavior
The function first checks that the value type is number, then verifies that it is greater than zero.
Zero Handling
Zero is not considered positive because the comparison uses value > 0.
Type guard
The function narrows unknown values to number when it returns true.
Parameters
valueunknownrequiredThe value to check.
Returns
booleanReturns true when the value is a number greater than zero; otherwise returns false.
Examples
01
Positive numbers
Returns true for numbers greater than zero.
TypeScript
isPositive(10);
// true
isPositive(0.5);
// true02
Zero and negative numbers
Zero and negative numbers are not considered positive.
TypeScript
isPositive(0);
// false
isPositive(-5);
// false03
Non-number values
Non-number values return false.
TypeScript
isPositive("10");
// false
isPositive(null);
// false
isPositive(true);
// false04
Special numbers
NaN and Infinity behavior follows JavaScript number comparisons.
TypeScript
isPositive(NaN);
// false
isPositive(Infinity);
// trueBuilt with@cyref/js·Official documentation