UNPKG

@ivandt/json-rules

Version:

Rule parsing engine for JSON rules

61 lines (60 loc) 2.5 kB
import { Rule } from "../types"; import { Builder } from "../builder"; import { ValidationResult } from "./validator"; export declare class JsonRules { #private; /** * Returns a rule builder class instance. * Allows for the construction of rules using a fluent interface. */ builder(): Builder; /** * Evaluates a rule against a set of criteria and returns the result. * If the criteria is an array (indicating multiple criteria to test), * the rule will be evaluated against each item in the array and * an array of results will be returned. * * @param rule The rule to evaluate. * @param criteria The criteria to evaluate the rule against. * @param trustRule Set true to avoid validating the rule before evaluating it (faster). * @throws RuleError if the rule is invalid. */ evaluate<T>(rule: Rule, criteria: object | object[], trustRule?: boolean): T | boolean; /** * Takes in a rule as a parameter and returns a ValidationResult * indicating whether the rule is valid or not. * * Invalid rules will contain an error property which contains a message and the element * that caused the validation to fail. * * @param rule The rule to validate. */ validate(rule: Rule): ValidationResult; /** * Returns a rule builder class instance. * Allows for the construction of rules using a fluent interface. */ static builder(): Builder; /** * Evaluates a rule against a set of criteria and returns the result. * If the criteria is an array (indicating multiple criteria to test), * the rule will be evaluated against each item in the array and * an array of results will be returned. * * @param rule The rule to evaluate. * @param criteria The criteria to evaluate the rule against. * @param trustRule Set true to avoid validating the rule before evaluating it (faster). * @throws RuleError if the rule is invalid. */ static evaluate<T>(rule: Rule, criteria: object | object[], trustRule?: boolean): T | boolean; /** * Takes in a rule as a parameter and returns a ValidationResult * indicating whether the rule is valid or not. * * Invalid rules will contain an error property which contains a message and the element * that caused the validation to fail. * * @param rule The rule to validate. */ static validate(rule: Rule): ValidationResult; }