silentmatt / expr-eval

Mathematical expression evaluator in JavaScript
http://silentmatt.com/javascript-expression-evaluator/
MIT License
1.19k stars 239 forks source link

Add operator renaming #215

Open SHND opened 4 years ago

SHND commented 4 years ago

I really like this package but the only thing that kind of bothers me is lengthy operators: and, or, ... .

I'm using this package to to write conditional expressions in my routing strings.

It would be awesome if there was a configuration to rename for example and to &.

Telokis commented 4 years ago

From a brief look at the code, you should be able to alter parser.binaryOps just like you can alter parser.functions even though it's not in the documentation.

I think this would solve your issue.

silentmatt commented 4 years ago

@Telokis That won't quite work, because that only comes into play after the expression is parsed. You would also need to modify the parser to recognize the & and | symbols.

I have some ideas on how we could do this, but I'll need to give it some more thought.

Telokis commented 4 years ago

@silentmatt Ok, my bad, I suppose I looked too quickly before answering! Thanks for clarifying!