Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Validator

Validator

Aggregated validation of given validation rules against the tested value.

Hierarchy

  • Validator

Index

Constructors

Properties

Accessors

Methods

Constructors

  • new Validator(rules: ValidationRule[]): Validator
  • Parameters

    • rules: ValidationRule[]

      Validation rules. FIFO order, i.e. the rules will be tested from top to bottom.

    Returns Validator

Properties

_rules: ValidationRule[]

Accessors

  • get rules(): ValidationRule[]
  • Get the validator rules.

    Returns ValidationRule[]

Methods

  • errors(value: unknown, firstErrorOnly?: boolean): string[]
  • Get all validation errors, if any. Otherwise it returns empty array.

    Parameters

    • value: unknown

      Validated value.

    • firstErrorOnly: boolean = false

      Return only first error. Defaults to false.

    Returns string[]

  • valid(value: unknown): boolean
  • Validity predicate against the value.

    Parameters

    • value: unknown

      Validated value.

    Returns boolean

  • Validate against the value. If all rules are satisfied, the return value is true. Otherwise the return value is an error message of the failed rule.

    Parameters

    • value: unknown

      Validated value.

    • firstErrorOnly: boolean = true

      Return only first error. Defaults to true. If set to false, it returns an array of errors, if any.

    Returns ValidationResult

Generated using TypeDoc