Schema - Positive (Number)
The .positive
method is used to validate whether a given numeric value is greater than zero. It ensures that the input is a positive number, making it useful for scenarios where only positive values are valid, such as prices, quantities, or indexes.
This method is particularly useful for enforcing constraints where negative or zero values are invalid.
Example
Below is an example of how to use .positive
to validate whether a number is positive:
import { schema } from "vkrun"
const exampleSchema = schema().number().positive()
const validateA = exampleSchema.validate(1)
const validateB = exampleSchema.validate(0)
const validateC = exampleSchema.validate(-1)
console.log(validateA) // true
console.log(validateB) // false
console.log(validateC) // false