使用 joi 进行条件验证:如果 属性 值大于 4,则执行一项操作,否则执行其他操作

Conditional validation with joi: Do one thing if a property value is greater than 4, otherwise do something else

在joi中,我知道我能做到:

.when('propertyName', {
  is: 4,
  then: Joi.number().required(),
  otherwise: Joi.number()
    .strip()
    .optional()
    .allow(''),
})

但是,我不想在 propertyName 等于 4 时触发“then”,而是想在 propertyName 大于 4 时触发它。我该怎么做?请注意 propertyName 可以是任何浮点数,而不仅仅是整数。

代替is: 4,做is: Joi.number().greater(4)