Recursively perform calculations on an object according to a list of definitions.
npm install calculation-enginenull`.
The order in which the calculations are defined determines the precedence of execution.
Usage
`javascript
const calcEngine = require('calculation-engine');
let ce = new calcEngine([
{
inupts: ['var_1'],
outputs: ['var_2'],
fn: function (v) {
return { var_2: v.var_1 * 2 };
},
},
{
inputs: ['var_2'],
outputs: ['var_3'],
excludes: ['var_4'],
fn: function (v) {
return { var_3: v.var_2 - 0.2 };
},
},
{
inputs: ['var_2'],
outputs: ['var_3'],
fn: function (v) {
return { var_3: v.var_2 - 0.1 };
},
},
]);
expect(ce.calculate({
var_1: 2,
var_2: null,
var_3: null,
var_4: null,
})).to.deep.equal({
var_1: 2,
var_2: 4,
var_3: 3.9,
var_4: null,
});
`
Constructor
`javascript
@param {Array.`
Provide an array of objects. Each object must contain a list of input keys and a list of output keys, as well as a function to execute when the definition is selected. Optionally, attribute names listed in 'excludes' will prevent the calculation from being used if any of those attributes exist on the incoming object. Missing or invalid attributes, duplicate input/output definitions, and circular references will throw an error.
Methods
$3
`javascript
@param {Object} values
@returns {Object}
`
$3
`javascript
@returns {Array.}
`
$3
`javascript
@param {!Array.} inputs - optional list of input keys; outputs are filtered to only those that
can be satisified with the given inputs
@returns {Array.}
``