Skip to content
On this page

Validator

A rule to dynamically validate received data.

ValidationResult

A Validator have to respond with ValidationResult that could be one of the following values:

  • true or empty array — that means the data is valid
  • false or error string or non-empty array with error strings — that means the data is invalid

Overloads

Function

Validator can be a simple function that accepts { result, params } object and returns ValidationResult.

ts
const validator = ({ result, params }): ValidationResult => result[params.id] !== null;

Function with external source

Validator can be an object with field source which is any Store and fn witch is a function that accepts object { result, params } and the value of source and returns ValidationResult.

ts
const validator = {
  source: $externalStore,
  fn: ({ result, params }, externalSource): ValidationResult => result[params.id] !== null && result[externalSource.id] !== null,
};

Released under the MIT License.