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

node v6.17.1
version: 1.1.2
endpointsharetweet
const { object, string, number, date } = require('yup') const contactSchema = object({ name: string() .required(), age: number() .required() .positive() .integer(), email: string() .email(), website: string() .url(), createdOn: 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: 'jdog@cool.biz' } await contactSchema.isValid(contact)
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…

2 comments

  • posted 5 years ago by astraube
    beautifull
  • posted 3 years ago by varun-nambiar
    very *beautiful

sign in to comment