We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The text was updated successfully, but these errors were encountered:
let userSchema = object({ name: string().required(), age: number().required().positive().integer(), email: string().email(), website: string().url().nullable(), createdOn: date().default(() => new Date()), }); // parse and assert validity const user = await userSchema.validate(await fetchUser()); type User = InferType<typeof userSchema>; /* { name: string; age: number; email?: string | undefined website?: string | null | undefined createdOn: Date }*/
test
const order = object({ no: number().required(). sku: string().test({ name: 'is-sku', skipAbsent: true, test(value, ctx) { if (!value.startsWith('s-')) { return ctx.createError({ message: 'SKU missing correct prefix' }) } if (!value.endsWith('-42a')) { return ctx.createError({ message: 'SKU missing correct suffix' }) } if (value.length < 10) { return ctx.createError({ message: 'SKU is not the right length' }) } return true } }) }) order.validate({ no: 1234, sku: 's-1a45-14a' })
Sorry, something went wrong.
No branches or pull requests
What is Yup and its applications
The text was updated successfully, but these errors were encountered: