Skip to content

fast-json-rules-engineSame rules JSON, compiled once

A compiled, synchronous, zero-dependency engine for the json-rules-engine rule format — no promises, no clones.

Quick start

sh
npm install fast-json-rules-engine
js
import { compile } from 'fast-json-rules-engine'

const rules = [
  {
    conditions: {
      all: [
        { fact: 'country', operator: 'in', value: ['US', 'GB', 'CA'] },
        { fact: 'spend', operator: 'greaterThanInclusive', value: 100 },
      ],
    },
    event: { type: 'whale', params: { tier: 'gold' } },
    priority: 10,
  },
]

// Compile once (e.g. when your config loads), reuse for every request.
const engine = compile(rules)

const { events } = engine.run({ country: 'US', spend: 250 })
// events -> [{ type: 'whale', params: { tier: 'gold' } }]

engine.run(facts) returns synchronously — no await, no .then(). Rules are near-static and facts change every call, so the pattern is always compile once, run many.

What it trades away

The speed comes from dropping json-rules-engine's runtime dynamism: async facts, event handlers, the evaluated conditions tree, and mutating rules on a live engine are deliberately not supported — recompile instead of patching a running engine. If your facts are plain values and you evaluate the same rules over and over, that trade is usually free. See the migration guide for the full compatibility matrix.

Released under the MIT License. An independent project, not affiliated with json-rules-engine.