Schema - NotEqual
The .notEqual
method is used to validate whether a given value does not match a specified reference value. It ensures that the input value is different from the provided value, making it useful for scenarios where strict inequality is required, such as confirming values are not equal to specific reference values or preventing duplicates.
This method is essential when you need to enforce that the input value must not match the value you're comparing it to, including complex objects or nested structures.
Example: Basic Validation with .notEqual
Below is an example of how to use .notEqual
to validate whether a value does not match a reference value:
import { schema } from "vkrun"
const exampleSchema = schema().notEqual({
keyA: "any value",
keyB: false,
keyC: [1, 2, 3]
})
const validateA = exampleSchema.validate({
keyA: "any value",
keyB: false,
keyC: [1, 2, 4] // different array
})
const validateB = exampleSchema.validate({
keyA: "any value",
keyB: false,
keyC: [1, 2, 3]
})
console.log(validateA) // true
console.log(validateB) // false