UNPKG

rules-engine-lib

Version:

A Ts rules engine lib

73 lines (69 loc) 1.65 kB
// Generated by dts-bundle-generator v9.5.1 export type Primitive = string | number | boolean | null; export interface Operator { between: [ number, number ]; contains: string; includes: string[] | number[]; greaterThan: number; lessThan: number; in: string[] | number[]; matches: RegExp; not: string | { in?: number[] | string[]; includes?: number[] | string[]; }; } export interface IFAND { AND: Record<string, Primitive | Partial<Operator>>; } export interface IFOR { OR: Record<string, Primitive | Partial<Operator>>; } export interface Logic { IF: IFAND | IFOR | Record<string, Primitive | Partial<Operator>>; THEN: { [key: string]: Primitive | unknown[] | Record<string, unknown>; }; OTHERWISE?: { [key: string]: Primitive | unknown[] | Record<string, unknown>; }; WEIGHT?: number; } export interface Conditions { [key: string]: Logic; } export interface Options { caseSensitive?: boolean; modifyDataset?: boolean; } declare class RulesEngine { private conditions; private options; constructor(conditions: Conditions, options?: Options); run(dataset: Record<string, unknown>): { [key: string]: Record<string, unknown> | Primitive | unknown[]; } | undefined; private modifyData; private executeIF; private executeLogicalOperation; private executeBetween; private executeContains; private executeIncludes; private executeGreaterThan; private executeLessThan; private executeMatches; private executeNot; /** * * @description Sort conditions by weight and return array of conditions id * @returns {string[]} */ private sortByWeights; } export { RulesEngine as default, }; export {};