// to include an npm module/package into clojurescript: // https://figwheel.org/docs/npm.html // to reduce the bundle size: // https://mathjs.org/docs/custom_bundling.html import { parse, evaluate } from 'mathjs'; function getVariables(expression) { if( !expression || typeof expression !== 'string' ) { console.log('not correct input', expression, typeof expression); return []; } try { const expressionObject = parse(expression); console.log('now returning', expressionObject); return expressionObject .filter(x => x.isSymbolNode) .map(x => x.name) .map(x => x.toUpperCase()) .filter(x => /^[A-Z]+[0-9]+$/.test(x)); } catch(e) { console.error('error in parsing or filtering for variables', e.message || e); return []; } } function customEval(...args) { try { return evaluate(...args); } catch(e) { console.error('error in evaluating expression', e.message || e); return {error: e.message}; } } window.mathjs = {parse, evaluate: customEval, getVariables};