You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

json-logic-engine

Package Overview
Dependencies
Maintainers
1
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-logic-engine - npm Package Compare versions

Comparing version

to
1.0.1

utilities/omitUndefined.js

5

asyncLogic.js

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

2

package.json
{
"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.
![Logo](https://raw.githubusercontent.com/gist/TotalTechGeek/22d699b6d7cb0f7fa1c37fdb0c427e60/raw/63bd743ce7720b7337ac30ae09cbb1b8e12f3a5b/json-logic-engine.svg)
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.