Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
RunKit + npm: joi
node v18.11.0
endpoint
share
tweet
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…
Clone and edit this document