Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

yup examples

node v0.12.18
endpointsharetweet
Define your schema by combining yup schema objects and use them to parse objects
var yup = require('yup') var contactSchema = yup.object({ name: yup.string() .required(), age: yup.number() .required() .positive() .integer(), email: yup.string() .email(), website: yup.string() .url(), createdOn: yup.date() .default(() => new Date()) }) contactSchema.cast({ name: 'jimmy', age: '24', createdOn: '2014-09-23T19:25:25Z' })
Or validate an object you already have.
let contact = { name: 'jimmy', age: 24, email: '[email protected]' } await contactSchema.isValid()
Or if you want to do both at the same time:
await contactSchema.validate(contact)
If something is wrong it will let throw an error!
contact = { name: 'jimmy', email: 'jdog' } await contactSchema.validate(contact, { abortEarly: false })
Loading…

no comments

    sign in to comment