Skip to content

ChrisTheBaron/node-json-math

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-json-math

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

Examples of use

var JSONMath = require('json-math');
var math = new JSONMath();
var result = math.execute({
	"a": {
		"operation": "+",
		"variables": [
			2,
			2
		]
	},
	"b": {
		"operation": "-",
		"variables": [
			5,
			1
		]
	},
	"c": {
		"operation": "*",
		"variables": [
			2,
			2
		]
	},
	"d": {
		"operation": "/",
		"variables": [
			8,
			2
		]
	}
});

After this has executed, the value of a , b, c and d will be 4.

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

[
	{
		"a": 3,
		"b": 4
	},
	{
		"c": {
			"operation": "+",
			"variables": [
				"a",
				"b"
			]
		}
	},
	{
		"c": "c"
	}
]

After this the value of a will be 3, b will be 4 and c will be 7.

About

Package for expressing mathematical operations in JSON

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published