primate
primate copied to clipboard
create `@primate/pema` and deprecate `@primate/types`
General purpose validation module.
import schema from "@primate/pema";
import array from "@primate/pema/array";
import file from "@primate/pema/file";
import number from "@primate/pema/number";
import string from "@primate/pema/string";
// options:
// strict: do not coerce string values
const form = schema({
id: number,
title: string,
tags: array(string).min(2),
content: file,
}, { strict: true });
form.validate({ id: "1", title: "foobar" });
// -> success: returns validated fields, coerced to correct type if not strict
// -> failure: throws, with validation errors
renamed in a31b9a3, schema validation itself pending