SCHEMA
Validation Methods
.bigInt
.negative

Schema - Negative (BigInt)

The .negative method is used to validate whether a given BigInt value is less than zero. It ensures that the input is a negative BigInt, making it particularly useful for scenarios where only negative values are allowed, such as tracking debts, offsets, or temperature drops in systems using large integers.

This method is essential for enforcing constraints that disallow positive or zero values in BigInt data.


Example

Below is an example of how to use .negative to validate whether a BigInt value is negative:

import { schema } from "vkrun"
 
const exampleSchema = schema().bigInt().negative() // < 0n
 
const validateA = exampleSchema.validate(-1n)  // Valid, negative value
const validateB = exampleSchema.validate(0n)   // Invalid, zero is not negative
const validateC = exampleSchema.validate(1n)   // Invalid, positive value
 
console.log(validateA) // true
console.log(validateB) // false
console.log(validateC) // false
Copyright © 2024 MIT by Mario Elvio