Skip to content

renrenche/service-rule-evaluator

Repository files navigation

service-rule-evaluator NPM version Build Status Dependency Status Coverage percentage

service rule evaluator

Installation

$ npm install --save @rrc/service-rule-evaluator
or
$ yarn add @rrc/service-rule-evaluator -S

Usage

const evaluator = require('@rrc/service-rule-evaluator');

// 判断是否匹配
evaluator.isMatch('123', { eq: 123 });     // true
evaluator.isMatch('123', { lte: 123 });    // true
evaluator.isMatch('123', { gte: 123 });    // true

// 解释和执行
evaluator.evaluate('count=count+1', { count: 20 });     // { count: 21 }
evaluator.evaluate('count=count  -1', { count: 20 };    // { count: 19 }
evaluator.evaluate('count=count*  3', { count: 20 });   // { count: 60 }
evaluator.evaluate('count=count  /  2', { count: 20 }); // { count: 10 }
evaluator.evaluate('count = Math.max(count/increment, increment*2);', { count: 20, increment: 2 });     // { count: 10 }

License

MIT © wangshijun

About

规则判断引擎,结合 `service-rule-parser` 使用

Resources

License

Stars

Watchers

Forks

Packages

No packages published