index.js 791 B

12345678910111213141516171819202122232425262728
  1. // to include an npm module/package into clojurescript:
  2. // https://figwheel.org/docs/npm.html
  3. // to reduce the bundle size:
  4. // https://mathjs.org/docs/custom_bundling.html
  5. import { parse, evaluate } from 'mathjs';
  6. function getVariables(expression) {
  7. if( !expression || typeof expression !== 'string' ) {
  8. console.log('not correct input', expression, typeof expression);
  9. return [];
  10. }
  11. try {
  12. const expressionObject = parse(expression);
  13. console.log('now returning', expressionObject);
  14. return expressionObject.filter(x => x.isSymbolNode).map(x => x.name);
  15. }
  16. catch(e) {
  17. console.error('error in parsing or filtering for variables', e.message || e);
  18. return [];
  19. }
  20. }
  21. window.mathjs = {parse, evaluate, getVariables};