Schema - Negative (Number)
The .negative
method is used to validate whether a given numeric value is less than zero. It ensures that the input is a negative number, making it useful for scenarios where only negative values are valid, such as temperature drops, debts, or offsets.
This method is particularly useful for enforcing constraints where positive or zero values are invalid.
Example
Below is an example of how to use .negative
to validate whether a number is negative:
import { schema } from "vkrun"
const exampleSchema = schema().number().negative()
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