Schema - Integer (Number)
The .integer
method is used to validate whether a given value is an integer. It ensures that the input is a whole number without any decimal places and can be further combined with additional validation methods to define specific rules for numeric inputs.
This method is particularly useful for validating data like IDs, counts, or any values that must be integers.
Example
Below is an example of how to use .integer
to validate whether a value is a valid integer:
import { schema } from "vkrun"
const exampleSchema = schema().number().integer()
const validateA = exampleSchema.validate(123) // Valid integer
const validateB = exampleSchema.validate(123.5) // Invalid integer (float)
console.log(validateA) // true
console.log(validateB) // false