12345678910111213141516171819202122232425262728 |
- // 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);
- }
- catch(e) {
- console.error('error in parsing or filtering for variables', e.message || e);
- return [];
- }
- }
- window.mathjs = {parse, evaluate, getVariables};
|