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 🙏

© 2024 – Pkg Stats / Ryan Hefner

nested-rules-engine

v1.1.142

Published

Nested Conditional Rules Engine

Downloads

62

Readme

Synopsis

A simple Decision tree based Rule Engine described using json files. Rules are executed according to decision tree. Create a set of rules (make them nested as you like) and based on set of inputs run the rules.

Features

  1. Rules expressed in huaman readable JSON
  2. Create new set of inputs or change existing inputs as you traverse rules tree
  3. Do multiple executions or rules set

Installation

npm install nested-rules-engine --save

Basic Example

const {executeEngine} = require('nested-rules-engine');

// Step1: Define your conditional rules
const rules = {
  "you_are_a_human": {
    "you_are_kind": "help_me_find_my_book",
    "you_are_smart": "please_do_my_homework",
  },
  "default": "please_do_my_homework"
};

// Step2: make set of inputs collection
const inputs = {
  "type" : "human",
  "kindnessLevel": 0,
  "intelligence": 10
}

// Step3: Make your custom Functions
const functions = {
  default : () => true,
  you_are_a_human: ({type}) => type === 'human',
  you_are_kind: ({kindnessLevel}) => kindnessLevel > 300,
  you_are_smart: ({intelligence}) => intelligence > 5,
  help_me_find_my_book: () => ({
    payload: 'lets help someone',
    effort: 'finding the book'
  }),
  please_do_my_homework: () => ({
    payload: 'doing homework',
    effort: 'im getting sick'
  })
};

// Step4: Execute Engine
const res = executeEngine(inputs, functions, rules);

// Output res:
/*
{
  result: { payload: 'doing homework', effort: 'im getting sick' },
  logs: []
}
*/

Documentation

Engine Execution Signature:

executeEngine(variables, functions, rules, options);

Inputs

  • variables Collection of values on which rule engine will execute You can change these collection of variables (Add/Edit/Delte them) as you traverse the decision tree of rules.

  • functions Collection of functions that decide which way the tree should be traversed.

    • In case the function indicates a final decision in tree (leaf of decision tree): Output can be anything that you want to see as result
    • In case the function is makes an intermediate decision (branch of decision tree):
      • if output is true: this means this branch should be traversed
      • else: the function will be executed
  • rules Decision Tree that will be traversed by this Rule Engine

  • options there are different options that you can provide to customize the execution nature

    • verbose (boolean): Makes Sure you get enough logs while engine goes through all decision tree
    • multiple (boolean): You can run multiple Decision Trees based on same inputs. Input sets are shared between each tree

Outputs

  • result: Result of the engine execution. format of Result will be defined by you through functions
  • logs: Detailed logs while engine got executed (by default its disabled)

Hard Examples

  1. Example with verbose output, multiple executions Find Here
  2. Example with Creating new set of inputs while engine is executing Find Here

License

MIT