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

@arunkumar_h/rule-engine

v3.1.2

Published

A lightweight and extensible rule engine built with TypeScript and Node.js. Define complex business rules and evaluate conditions easily using a simple JSON structure.

Readme

@arunkumar_h/rule-engine

Known Vulnerabilities NPM Version NPM Downloads License Bundle Size Install size

badge-branches badge-functions badge-lines badge-statements


Breaking Change: Please move to v3.1.0 or later.


A lightweight and extensible rule engine built with TypeScript and Node.js. Define complex business rules and evaluate conditions easily using a simple JSON structure.

📦 Installation

npm install @arunkumar_h/rule-engine
yarn add @arunkumar_h/rule-engine

🧠 Features

  • ✅ Logical condition support (and, or, nested expressions)
  • 🔧 Custom operators and named conditions
  • 📜 Fully typed with TypeScript
  • 🚀 Lightweight and dependency-aware
  • 🔎 Native JMESPath support for data querying
  • 🧰 Built-in caching using lru-cache for better performance

| Feature / Capability | @arunkumar_h/rule-engine | | --- | --- | | ✅ Written in TypeScript | ✅ Native TypeScript with full type safety | | ⚙️ Custom Operators | ✅ Built-in support, sync or async | | 🧠 Named Conditions | ✅ Supports reusable named conditions | | 🧱 Nested Logical Trees | ✅ Fully supported (and, or, deeply nested) | | 🔍 Data Query Language | ✅ Built-in JMESPath support | | 🚀 Performance Optimizations | ✅ Rule-level cache with lru-cache | | 🧰 Extensibility | ✅ Add custom operators, conditions dynamically | | ⚖️ Lightweight | ✅ Small and focused build | | 🧪 Testing Coverage Ready | ✅ Easy to unit test each rule block | | 🔁 Dynamic Rule Loading | ✅ Add/modify rules at runtime | | 🔄 Async Support | ✅ Full async engine and operators | | 📦 Modern Packaging | ✅ ESM + CJS + .d.ts types out of the box |

⚙️ Default Operators

The following operators are available by default:

| Operator | Description | | ------ | ------ | | === | Strict equality | | !== | Strict inequality | | == | Loose equality | | != | Loose inequality | | > | Greater than | | >= | Greater than or equal to | | < | Less than | | <= | Less than or equal to | | %like | Starts with | | like% | Ends with | | %like% | Contains | | in | Value is in the array | | !in | Value is not in the array | | includes | Array includes value | | !includes | Array does not include value |

🔨 Basic Usage

  • condition This containes and and or as main block.
  • onSuccess value that will be returned or function that will be invoked if the condition is satisfied.
  • onFail value that will be returned or function that will be invoked if the condition fails.
  • cache as default this will be set to true and can be disabled for rule wise false
import { Engine } from "@arunkumar_h/rule-engine";

const engineObj = new Engine();
const rule = {
  testRule: {
    condition: {
      and: [
        { path: "age", operator: "!==", value: 10 },
        {
          and: [
            { path: "age", operator: ">", value: 15 },
            {
              or: [
                { path: "age", operator: "!==", value: 30 },
                { path: "skills", operator: "includes", value: "ts" },
              ],
            },
          ],
        },
        { path: "language", operator: "in", value: ["tamil", "english"] },
      ],
    },
    onSuccess: (fact, ruleName) => "Success", // onSuccess: { id: 23 }
    onFail: (fact, ruleName) => "Fail", // onFail: "Error"
    cache: false, // default will be true
  }
};
engine.addRule(rule);

const fact = {age: 16, skills: ["ts", "php"], language: "tamil"}; // Your data to be validated 
const result = await engineObj.run(fact, "testRule");

🔧 Custom Operator Example

engine.addOperator({
  isEven: (factValue) => factValue % 2 === 0,
});

const rule = {
  evenCheck: {
    condition: {
      and: [
        { path: "number", operator: "isEven" },
      ],
    },
    onSuccess: "Number is even",
    onFail: "Number is odd",
  },
};

const result = await engine.run({ number: 8 }, "evenCheck");

🔍 API Overview

flowchart TB
    Rule --> onSuccess
    Rule --> onFail
    Rule --> Condition --> AND --> Operation
    Condition --> OR --> Operation

Engine API

let engine = new Engine() 

addRule({ rule1, rule2, ... })

  • Add named rules dynamically.

addCondition({ condition1, condition2, ... })

  • Add reusable named conditions.
  • Conditions can reference other named conditions.

addOperator({ customOperator1, customOperator2, ... })

  • Add custom (sync or async) operators.

run(fact, ruleName)

  • Executes a given rule against the provided fact

⚡ Advanced Usage

  • Adding named conditions.
  • Adding named operators.
  • Rule wise cache disabling.
import { Engine } from "@arunkumar_h/rule-engine";

const engineObj = new Engine();

const condition1 = {
  condition1: {
    and: [
      { path: "age", operator: "!==", value: 10 },
      {
        and: [
          { path: "age", operator: ">", value: 15 },
          {
            or: [
              { path: "age", operator: "!==", value: 30 },
              { path: "skills", operator: "includes", value: "ts" },
            ],
          },
        ],
      },
      { path: "language", operator: "in", value: ["tamil", "english"] },
    ],
  }
};
engine.addCondition(condition1);  // adding named condition

const rule = {
  testRule: {
    condition: "condition1",  // Using named condition
    onSuccess: "Success",  //  can be a function or a data
    onFail:  "Fail", //  can be a function or a data
    cache: false  // disable cache for this rule 
  }
};
engine.addRule(rule);

const fact = {age: 16, skills: ["ts", "php"], language: "tamil"}; // Your data to be validated 
const result = await engineObj.run(fact, "testRule");

🧪 Test Coverage

Badges above represent live coverage stats for:

  • badge-branches
  • badge-functions
  • badge-lines
  • badge-statements

Author

Arunkumar H

LinkedIn GitHub Email

📄 License

Some non-code content (e.g. diagrams, images, markdown docs) is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.

See https://creativecommons.org/licenses/by-sa/4.0/ for more info.

The detailed list of Open Source dependencies can be found in Fossa report.