UNPKG

676 BJavaScriptView Raw
1const { create, evaluateDependencies } = require('../..')
2
3// custom implementations of all functions you want to support
4const add = (a, b) => a + b
5const subtract = (a, b) => a - b
6const multiply = (a, b) => a * b
7const divide = (a, b) => a / b
8
9// create a mathjs instance with hardly any functions
10// there are some functions created which are used internally by evaluate though,
11// for example by the Unit class which has dependencies on addScalar, subtract,
12// multiplyScalar, etc.
13const math = create(evaluateDependencies)
14
15// import your own functions
16math.import({ add, subtract, multiply, divide }, { override: true })
17
18console.log(math.evaluate('2 + 3 * 4')) // 14