2.0.0 • Published 10 years ago

json-logic v2.0.0

Weekly downloads
33
License
MIT
Repository
github
Last release
10 years ago

node-json-logic

Package for expressing logical operations in JSON. Useful for storing logical procedures in a database.

Examples of use

var JSONMath = require('json-logic');
var logic = new JSONLogic();
var result = logic .execute({
	"a": {
		"operation": "||",
		"variables": [
			{
				"operation": "<",
				"variables": [
					5,
					1
				]
			},
			{
				"operation": "&&",
				"variables": [
					{
						"operation": "==",
						"variables": [
							8,
							2
						]
					},
					true
				]
			}
		]
	}
});

After this has executed, the value of a will be false.

You can also pass in an array of operations to perform, and even reference variables inside the procedure

[
	{
		"a": true,
		"b": false
	},
	{
		"c": {
			"operation": "&&",
			"variables": [
				"a",
				"b"
			]
		}
	},
	{
		"c": "c"
	}
]

After this the value of a will be true, b will be false and c will be false.