darky / json-logic-js-jit

Build complex rules, serialize them as JSON, and execute them in JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

json-logic-js-jit

Another implementation of JsonLogic, which precompile JSON rules for high speed performance.

Examples

Basic

import { compile } from 'json-logic-js-jit';

const fn = compile({ "and" : [
  { ">" : [3,1] },
  { "<" : [1,3] }
]});

fn(); // true

Add operation

import { compile, addOperation } from 'json-logic-js-jit';

addOperation("plus", (a, b) => a + b);

const fn = compile({ plus: [1, 2] });

fn(); // 3

Pass data

import { compile, addOperation } from 'json-logic-js-jit';

addOperation("var", (key, data) => data[key]);

const fn = compile({ var: ["fruit"] });

fn({ fruit: "apple" }); // "apple"

Built-in operators

  • and
  • or
  • >
  • <
  • >=
  • <=
  • ==
  • ===
  • !=
  • !==
  • !
  • !!
  • +
  • -
  • *
  • /
  • %

Additional tools

https://github.com/darky/json-logic-js-jit-tools

About

Build complex rules, serialize them as JSON, and execute them in JavaScript

License:MIT License


Languages

Language:JavaScript 100.0%