Validator

Class Name Validator
Extends Logger
Source validator.ts
Examples validator.spec.ts

The Validator module can be used to verfiy given JSON schemas.


constructor

new Validator(options);

Creates a new Validator instance.

Parameters

  1. options - ValidatorOptions: options for Validator constructor.
    • schema - any: the validation schema definition
    • log - Function (optional): function to use for logging: (message, level) => {...}
    • logLevel - LogLevel (optional): messages with this level will be logged with log
    • logLog - LogLogInterface (optional): container for collecting log messages
    • logLogLevel - LogLevel (optional): messages with this level will be pushed to logLog

Returns

Validator instance

Example

const nameResolver = new Validator({
    schema
  });

validate

validator.validate(data);

validate a given data object with the instantiated schema

Parameters

  1. data - any: to be validated data

Returns

bool | strings[]: true if data is valid, array of object if validation is failed


getErrorsAsText

validator.getErrorsAsText();

returns errors as text if previous validation was failed

Returns

string: all previous validation errors concatenated as readable string