safe-evaluate-expression
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -5,2 +5,4 @@ # Changelog | ||
### [1.1.2](https://github.com/ttessarolo/safe-evaluate-expression/compare/v1.1.1...v1.1.2) (2020-11-12) | ||
### [1.1.1](https://github.com/ttessarolo/safe-evaluate-expression/compare/v1.1.0...v1.1.1) (2020-11-12) | ||
@@ -7,0 +9,0 @@ |
{ | ||
"name": "safe-evaluate-expression", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Small library to dynamically create and evaluate expression with multiple parameters (even undefined)", | ||
@@ -12,3 +12,4 @@ "main": "index.js", | ||
"push": "git push --follow-tags", | ||
"release": "npm run test && npm run commit && npm run version && npm run push" | ||
"publish": "npm publish", | ||
"release": "npm run test && npm run commit && npm run version && npm run push && npm publish" | ||
}, | ||
@@ -15,0 +16,0 @@ "husky": { |
@@ -10,3 +10,3 @@ # safe-evaluate-expression | ||
Small library to dynamically create and evaluate expression with multiple parameters (even undefined). **To handle more sofisticate use cases is provided a [Factory](#factory) functionality to build evaluate functions with some spice 🔥**. | ||
Small library to dynamically create and evaluate expression with multiple parameters (even undefined). **To handle more sofisticate use cases is provided a [Factory](#factory) functionality to build evaluate functions with some spice 🔥** | ||
@@ -28,4 +28,4 @@ _It also offer an ancillary function to protect lambda function to undefined params inputs._ | ||
```javascript | ||
const evaluate = require("safe-evaluate-expression"); | ||
evaluate("a > 1", { a: 3 }); // -> true | ||
const evaluate = require('safe-evaluate-expression'); | ||
evaluate('a > 1', { a: 3 }); // -> true | ||
``` | ||
@@ -38,3 +38,3 @@ | ||
```javascript | ||
const evaluate = require("safe-evaluate-expression"); | ||
const evaluate = require('safe-evaluate-expression'); | ||
@@ -51,10 +51,10 @@ const operators = { | ||
evaluate("isEqual(a,b)", params); // -> true | ||
evaluate("isEqual(a,c)", params); // -> false | ||
evaluate("isEqual(a,notDefined)", params); // -> false | ||
evaluate("isUndefined(a)", params); // -> false | ||
evaluate("isUndefined(notDefined)", params); // -> true | ||
evaluate('isEqual(a,b)', params); // -> true | ||
evaluate('isEqual(a,c)', params); // -> false | ||
evaluate('isEqual(a,notDefined)', params); // -> false | ||
evaluate('isUndefined(a)', params); // -> false | ||
evaluate('isUndefined(notDefined)', params); // -> true | ||
// It works also with infinite nested conditions | ||
evaluate("(isUndefined(notDefined) || (isGreater(c, a) && isLower(b, c))) && isEqual(a,1)", params); // -> true | ||
evaluate('(isUndefined(notDefined) || (isGreater(c, a) && isLower(b, c))) && isEqual(a,1)', params); // -> true | ||
``` | ||
@@ -69,3 +69,3 @@ | ||
```javascript | ||
const { factory, operators } = require("safe-evaluate-expression"); | ||
const { factory, operators } = require('safe-evaluate-expression'); | ||
const evaluate = factory({ operators, multipleParams: true, translateLogical: true }); | ||
@@ -75,6 +75,6 @@ | ||
const list = { k: 3, z: 4 }; | ||
const map = new Map([["pi", 3.14]]); | ||
const map = new Map([['pi', 3.14]]); | ||
const expression1 = "isLower(x,z)"; | ||
const expression2 = "isLower(k,y)"; | ||
const expression1 = 'isLower(x,z)'; | ||
const expression2 = 'isLower(k,y)'; | ||
@@ -86,3 +86,3 @@ evaluate(expression1, metadata, list); // -> true | ||
const expression3 = "isLower(notDefined,z)"; // put a not defined value | ||
const expression3 = 'isLower(notDefined,z)'; // put a not defined value | ||
@@ -98,2 +98,4 @@ evaluate(expression3, metadata, list); | ||
The Factory used without parameters gives the same results as the "evaluate" function. However, it is possible to create new "evaluate" functions with much more spice by setting the Factory parameters correctly. All parameters are optional. The parameter "multipleParams" allows you to pass various objects (or Maps) to the evaluation function, thus avoiding the need to deconstruct operators and values in a single object. It is important to remember that the parameter "operators", if specified, must contain an object with all the functions you want to define as operators. This object can be plugged in-scope within the evaluation function to optimise performance. However, if the "operators" functions depend on the external libraries, you should not set the "operatorsInScope" functionality. | ||
<table> | ||
@@ -148,3 +150,3 @@ <tr> | ||
```javascript | ||
const { safeLambda } = require("safe-evaluate-expression"); | ||
const { safeLambda } = require('safe-evaluate-expression'); | ||
@@ -151,0 +153,0 @@ const lambda = (a, b, c) => a + b + c; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
151
30838
20