Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create @primate/schema and deprecate @primate/types #144

Open
terrablue opened this issue Jul 25, 2024 · 1 comment
Open

create @primate/schema and deprecate @primate/types #144

terrablue opened this issue Jul 25, 2024 · 1 comment
Labels
modules modules / ecosystem

Comments

@terrablue
Copy link
Contributor

General purpose validation module.

import schema from "@primate/schema";
import array from "@primate/schema/array";
import file from "@primate/schema/file";
import number from "@primate/schema/number";
import string from "@primate/schema/string";

// options:
// coerce: accept string values as valid by trying to coerce them first to target type
// strict: make sure all fields are present
const form = schema({
  id: number,
  title: string,
  tags: array.of(string).min(2),
  content: file,
}, { coerce: true, strict: false });

form.validate({ id: "1", title: "foobar" });
// -> success: returns validated fields, coerced to correct type if option
// `coerce` was set to true
// -> failure: throws, with validation errors
@terrablue terrablue added the modules modules / ecosystem label Jul 25, 2024
@terrablue
Copy link
Contributor Author

renamed in a31b9a3, schema validation itself pending

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modules modules / ecosystem
Projects
None yet
Development

No branches or pull requests

1 participant