json-logic-js
json-logic-js copied to clipboard
Feature Request: ability to add custom operators which are not automatically traversed for evaluation
Some operators, for example if
, map
, reduce
etc. have modified scope for evaluation, so that the parameters passed into these operators aren't automatically evaluated but instead conditionally evaluated based on the operators control structure.
{ "if"[true, "only evaluated after if is run", "never gets evaluated"] }
However, it appears the ability to add such behaviour with a custom operator is not currently supported
https://github.com/jwadhams/json-logic-js/blob/9c805e9ac6a3787e8508e982a079888d3cc295b5/logic.js#L231
There is already this large if-else chain within the apply
method which could be easily modified to allow for custom operators to added and executed here (perhaps via some configuration when registering the custom operator), which would allow users to define whether their custom operator should automatically traverse or not.
js-logic-engine another library for json-logic also has an implementation of a similar configuration when registering a custom operator with their traverse
option.
Would it be possible, to add a similar sort of functionality to this library when registering custom operators?