Schema - Positive (BigInt)
The .positive
method is used to validate whether a given BigInt
value is greater than zero. It ensures that the input is a positive BigInt
, making it particularly useful for scenarios where only positive values are allowed, such as quantities, indexes, or counts in large-scale systems.
This method is crucial for enforcing constraints that disallow negative or zero values in BigInt
data.
Example
Below is an example of how to use .positive
to validate whether a BigInt
value is positive:
import { schema } from "vkrun"
const exampleSchema = schema().bigInt().positive() // > 0n
const validateA = exampleSchema.validate(1n) // Valid, positive value
const validateB = exampleSchema.validate(0n) // Invalid, zero is not positive
const validateC = exampleSchema.validate(-1n) // Invalid, negative value
console.log(validateA) // true
console.log(validateB) // false
console.log(validateC) // false