Formula machine
A formula machine for JS
example
var formula = ; var src = operator: '+' operands: 2 operator: 'sqrt' operands: number: 4 // like a just number operator: '/' operands: 2 2 ; // will convert to2 + Math console; // 4
With variables
var formula = ; var src = operator: '+' operands: 2 variable: 'name' ; var fn = formula; console; // 2 + 4 = 6
Multiple operands
var formula = ; var src = operator: '+' operands: 2 3 4 5 operator: '+' operands: 6 7 ; var fn = formula; console; // 2 + 3 + 4 + 5 + (6 + 7) = 27
operators
Formula machine has some binary operators:
- 1 + 2: simple "plus" (+)
- 1 - 2: simple "minus" (-)
- 1 * 2: simple "multiply" (*)
- 1 / 2: simple "division" (/)
- Math.pow(1, 2): exponentiation (pow)
Formula machine has some unary operators:
- Math.sqrt(4): calculating the root (sqrt)
install
With npm do:
npm install formula-machine
test
With npm do:
npm test