new RuleBase(ruleName)

Creates a new rule object. The rule instances should be frozen.

Parameter

Name Type Optional Description

ruleName

string

 

The name of the rule.

Throws

Argument error: The rule name must be a non-empty string.

Properties

read-only
message  string

Human-readable description of the rule failure.

read-only
priority  number

The priority of the rule. Higher number means higher priority.

Default value

read-only
ruleName  string

The name of the rule type. The default value usually the name of the constructor, without the Rule suffix.

read-only
stopsProcessing  boolean

Indicates whether processing of the rules for a property stops when the rule fails.

Default value

Methods

abstract
execute(inputs)

Abstract method to check if the rule is valid for the property.

Parameter

Name Type Optional Description

inputs

Array of any type

 

An array of the values of the required properties.

Throws

Not implemented error: The Rule.execute method is not implemented.

initialize(message[, priority][, stopsProcessing])

Sets the properties of the rule.

Parameters

Name Type Optional Description

message

string

 

Human-readable description of the rule failure.

priority

number

Yes

The priority of the rule.

stopsProcessing

boolean

Yes

Indicates the rule behavior in case of failure.

Throws

Argument error: The message must be a non-empty string.

Argument error: The last 3 arguments can be: a string as the message, an integer as the priority and a Boolean as the stopsProcessing argument.

abstract
result([message][, severity]) → object

Abstract method that returns the result of the rule checking.

Parameters

Name Type Optional Description

message

string

Yes

Human-readable description of the rule failure.

severity

bo.rules.RuleSeverity

Yes

The severity of the rule failure.

Throws

Not implemented error: The Rule.result method is not implemented.

Returns

object An object that describes the result of the rule checking.