Yup

node v6.12.2
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…

no comments

    sign in to comment