Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

safe-evaluate-expression

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

safe-evaluate-expression - npm Package Compare versions

Comparing version 1.0.8 to 1.1.0

.nyc_output/110ebac1-9455-4acf-982d-4e3cb76b9a9c.json

4

examples/factory.js

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc