bylexus / fparse Goto Github PK
View Code? Open in Web Editor NEWA JavaScript Formula Parser
Home Page: http://fparser.alexi.ch/
License: MIT License
A JavaScript Formula Parser
Home Page: http://fparser.alexi.ch/
License: MIT License
Hello,
For some reason, the parser doesn't like expression -z+t
. However, -z
is fine and z+t
also works.
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?
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 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?
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()');
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;
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) {...}
would be nice if there was a function to get all variables from an expression.
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?
It would be useful to be able to have spaces in variable to aid readability.
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
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.