UNPKG

@inixiative/json-rules

Version:

TypeScript-first JSON rules engine with intuitive syntax and detailed error messages

84 lines (80 loc) 2.01 kB
declare enum Operator { equals = "equals", notEquals = "notEquals", lessThan = "lessThan", lessThanEquals = "lessThanEquals", greaterThan = "greaterThan", greaterThanEquals = "greaterThanEquals", contains = "contains", notContains = "notContains", in = "in", notIn = "notIn", matches = "matches", notMatches = "notMatches", between = "between", notBetween = "notBetween", isEmpty = "isEmpty", notEmpty = "notEmpty", exists = "exists", notExists = "notExists", startsWith = "startsWith", endsWith = "endsWith" } declare enum ArrayOperator { all = "all", any = "any", none = "none", atLeast = "atLeast", atMost = "atMost", exactly = "exactly", empty = "empty", notEmpty = "notEmpty" } declare enum DateOperator { before = "before", after = "after", onOrBefore = "onOrBefore", onOrAfter = "onOrAfter", between = "between", notBetween = "notBetween", dayIn = "dayIn",// e.g., ['monday', 'tuesday', 'friday'] dayNotIn = "dayNotIn" } type Rule = { field: string; operator: Operator; value?: any; path?: string; error?: string; }; type ArrayRule = { field: string; arrayOperator: ArrayOperator; condition?: Condition; count?: number; error?: string; }; type DateRule = { field: string; dateOperator: DateOperator; value?: any; path?: string; error?: string; }; type All = { all: Condition[]; error?: string; }; type Any = { any: Condition[]; error?: string; }; type IfThenElse = { if: Condition; then: Condition; else?: Condition; error?: string; }; type Condition = Rule | ArrayRule | DateRule | All | Any | IfThenElse | boolean; declare const check: (conditions: Condition, data: any, context?: any) => boolean | string; export { type All, type Any, ArrayOperator, type ArrayRule, type Condition, DateOperator, type DateRule, type IfThenElse, Operator, type Rule, check };