UNPKG

582 BJavaScriptView Raw
1const { create, all } = require('../../..')
2const workerpool = require('workerpool')
3const math = create(all)
4
5// disable the import function so the math.js instance cannot be changed
6function noImport () {
7 throw new Error('function import is disabled.')
8}
9math.import({ import: noImport }, { override: true })
10
11/**
12 * Evaluate an expression
13 * @param {string} expr
14 * @return {string} result
15 */
16function evaluate (expr) {
17 const ans = math.evaluate(expr)
18 return math.format(ans)
19}
20
21// create a worker and register public functions
22workerpool.worker({
23 evaluate: evaluate
24})