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: master
endpointsharetweet
const yup = require('yup') const contactSchema = yup.object({ name: yup.string() .required(), nrOfApples: yup .number() .min(0) .max(999) .nullable(true) // checking self-equality works for NaN, transforming it to null .transform((_, val) => val ? Number(val) : null) // .transform((_, val) => val === val ? val : null) }) const string = await contactSchema.isValid({ name: 'jimmy', nrOfApples: 'test', }) const number = await contactSchema.isValid({ name: 'jimmy', nrOfApples: 24, }) const nan = await contactSchema.isValid({ name: 'jimmy', nrOfApples: NaN, }) const undef = await contactSchema.isValid({ name: 'jimmy', nrOfApples: undefined }) const nul = await contactSchema.isValid({ name: 'jimmy', nrOfApples: null }) console.log({ string, number, nan, undef, nul })
Loading…

no comments

    sign in to comment