jwadhams / json-logic-js

Build complex rules, serialize them as JSON, and execute them in JavaScript
MIT License
1.27k stars 139 forks source link

Would you be interested in a code merge? (json-logic-engine) #119

Open TotalTechGeek opened 1 year ago

TotalTechGeek commented 1 year ago

Hello!

I am and have been a huge fan of JSON Logic & the language you've designed.

For a while I've maintained an alternative JSON Logic implementation, and I'm curious if there's any interest in potentially doing a code merge? Introducing some of the work done for json-logic-engine into json-logic-js?

I would be happy to make efforts to ensure that any remaining differences are removed, mainly just:

However, my codebase is not designed for as much compatibility as your project is (it most certainly would not work with IE8), though it should be able to run in all currently supported web browsers.

If you'd prefer for our projects to remain separate, there won't be any hard feelings 😄.

TotalTechGeek commented 1 day ago

Hey @jwadhams, I've recently been putting some work into JSON Logic Engine, and I decided to revisit some of the compatibility differences.

I've introduced a flag in my project that applies some of the truthiness differences (empty arrays being false for both all and truthiness checks in general).

With 100% compatibility, I wanted to reach out and see if there's any appetite for merging the projects.

What JLE Introduces:

I've also produced some small benchmarks around the public JSON Logic tests, here are the timings of 1M iterations for each -

json-logic-js: 3.032s
le interpreted: 2.975s -- This guy has the optimizer disabled, as a way to keep things somewhat "fair"
le interpreted (optimized): 724.976ms
le built: 79.539ms
le async built: 432.778ms

If you're available, I'd love to chat about how I can contribute back to this really awesome spec you've built, and to the broader community.


I've been using JSON Logic to a ridiculous extent in other projects -- I've actually been using it as an AST for various PEG grammars and DSLs. 😅

At the risk of bragging (but also to show "Hey, I really, really like using this spec!") In an attempt to reduce dependencies from a personal project, I wrote a PEG grammar to convert Handlebars to JSON Logic, and I was surprised to discover that it performed nearly 13x faster when optimized through JSON Logic compared to the Handlebars compiler. I've also used it for other DSLs, like this silly testing DSL experiment.

I think it would be really cool to expand the ecosystem around JSON Logic, and help consolidate some of the projects and formalize the spec a bit more.

TotalTechGeek commented 1 day ago

Elaborating a bit,

I believe the additions in JSON Logic Engine resolve these issues - https://github.com/jwadhams/json-logic-js/issues/48, https://github.com/jwadhams/json-logic-js/issues/61, #82, #91, #97, #107, #111, #116, https://github.com/jwadhams/json-logic-js/issues/124, #127, https://github.com/jwadhams/json-logic-js/issues/130, https://github.com/jwadhams/json-logic-js/issues/134, https://github.com/jwadhams/json-logic-js/issues/135,

It also differs a bit and resolves some like -

54, #128, somewhat on #99 (and my opinions have shifted a bit since my comments on there), #35 (Since you can specify what isData or use preserve)