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

@ctserv/rule-evaluator

v1.0.0

Published

Evaluate FormBuilder logic rule conditions from JSON (nested AND/OR groups)

Readme

@ctserv/rule-evaluator

Evaluate FormBuilder logic rule conditions from JSON. Returns a boolean — whether the expression is satisfied at runtime.

Pure JavaScript. No React. No DOM. Runs in Node and browser bundlers.

Install

npm install @ctserv/rule-evaluator

Local development from FormBuilder:

npm install ../Rules\ Evaluator

Usage

import {
  evaluateConditions,
  normalizeRules,
  hasCompleteConditions,
} from "@ctserv/rule-evaluator";

const rules = {
  enableWhen: {
    type: "group",
    op: "or",
    children: [
      {
        type: "group",
        op: "and",
        children: [
          { type: "condition", field: "age", op: ">", value: "18" },
          { type: "condition", field: "country", op: "==", value: "US" },
        ],
      },
      { type: "condition", field: "vip", op: "==", value: "true" },
    ],
  },
  action: "disable",
};

const values = { age: "25", country: { value: "US" }, vip: false };

const met = evaluateConditions(rules, values, {
  fieldLookup: {
    age: { type: "inputNumeric" },
    country: { type: "select" },
    vip: { type: "checkbox" },
  },
});

Flat and legacy shapes are normalized internally:

// flat
{ match: "all", conditions: [...] }

// legacy
{ all: [...] }  // or { any: [...] }

API

| Function | Description | |----------|-------------| | evaluateConditions(rules, values, options?) | Returns boolean | | normalizeRules(rules) | Canonical tree-shaped rules object | | hasCompleteConditions(rules) | At least one complete field + op condition | | sanitizeRules(rules) | Strip incomplete nodes; null if nothing valid |

Options

  • fieldLookup — map of field name → metadata (type, etc.)
  • getComparableValue(fieldMeta, rawValue) — override for type-aware comparisons (dateTime, richEdit, fileUpload)

Default comparable values

| Field type | Comparable | |------------|------------| | inputText, inputNumeric, radioGroup | raw scalar / string | | select | rawValue.value | | checkbox | "true" or "false" | | dateTime, richEdit, fileUpload | use injected getComparableValue |

Debugging

Example scripts live in debug/. Open any file, set breakpoints, then run Debug current file from .vscode/launch.json.

| File | What it exercises | |------|-------------------| | debug/evaluate-flat-and.js | Flat AND rules | | debug/evaluate-flat-or.js | Flat OR rules | | debug/evaluate-nested-or-and.js | Nested OR with inner AND | | debug/evaluate-legacy-all.js | Legacy all[] shape | | debug/evaluate-field-types.js | Select, checkbox, numeric, case sensitivity | | debug/normalize-rules.js | Normalization and sanitize |

Shared helpers: debug/_shared.js.

Or run from terminal:

node debug/evaluate-nested-or-and.js

Operators

==, !=, >, >=, <, <=

Ordering ops use numeric comparison when both sides are finite numbers; otherwise lexicographic string comparison.