mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
25 lines
590 B
JavaScript
25 lines
590 B
JavaScript
const { create, all } = require('../../../index')
|
|
const workerpool = require('workerpool')
|
|
const math = create(all)
|
|
|
|
// disable the import function so the math.js instance cannot be changed
|
|
function noImport () {
|
|
throw new Error('function import is disabled.')
|
|
}
|
|
math.import({ 'import': noImport }, { override: true })
|
|
|
|
/**
|
|
* Evaluate an expression
|
|
* @param {string} expr
|
|
* @return {string} result
|
|
*/
|
|
function evaluate (expr) {
|
|
const ans = math.evaluate(expr)
|
|
return math.format(ans)
|
|
}
|
|
|
|
// create a worker and register public functions
|
|
workerpool.worker({
|
|
evaluate: evaluate
|
|
})
|