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

Ian/validate #434

Merged
merged 7 commits into from
Feb 5, 2025
Merged

Ian/validate #434

merged 7 commits into from
Feb 5, 2025

Conversation

ianmacartney
Copy link
Collaborator

Add a validate(validator, value) helper


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ianmacartney ianmacartney requested a review from ldanilek February 4, 2025 03:14
Copy link
Contributor

@ldanilek ldanilek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@@ -666,6 +669,9 @@ const balanceAndEmail = pick(vv.doc("accounts").fields, ["balance", "email"]);

// A validator for all the fields except balance.
const accountWithoutBalance = omit(vv.doc("accounts").fields, ["balance"]);

// Validate against a validator. Can optionally throw on error.
validate(balanceAndEmail, { balance: 123n, email: "[email protected]" });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth putting a oneline v.id warning here?

});

test("includes path in error messages", () => {
const complexValidator = object({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the array pathPrefix is also interesting

@ianmacartney ianmacartney merged commit fcc216b into main Feb 5, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants