Compiled, not interpreted
compile(rules) once into plain predicate functions; engine.run(facts) is synchronous — no Promise or clone overhead per evaluation.
A compiled, synchronous, zero-dependency engine for the json-rules-engine rule format — no promises, no clones.
npm install fast-json-rules-engineimport { 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.
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.