Schema - Function
The .function
method is used to validate whether a given value is of type function
. It ensures that the input is a valid function, making it useful for validating function-type data such as event handlers, callbacks, or any other function-based logic in your application.
This method is crucial when you need strict type validation, ensuring that only valid functions are allowed.
Examples
.validate()
Validates if the value is a function:
import { schema } from "vkrun"
const schemaValidation = schema().function()
const validateA = schemaValidation.validate(() => {}) // Valid function
const validateB = schemaValidation.validate("test") // Invalid, string is not a function
console.log(validateA) // true
console.log(validateB) // false