Validate with Pema
Pema stands Primate schema. Use pema for type-safe validation of data.
Pema provides composable validators for common types.
import pema from "pema";
import string from "pema/string";
import number from "pema/number";
const schema = pema({
name: string.min(1),
age: number.min(0),
});
const data = schema.parse({ name: "John", age: 30 });
const emailSchema = string.min(1).max(255).email();
const ageSchema = number.integer().min(0).max(150);
try {
schema.parse(input);
} catch (error) {
console.log(error.errors); // detailed errors
}