json-logic-engine
Advanced tools
Comparing version
@@ -13,2 +13,3 @@ // @ts-check | ||
const { buildAsync } = require('./compiler') | ||
const omitUndefined = require('./utilities/omitUndefined') | ||
@@ -65,4 +66,4 @@ /** | ||
*/ | ||
addMethod (name, method, { deterministic = false, async = true, sync = !async, yields = false, useContext = false } = {}) { | ||
Object.assign(method, { yields, deterministic, useContext }) | ||
addMethod (name, method, { deterministic, async = true, sync = !async, yields, useContext } = {}) { | ||
Object.assign(method, omitUndefined({ yields, deterministic, useContext })) | ||
this.methods[name] = declareSync(method, sync) | ||
@@ -69,0 +70,0 @@ } |
@@ -36,32 +36,47 @@ const { LogicEngine, AsyncLogicEngine } = require('../index') | ||
// const defined = [ | ||
// [ | ||
// { '+': [1, 2, 3, 4, 5] }, | ||
// {} | ||
// ], | ||
// [ | ||
// { map: [[1, 2, 3, 4, 5], { '+': [{ var: '' }, 1] }] }, | ||
// {} | ||
// ], | ||
// [ | ||
// { cat: ['Test of a ', { var: 'x' }] }, | ||
// { x: 'Program' } | ||
// ], | ||
// [ | ||
// { '>': [{ var: 'x' }, 10] }, | ||
// { | ||
// x: 7 | ||
// } | ||
// ], | ||
// [ | ||
// { and: [{ '>': [{ var: 'accountants' }, 3] }, { var: 'approvedBy.ceo' }] }, | ||
// { | ||
// approvedBy: { | ||
// ceo: true | ||
// }, | ||
// accountants: 10 | ||
// } | ||
// ] | ||
// ] | ||
const tests = compatible | ||
const defined = [ | ||
[ | ||
{ '+': [1, 2, 3, 4, 5] }, | ||
{} | ||
], | ||
[ | ||
{ map: [[1, 2, 3, 4, 5], { '+': [{ var: '' }, 1] }] }, | ||
{} | ||
], | ||
[ | ||
{ cat: ['Test of a ', { var: 'x' }] }, | ||
{ x: 'Program' } | ||
], | ||
[ | ||
{ '>': [{ var: 'x' }, 10] }, | ||
{ | ||
x: 7 | ||
} | ||
], | ||
[ | ||
{ and: [{ '>': [{ var: 'accountants' }, 3] }, { var: 'approvedBy.ceo' }] }, | ||
{ | ||
approvedBy: { | ||
ceo: true | ||
}, | ||
accountants: 10 | ||
} | ||
], | ||
[ | ||
{ '+': [{ var: '' }, 1] }, | ||
5, | ||
6 | ||
], | ||
[ | ||
{ '-': [{ var: '' }, 1] }, | ||
7, | ||
6 | ||
], | ||
[ | ||
{ '*': [{ var: 'x' }, { var: 'y' }] }, | ||
{ x: 1, y: 3 }, | ||
3 | ||
] | ||
] | ||
const tests = defined || compatible | ||
@@ -68,0 +83,0 @@ const other = tests || traverseCopy(tests, [], { |
@@ -11,2 +11,3 @@ // @ts-check | ||
const declareSync = require('./utilities/declareSync') | ||
const omitUndefined = require('./utilities/omitUndefined') | ||
@@ -59,4 +60,4 @@ /** | ||
*/ | ||
addMethod (name, method, { deterministic = false, yields = false, useContext = false } = {}) { | ||
Object.assign(method, { yields, useContext, deterministic }) | ||
addMethod (name, method, { deterministic, yields, useContext } = {}) { | ||
Object.assign(method, omitUndefined({ yields, useContext, deterministic })) | ||
this.methods[name] = declareSync(method) | ||
@@ -63,0 +64,0 @@ } |
{ | ||
"name": "json-logic-engine", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Construct complex rules with JSON & process them.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,8 +7,17 @@ # JSON Logic Engine | ||
This library was developed to be (for the most part) a drop-in replacement for the popular npm module [`json-logic-js`](https://github.com/jwadhams/json-logic-js), which at the time of writing has an vulnerability with prototype pollution. | ||
The intention of the library is to keep the functionality very similar to the original, while adding a few new notable features. | ||
 | ||
The library has an async version of the engine, so if an operation needed to be added that needed to process asynchronously, the library is capable of handling it. | ||
### Fast, Powerful, and Persistable Logic | ||
Have you ever needed the ability to write a custom set of logic or set of rules for a particular customer? Or needed to be able to configure a piece of logic on the fly? | ||
JSON Logic might be your solution! Designed with a lisp-like syntax, JSON Logic makes it easy to write safe instructions that can be persisted into a database, and shared between the front-end and back-end. | ||
Check out our [Documentation Here](https://jessemitchell.me/json-logic-engine). | ||
The engine supports both synchronous & asynchronous operations, and can use function compilation to keep your logic performant at scale. | ||
Examples: | ||
@@ -102,1 +111,8 @@ | ||
``` | ||
--- | ||
This library was developed to be (for the most part) a drop-in replacement for the popular npm module [`json-logic-js`](https://github.com/jwadhams/json-logic-js), which at the time of writing has an vulnerability with prototype pollution. | ||
The intention of the library is to keep the functionality very similar to the original, while adding a few new notable features. | ||
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
251274
0.43%39
2.63%11740
0.21%117
15.84%4
33.33%