npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

json-rules-engine-upgraded

v1.0.1

Published

A modern, TypeScript-first JSON rules engine — the comprehensive, maintained successor to json-rules-engine.

Readme

json-rules-engine-upgraded

A lightweight TypeScript-first JSON rules engine for Node.js and browsers — an upgrade to json-rules-engine.

npm install json-rules-engine-upgraded

Synopsis

json-rules-engine-upgraded is a rules engine. Rules are composed of simple JSON structures — strictly typed, schema-validated at load time, and easy to persist in any JSON store.

Features

  • Rules expressed in simple, strictly-typed JSON; human-readable and persistable
  • Full support for all / any / not boolean operators, with recursive nesting and short-circuit evaluation
  • 28+ built-in operators across 6 families (comparison, collection, string, presence, size, numeric); custom operators supported
  • Async fact resolution with per-run caching and cycle detection
  • TypeScript-first end-to-end; zero runtime dependencies
  • JSON Schema export for the DSL, plus a $schema version field on every rule
  • Structured errors with ruleName, conditionPath, operator, and factValue context
  • Database-ready: rules drop straight into MongoDB, Postgres jsonb, DynamoDB, Firestore, or Redis
  • Secure; no eval(), ReDoS-checked regex, facts deep-frozen per run
  • Isomorphic; runs in Node and browsers without polyfills; ~35KB

Basic Example

import { Engine } from 'json-rules-engine-upgraded';

const engine = new Engine([
  {
    name: 'foulOut',
    priority: 10,
    conditions: {
      all: [
        { fact: 'gameDuration', operator: 'equal', value: 40 },
        { fact: 'personalFoulCount', operator: 'greaterThanInclusive', value: 5 },
      ],
    },
    event: { type: 'fouledOut', params: { message: 'Player has fouled out' } },
  },
]);

const { passed } = await engine.run({
  gameDuration: 40,
  personalFoulCount: 6,
});

console.log(passed); // [{ type: 'fouledOut', params: { message: 'Player has fouled out' } }]

Storing rules in MongoDB (or any JSON store)

Rules are plain JSON objects, so they round-trip through any JSON-capable store. Here's MongoDB:

import { MongoClient } from 'mongodb';
import { Engine, RULE_JSON_SCHEMA, fromJSON, OperatorRegistry } from 'json-rules-engine-upgraded';

const client = new MongoClient(process.env.MONGO_URL!);
const rules = client.db('myapp').collection('rules');

// 1. (Optional but recommended) Enforce rule shape at the database level
//    using Mongo's $jsonSchema validator. Any insert that doesn't match
//    the DSL schema is rejected before it hits your collection.
await client.db('myapp').command({
  collMod: 'rules',
  validator: { $jsonSchema: RULE_JSON_SCHEMA as any },
  validationLevel: 'strict',
});

// 2. Insert a rule — just a document
await rules.insertOne({
  $schema: '1.0.0',
  name: 'grantDiscount',
  conditions: {
    all: [
      { fact: 'cartTotal', operator: 'greaterThan', value: 100 },
      { fact: 'customer', path: '$.tier', operator: 'in', value: ['gold', 'platinum'] },
    ],
  },
  event: { type: 'applyDiscount', params: { percent: 15 } },
});

// 3. Load rules into the engine at startup (or on a change stream)
const engine = new Engine();
const operators = new OperatorRegistry();
for await (const doc of rules.find()) {
  engine.addRule(fromJSON(doc, { operators }));
}

// 4. Run against a fact set
const { passed } = await engine.run({
  cartTotal: 150,
  customer: { tier: 'gold' },
});

Works the same with Postgres jsonb, DynamoDB, Firestore, Redis, or any store that holds JSON.

Operator catalogue

| Family | Operators | |---|---| | Comparison | equal, notEqual, equalLoose, lessThan, lessThanInclusive, greaterThan, greaterThanInclusive, between | | Collection | in, notIn, contains, doesNotContain, subsetOf, supersetOf, intersectsWith | | String | startsWith, endsWith, regex, matchesAny | | Presence / type | isEmpty, isNotEmpty, isNull, isNotNull, typeOf, hasProperty | | Size | lengthEqual, lengthGreaterThan, lengthLessThan | | Numeric | approximately |

Register a custom operator with engine.addOperator({ name, evaluate, validateConditionValue }).

Comparison

| Feature | json-rules-engine-upgraded | json-rules-engine | json-logic-js | |---|---|---|---| | TypeScript-first | ✅ | ❌ | ❌ | | Zero runtime deps | ✅ | ❌ | ✅ | | Built-in operators | 28+ | ~11 | many (different paradigm) | | JSON Schema for DSL | ✅ | ❌ | ❌ | | $schema versioning in rules | ✅ | ❌ | ❌ | | Strict equality by default | ✅ | ❌ | varies | | Structured error codes | ✅ | ❌ | ❌ | | ReDoS-safe regex | ✅ (checked at load) | ❌ | n/a | | Browser support without polyfills | ✅ | partial | ✅ |

Related libraries

Not a schema validator. Libraries like Ajv and Zod answer "is this data shaped correctly?". This library answers "given this data, what business rule fires?". They compose — use the exported RULE_JSON_SCHEMA with Ajv to validate rule JSON at ingest.

Docs

License

MIT