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

maxim-engine

v1.2.1

Published

A simplistic (for now) rules engine

Downloads

14

Readme

Build Status Code Quality Test Coverage

Maxim Engine

Maxim is a simple rule engine, getting better a step at a time.

The engine will recognize when a consequence changes a property in working memory that is referenced by a registered rule. When this happens, it will re-run the rule-set.

It does not (yet) do loop detection so it will re-run the rule-set a defined number of times (default is 10).

The engine lazily evaluates referenced properties in working memory and uses Reflect / Proxy to intercept and record when they change.

Limitations

  • no loop detection / conflict resolution
  • no optimization of rule re-runs
  • probably more I haven't thought of...

Roadmap (tentative)

These will change depending on community engagement, and my own needs.

  • ability to name rules
  • explore smarter algorithms to execute across the ruleset
    • loop detection
    • conflict resolution

Usage

Initialize yourself an instance of the MaximEngine

const { MaximEngine } = require('maxim-engine');
let engine = new MaximEngine();

Rules have two components, a condition and a consequence. Each component needs a lambda that takes an instance of the engine's Working Memory

A condition is a lambda that takes an instance of the engine's Working Memory and returns a boolean value that indicates to the engine that the consequence applies.

eg. (wm) => !('message' in wm)

A consequence is a lambda that mutates the provided working memory (which is actually a copy of the original working memory in order to avoid side-effects).

eg. (wm) => wm.message = "Hello, World!"

So here is an example of a complete rule:

let rule = {
    condition: (wm) => !('message' in wm),
    consequence: (wm) => wm.message = "Hello, World!"
};

Once you have a set of rules you can register them with the engine. You can provide a single rule or an array of rules.

engine.register(rule);

Once you have loaded your rules into the engine, you can use it as many times as you'd like with different input data.

let result = engine.execute({ message: "Change me!" });
console.log(result.message); // Outputs "Hello, World!"

With a more sophisticated ruleset, if you want to ensure a maximum number of working memory generations (in case you have loops) you can do so like this:

let result = engine.execute({ message: "Change me!" }, 100);
// evaluates a maximum of 100 generations of working memory

Prioritizing Rules

Rules can be prioritized with a property called priority. Higher integers represent higher priority.

engine.register([
    {
        priority: 100,
        condition: wm => wm.value === 1,
        consequence: wm => wm.value = 100
    },
    {
        priority: 1,
        condition: wm => wm.value === 1,
        consequence: wm => wm.value = 10
    }
]);

let result = engine.execute({value: 1});
// { value: 100 }

Distributed Openly, Built Openly

This project is licensed under the very permissive MIT license and Copyright (c) 2018 Stacey Vetzal.

My goal is that the entirety of this system will be built openly via the Twitch platform. While traditionally a game-streaming platform, Twitch offers a remarkable experience for the streamer, and I hope that the archive of streams will be perhaps useful for educational purposes.

You can watch the entirety of Maxim-Engine's construction via the following Twitch collection.

I welcome engagement, real time over Twitch, or via Github.