Skip to content

5.0.0 Release Notes #501

@Marsup

Description

@Marsup

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

  1. 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)
  2. array() rejects sparse arrays by default (arrays with undefined values), this can still be enabled by calling array().sparse().
  3. 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.
  4. 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.

Metadata

Metadata

Assignees

Labels

breaking changesChange that can breaking existing coderelease notesMajor release documentation

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions