Summary
Joi 5.0.0 changes a few default behaviors that were surprising to a few users.
- Upgrade time: low to none - most people shouldn't have to do anything
- Complexity: low - the new defaults will probably already be what you want, otherwise it will be just a function call
- Risk: low - if you don't fall into the following edge cases, it should be a very low risk upgrade
Breaking changes
number() rejects Infinity and -Infinity by default. If you do want Infinity to be accepted as a number, you have to use number().allow(Infinity, -Infinity)
array() rejects sparse arrays by default (arrays with undefined values), this can still be enabled by calling array().sparse().
array().unique() will now perform a deep comparison where necessary, previous implementation only compared numbers and strings. Be aware that doing so will indeed have a cost in performance.
number().precision() will convert numbers to the given precision if convert: true.
New features
array().single() when convert: true will try to wrap your value inside an array if it doesn't validate as it is, especially useful when you want to accept a type or an array of that type.
- the context will now be returned in the errors allowing you have a better insight into the parameters of the rule that triggered the error.
Summary
Joi 5.0.0 changes a few default behaviors that were surprising to a few users.
Breaking changes
number()rejectsInfinityand-Infinityby default. If you do wantInfinityto be accepted as a number, you have to usenumber().allow(Infinity, -Infinity)array()rejects sparse arrays by default (arrays with undefined values), this can still be enabled by callingarray().sparse().array().unique()will now perform a deep comparison where necessary, previous implementation only compared numbers and strings. Be aware that doing so will indeed have a cost in performance.number().precision()will convert numbers to the given precision ifconvert: true.New features
array().single()whenconvert: truewill try to wrap your value inside an array if it doesn't validate as it is, especially useful when you want to accept a type or an array of that type.