* "Lazy" load math.js: only require when we actually start using it. * This ensures the cli application looks like it loads instantly. * When requesting help or version number, math.js isn't even loaded. * @return {{ evalute: function, parse: function, math: Object }}
()
| 59 | * @return {{ evalute: function, parse: function, math: Object }} |
| 60 | */ |
| 61 | function getMath () { |
| 62 | const { create, all } = require('../lib/browser/math.js') |
| 63 | |
| 64 | const math = create(all) |
| 65 | const parse = math.parse |
| 66 | const evaluate = math.evaluate |
| 67 | |
| 68 | // See https://mathjs.org/docs/expressions/security.html#less-vulnerable-expression-parser |
| 69 | math.import({ |
| 70 | 'import': function () { throw new Error('Function import is disabled') }, |
| 71 | 'createUnit': function () { throw new Error('Function createUnit is disabled') }, |
| 72 | 'reviver': function () { throw new Error('Function reviver is disabled') } |
| 73 | }, { override: true }) |
| 74 | |
| 75 | return { math, parse, evaluate } |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Helper function to format a value. Regular numbers will be rounded |