safe-evaluate-expression
Advanced tools
Comparing version 1.0.8 to 1.1.0
@@ -18,6 +18,6 @@ const { factory, operators } = require("../"); | ||
evaluate(expression3, metadata, list); | ||
evaluate(expression3, metadata, list); // -> false | ||
evaluate(`${expression3} AND ${expression2}`, metadata, list); // -> false | ||
evaluate(`(isLower(x,z) AND isLower(k,y) OR (isLower(z,P) AND NOT isLower(P,k)))`, metadata, list); | ||
evaluate(`(isLower(x,z) AND isLower(k,y) OR (isLower(z,P) AND NOT isLower(P,k)))`, metadata, list); //-> false | ||
evaluate(`isLower(z,pi)`, metadata, list, map); // -> false |
{ | ||
"name": "safe-evaluate-expression", | ||
"version": "1.0.8", | ||
"version": "1.1.0", | ||
"description": "Small library to dynamically create and evaluate expression with multiple parameters (even undefined)", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "ava test/*.js", | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "npm test" | ||
} | ||
}, | ||
"repository": { | ||
@@ -26,3 +32,10 @@ "type": "git", | ||
}, | ||
"homepage": "https://github.com/ttessarolo/safe-evaluate-expression#readme" | ||
"homepage": "https://github.com/ttessarolo/safe-evaluate-expression#readme", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"ava": "^3.13.0", | ||
"codecov": "^3.8.1", | ||
"husky": "^4.3.0", | ||
"nyc": "^15.1.0" | ||
} | ||
} |
# safe-evaluate-expression | ||
![NPM](https://img.shields.io/npm/v/safe-evaluate-expression/latest) | ||
![NPM](https://img.shields.io/npm/dw/safe-evaluate-expression) | ||
![NPM](https://img.shields.io/npm/l/safe-evaluate-expression) | ||
![Codecov](https://img.shields.io/codecov/c/gh/ttessarolo/safe-evaluate-expression) | ||
![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/safe-evaluate-expression) | ||
![NPM](https://img.shields.io/badge/4R3S-PR0DUCT10N-yellowgreen) | ||
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 🔥**. | ||
@@ -55,2 +62,29 @@ | ||
## Example | ||
```javascript | ||
const { factory, operators } = require("safe-evaluate-expression"); | ||
const evaluate = factory({ operators, multipleParams: true, translateLogical: true }); | ||
const metadata = { x: 1.1, y: 2 }; | ||
const list = { k: 3, z: 4 }; | ||
const map = new Map([["pi", 3.14]]); | ||
const expression1 = "isLower(x,z)"; | ||
const expression2 = "isLower(k,y)"; | ||
evaluate(expression1, metadata, list); // -> true | ||
evaluate(expression2, metadata, list); // -> false | ||
evaluate(`${expression1} AND ${expression2}`, metadata, list); // -> false | ||
evaluate(`${expression1} OR ${expression2}`, metadata, list); // -> true | ||
const expression3 = "isLower(notDefined,z)"; // put a not defined value | ||
evaluate(expression3, metadata, list); | ||
evaluate(`${expression3} AND ${expression2}`, metadata, list); // -> false | ||
evaluate(`(isLower(x,z) AND isLower(k,y) OR (isLower(z,P) AND NOT isLower(P,k)))`, metadata, list); | ||
evaluate(`isLower(z,pi)`, metadata, list, map); // -> false | ||
``` | ||
## Factory Params | ||
@@ -100,29 +134,2 @@ | ||
## Factory Example | ||
```javascript | ||
const { factory, operators } = require("safe-evaluate-expression"); | ||
const evaluate = factory({ operators, multipleParams: true, translateLogical: true }); | ||
const metadata = { x: 1.1, y: 2 }; | ||
const list = { k: 3, z: 4 }; | ||
const map = new Map([["pi", 3.14]]); | ||
const expression1 = "isLower(x,z)"; | ||
const expression2 = "isLower(k,y)"; | ||
evaluate(expression1, metadata, list); // -> true | ||
evaluate(expression2, metadata, list); // -> false | ||
evaluate(`${expression1} AND ${expression2}`, metadata, list); // -> false | ||
evaluate(`${expression1} OR ${expression2}`, metadata, list); // -> true | ||
const expression3 = "isLower(notDefined,z)"; // put a not defined value | ||
evaluate(expression3, metadata, list); | ||
evaluate(`${expression3} AND ${expression2}`, metadata, list); // -> false | ||
evaluate(`(isLower(x,z) AND isLower(k,y) OR (isLower(z,P) AND NOT isLower(P,k)))`, metadata, list); | ||
evaluate(`isLower(z,pi)`, metadata, list, map); // -> false | ||
``` | ||
# Safe Lambda | ||
@@ -129,0 +136,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
81574
35
243
0
149
1
4