Skip to main content

Validate

Vality exposes one validation method to rule them all: validate(eny: Eny, value: unknown): ValidationResult. It takes in an eny (will be explained soon) and a value and returns an object that contains the result of the validation.

ts
import { vality, validate } from "vality";
 
result = validate({
name: vality.string,
age: vality.number,
address: {
street: vality.string,
city: vality.string,
country: vality.string,
},
}, {
name: "Larl",
age: 42,
address: {
street: "Main Street",
city: "Dummytown",
country: "USA",
},
});
 
// Yields:
result = { valid: true, errors: [] }
ts
import { vality, validate } from "vality";
 
result = validate({
name: vality.string,
age: vality.number,
address: {
street: vality.string,
city: vality.string,
country: vality.string,
},
}, {
name: "Larl",
age: 42,
address: {
street: "Main Street",
city: "Dummytown",
country: "USA",
},
});
 
// Yields:
result = { valid: true, errors: [] }