RunKit + npm: joi

node v18.11.0
endpointsharetweet
const Joi = require("joi"); const schema = Joi.object({ a: Joi.number().required(), b: Joi.number().required(), c: Joi.number().required(), d: Joi.number().when(Joi.valid(Joi.x('{ if(a >= 10 && b < 5 || c == 2, d, null) }')), { then: Joi.number().min(42), }) }); console.info(schema.validate({ a: 1, b: 2, c: 3, d: 4 })) console.info(schema.validate({ a: 10, b: 2, c: 3, d: 4 })) console.info(schema.validate({ a: 10, b: 10, c: 2, d: 4 })) console.info(schema.validate({ a: 10, b: 2, c: 2, d: 42 }))
Created from: https://npm.runkit.com/joi
Loading…