GithubHelp home page GithubHelp logo

bylexus / fparse Goto Github PK

View Code? Open in Web Editor NEW
82.0 6.0 15.0 1.06 MB

A JavaScript Formula Parser

Home Page: http://fparser.alexi.ch/

License: MIT License

JavaScript 34.86% HTML 1.88% Dockerfile 0.53% Vue 26.59% SCSS 0.07% TypeScript 36.07%
mathematical-formulas formula javascript-formula-parser javascript-math parser formulaparser

fparse's People

Contributors

bylexus avatar samstonehouse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fparse's Issues

Syntax error with `-z+t`

Hello,
For some reason, the parser doesn't like expression -z+t. However, -z is fine and z+t also works.

Support for binary operations ?

I would like to use fparse to create binary cases to execute like

x + y < z
x > y
x >= z
x + y + z = 10
etc 

is there a way to extend this functionality?

Plain Angular 17 project fail to start

export class AppComponent {
  constructor(private router: ActivatedRoute) {
    const fObj = new Formula('2^x');
    let result = fObj.evaluate({ x: 3 }); // result = 8
    console.log(result);
  }
}

run start

➜  playroutes git:(master) ✗ yarn start
yarn run v1.22.19
$ nx serve

> nx run playroutes:serve:development


Initial Chunk Files | Names         |  Raw Size
polyfills.js        | polyfills     |  82.71 kB | 
main.js             | main          |  34.11 kB | 
styles.css          | styles        |  95 bytes | 

                    | Initial Total | 116.92 kB

Application bundle generation complete. [1.507 seconds]
Watch mode enabled. Watching for file changes...

 >  NX   Failed to resolve entry for package "fparser". The package may have incorrect main/module/exports specified in its package.json.

   Pass --verbose to see the stacktrace.


 —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 >  NX   Running target serve for project playroutes failed

   Failed tasks:
   
   - playroutes:serve:development
   
   Hint: run the command with --verbose for more details.

   View structured, searchable error logs at https://nx.app/runs/KWq4lX62oE

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Can parser don't apply scientific notation to large numbers?

Can you make it so that when a formula is loaded, the parser doesn't apply scientific notation to large numbers? Or how can I achieve this in a fork?

for example:

new Formula(VALUE)

where VALUE gets transformed to scientific notation so any number with more than 15 digits will get rounded and rewriten to SN.

How can I prevent that?

Any ideas?

prevent stack overflow

I think it will be wise to prevent stack overflow and don't allow the execution of evaluate from inside the formula (formulas can be user generated)

fObj = new Formula('evaluate()');

Multiple types returns

I have a typescript error with that code (from v2) after upgrading to v3. Is there correct migration procedure?

const time = entry[i][0];
      const open = calculator.evaluate(paramsOpen);
      const high = calculator.evaluate(paramsHigh);
      const low = calculator.evaluate(paramsLow);
      const close = calculator.evaluate(paramsClose);

      kData.push([
        time,
        String(open),
        String(open >= close ? Math.max(high, open) : Math.max(high, close)),
        String(open >= close ? Math.min(low, close) : Math.min(low, open)),
        String(close),
        String(volume),
      ]);
 Argument of type 'number | number[]' is not assignable to parameter of type 'number'.

UPD.
At this moment I made a cast workaround

const close = formula.evaluate(params.close) as number;
const open = formula.evaluate(params.open) as number;
const high = formula.evaluate(params.high) as number;
const low = formula.evaluate(params.low) as number;
const volume = formula.evaluate(params.volume) as number;

string params

allow string params to user formula for example:

var fObj = new Formula('if(eq(prop(1),prop(2)), "yes", "no")');
fObj.if=function(a,b,c) {...}
fObj.eq=function(a,b) {...}
fObj.prop=function(a) {...}

getVariables

would be nice if there was a function to get all variables from an expression.

Could you add a license to this repo?

Hi, could you please assign a standardized license to this project? I was considering using it but there seems to be a lack of a license in the repo. If I missed it, could you please point it out to me?

Variable names cannot include spaces

It would be useful to be able to have spaces in variable to aid readability.

Example

const squareMyVariable = new Formula('[My Variable]^2');
fObj.evaluate({"My Variable": 3}); // Throws: Uncaught Error: Cannot evaluate MyVariable: No value given

The error is thrown because when the function is cleaned we remove all spaces meaning the variable no longer matches, and would instead have to be MyVariable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.