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

ruleforge

v0.3.1

Published

Declarative rule engine to map JSON/XML payloads into canonical nested JSON.

Readme

ruleforge

Declarative Rule Engine & Integration Mapping Framework Transform JSON/XML payloads into canonical nested JSON using selectors, conditions, transforms, and loop bindings.


Why ruleforge?

RuleForge allows you to:

  • Map complex nested payloads declaratively
  • Handle JSON and XML seamlessly
  • Extract deeply nested values using selector variables ($X1..$X10)
  • Apply operator-based conditions
  • Use preprocessors & postprocessors
  • Normalize CDATA into $pre
  • Support case-insensitive, regex, numeric comparisons
  • Build enterprise-grade integration pipelines without hardcoding logic

Features

  • JSON and XML support (XML normalized to JS object)
  • Envelope / metadata support via initializer
  • Payload inside string fields supported (JSON/XML strings)
  • Preprocessors, PostProcessors
  • Rule priority (top → bottom)
  • Array selector (X) – first match
  • Nested canonical output keys (dot-path targets)
  • Transform functions (built-ins + custom)
  • Debug metadata (result.meta.matched, $pre, etc.)

Installation

npm install ruleforge

Core Concepts

Namespaces

RuleForge works with three namespaces:

| Namespace | Description | | --------- | ----------------------------- | | $payload | Original normalized payload | | $meta | Input metadata | | $pre | Preprocessed / derived values |


Rule Document Structure

{
  "version": "1.0",
  "name": "example_rules",
  "initializer": { "function": "initRequest" },
  "aliases": {},
  "preprocessors": {},
  "postProcessors": [],
  "rules": {}
}

Basic Example

Input (JSON)

{
  "device": {
    "serialNumber": "CNB1234567"
  }
}

Rules

{
  "version": "1.0",
  "rules": {
    "output.device.serialNumber": {
      "mappings": ["device.serialNumber"]
    }
  }
}

Output

{
  "output": {
    "device": {
      "serialNumber": "CNB1234567"
    }
  }
}

Selector Variables ($X1..$X10)

Supports nested array traversal.

Example:

{
  "match.serial": {
    "conditions": {
      "customers.$X1.devices.$X2.id": "deviceId_10"
    },
    "mappings": [
      "customers.$X1.devices.$X2.serialNum"
    ]
  }
}

✔ Automatically finds correct indices ✔ DFS-based selector binding ✔ Supports up to 10 nested variables

Looping Output Arrays ($X)

For output array construction:

"metrics.$X.totalSheets": {
  "conditions": {
    "CounterGroup.$X1.CounterName": "TotalSheets"
  },
  "mappings": [
    "CounterGroup.$X1.Value"
  ]
}

Each match produces:

{
  "metrics": [
    { "totalSheets": 17 },
    { "totalSheets": 18 }
  ]
}

Operator-Style Conditions

Case Insensitive

{
  "$pre.clientName": { "equalsIgnoreCase": "agent_1" }
}

In List (Case Insensitive)

{
  "$pre.clientName": { "inIgnoreCase": ["agent_1", "agent_2"] }
}

Regex

{
  "$pre.clientName": { "regex": "^Agent_[0-9]+$", "flags": "i" }
}

Numeric Comparison

{
  "account.balance": { "gt": 1000 }
}

Exists

{
  "device.serialNumber": { "exists": true }
}

Type Check

{
  "field": { "type": "string" }
}

Combinators

{
  "$pre.clientName": {
    "all": [
      { "equalsIgnoreCase": "agent_1" },
      { "regex": "agent_[0-9]+", "flags": "i" }
    ]
  }
}

Preprocessors

Preprocessors allow derived values before rules execute.

{
  "preprocessors": {
    "clientName": { "function": "getClientName" }
  }
}

Implementation:

async function getClientName(ns, ctx) {
  return ns.payload.source?.system;
}

Accessible as:

$pre.clientName

PostProcessors

Transform final output before returning:

{
  "postProcessors": ["convertOutputData"]
}

Aliases

Aliases allow fallback paths across payload types.

{
  "aliases": {
    "Asset": [
      "$pre.jsonData.device",
      "UsageCollection.Asset"
    ]
  }
}

Usage:

"Asset.serialNumber"

Debug Mode

Enable debug to include:

  • matched rule index
  • selector bindings
  • resolved paths
  • $pre content
new Mapper({
spec,
functions,
debug: true
})

API Usage

import { Mapper } from "ruleforge";

const mapper = new Mapper({
  spec: rules,
  functions: {
    initializer: { initRequest },
    preprocessors: { getClientName },
    transforms: {},
    postProcessors: {}
  }
});

const result = await mapper.map(input);

if (result.ok) {
  console.log(result.value);
} else {
  console.error(result.error);
}

Guardrails

  • Max 10 selector variables ($X1..$X10)
  • Max candidate bindings limited
  • Max array scan per level limited
  • Invalid operator detection
  • Invalid selector detection
  • Required rule enforcement

Roadmap

  • Expression engine (optional future)
  • Plugin architecture (v0.3+)
  • Performance optimizations
  • JSON Schema validation for rule documents

License

MIT


Contributing

  • PRs welcome.
  • Open issues for feature discussions before major design changes.