UNPKG

mathjs

Version:

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser and offers an integrated solution to work with numbers, big numbers, complex numbers, units, and matrices.

24 lines (20 loc) 538 B
var math = require('mathjs'); var workerpool = require('workerpool'); // 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) { var ans = math.eval(expr); return math.format(ans); } // create a worker and register public functions workerpool.worker({ evaluate: evaluate });