Options
All
  • Public
  • Public/Protected
  • All
Menu
description

Rule class should be extended in order to create any rule.

abstract

Hierarchy

Index

Constructors

Properties

Methods

Constructors

constructor

  • new Rule(name: string): Rule
  • description

    Rule is an abstract class which must be extended in order to create a Rule. The subclass must have a validate function.

    Parameters

    • name: string

      Name of the Rule being defined.

    Returns Rule

Properties

Private name

name: string

Methods

formatMessage

  • description

    This formats the formatter string and includes the variables in it from values object. The variable key must be surrounded by % char.

    example
    const formattedString = formatMessage('%name% should not be empty.', { name: 'Email' });
    // Returns 'Email should not be empty.'
    example
    // If the message contains actual `%` symbol, it should be prefixed with `-`.
    const formattedString = formatMessage('%name% should be greater than 90-%.',
     { name: 'Marks' }
    );
    // Returns 'Marks should be greater than 90%.'

    Parameters

    • formatter: string

      The format string.

    • values: IRuleFormatterValues

      Object containing key and value pairs used in formatter string.

    Returns string

    Returns formatted string

validate

  • abstract
    description

    Validate the value and return the error string if there are any otherwise return undefined.

    Parameters

    Returns IRuleValidateReturn

    Value and error.

Generated using TypeDoc