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

@generatedpixel/gp-rules

v1.1.2

Published

Dynamic, reactive Business Rules Engine and event automation for Angular and gp-ui components.

Readme

@generatedpixel/gp-rules

Dynamic, Reactive Business Rules Engine for Angular and gp-ui

@generatedpixel/gp-rules is a powerful, declarative, and lightweight Business Rules Engine for Angular 19+ and @generatedpixel/gp-ui. It empowers developers to define declarative automation rules triggered by component events (such as keypress with configurable debounce, blur / lose focus, change / valueChange, and click), evaluate rich composite conditions, and execute reactive UI actions without boilerplate.


🌟 Key Features

  • ⚡ Reactive Event Triggers:
    • keypress & input with configurable debounce delay (e.g. debounce: 300 ms) and key filters (e.g. Enter).
    • blur & focusout (lose focus verification and formatting).
    • focus & focusin (gain focus guidance).
    • change & valueChange (reactive form control and signal value changes).
    • click & select (buttons, chips, options, and table rows).
    • init & mount (initialization automation).
  • 🧠 Rich Condition Engine:
    • Operators: eq, neq, gt, gte, lt, lte, between, notBetween, contains, notContains, startsWith, endsWith, matches (Regex), in, notIn, allIn, anyIn, noneIn, hasLength, lengthGt, lengthLt, isBefore, isAfter, isSameDay, isBetweenDates, isFuture, isPast, empty, notEmpty, truthy, falsy.
    • Dynamic Field-to-Field Comparisons: compareToField: 'password' (compare confirmPassword against password).
    • Composite Logic: all (AND), any (OR), none (NOR), not (negation).
    • Expression strings: quantity * price > 500 && country === 'US'.
    • Custom TypeScript synchronous and asynchronous predicate functions (customPredicate, asyncPredicate).
  • 🚀 Dynamic Action Handlers:
    • State & Transformations: setValue, patchValues, copyValue, transformValue (slugify, uppercase, lowercase, titlecase, trim, currency, phone), reset, clear.
    • Form Validation: setValidationError, clearValidationError.
    • UI & Styling: show, hide, toggleVisibility, setClass, setStyle, setFocus.
    • Control State: enable, disable, setRequired, setReadonly.
    • Cascading Selects: setOptions, filterOptions (Country ➔ State ➔ City).
    • Formulas & Computations: Built-in math and logic helpers (SUM, AVG, MIN, MAX, ROUND, IF, DATE_DIFF, CONCAT, UPPER, LOWER, TRIM).
    • Effects & Network: toast, emit, apiCall (with automated JSON response mapping), and custom programmatic functions.
  • 🧪 Simulator, Linter & Diagnostics:
    • GpRuleSimulator.simulate(...): Dry-run simulations with before/after state diffs without mutating UI or forms.
    • GpRuleValidator.validate(...): Static analysis, linting, syntax checking, and cyclic dependency detection.
  • 🎯 Angular Directives & Visual Components:
    • [gpRule] / [gpRules]: Attach rules directly to DOM inputs or gp-ui components.
    • [gpRuleGroup]: Scope rules across forms with shared reactive state.
    • <gp-rule-inspector>: Live audit trail displaying real-time execution metrics (totalExecutions, successRate, averageDurationMs), filtering, search, and JSON export.
    • <gp-rule-builder>: Interactive UI component to design, test, and register rules dynamically in the browser.

📦 Installation

npm install @generatedpixel/gp-rules @generatedpixel/gp-ui

🚀 Quick Start

1. Define a Business Rule

import { GpBusinessRule } from '@generatedpixel/gp-rules';

export const PROMO_CODE_RULE: GpBusinessRule = {
  id: 'promo-code-evaluator',
  name: 'Debounced Promo Code Evaluator',
  priority: 10,
  trigger: {
    event: 'keypress',
    debounce: 300,
    targetField: 'promoCode'
  },
  condition: {
    field: 'promoCode',
    operator: 'eq',
    value: 'SAVE20'
  },
  actions: [
    { type: 'setValue', target: 'discount', value: 20 },
    { type: 'toast', message: 'Promo code SAVE20 applied! (20% OFF)', severity: 'success' }
  ],
  elseActions: [{ type: 'setValue', target: 'discount', value: 0 }]
};

2. Attach to Component with Directive

<gp-input-text
  [(ngModel)]="promoCode"
  placeholder="Enter promo code..."
  [gpRule]="promoRule"
  [gpRuleState]="formState"
/>

<!-- Live Audit Trail with Metrics -->
<gp-rule-inspector />

📖 API Reference

Trigger Configuration (GpRuleTrigger)

| Property | Type | Description | | ------------- | ------------------------------------------------------------------ | ------------------------------------------- | | event | 'keypress' \| 'blur' \| 'focus' \| 'change' \| 'click' \| 'init' | Event to listen for | | debounce | number | Debounce delay in milliseconds (e.g. 300) | | throttle | number | Throttle interval in milliseconds | | targetField | string | Optional field name to scope trigger | | keyFilter | string \| string[] | Keyboard key filter (e.g. 'Enter') |

Operators (GpRuleOperator)

| Operator | Description | Example | | ------------------------- | ------------------------------------------ | ------------------------------------------------------------------------------ | | eq / equals | Equality check (=== or ==) | { field: 'confirmPassword', operator: 'eq', compareToField: 'password' } | | neq / notEquals | Not equal | { field: 'status', operator: 'neq', value: 'archived' } | | gt / gte | Greater than / Greater than or equal | { field: 'age', operator: 'gte', value: 18 } | | lt / lte | Less than / Less than or equal | { field: 'stock', operator: 'lt', value: 5 } | | between / notBetween | Range check [min, max] | { field: 'score', operator: 'between', value: [80, 100] } | | isBefore / isAfter | Date chronological comparison | { field: 'endDate', operator: 'isAfter', compareToField: 'startDate' } | | isSameDay | Date calendar day equality | { field: 'deliveryDate', operator: 'isSameDay', value: new Date() } | | hasLength / lengthGt | String or array length check | { field: 'password', operator: 'lengthGt', value: 8 } | | contains | Substring or array inclusion | { field: 'roles', operator: 'contains', value: 'admin' } | | startsWith / endsWith | String prefix / suffix matching | { field: 'taxId', operator: 'startsWith', value: 'US-' } | | matches | Regular expression match | { field: 'email', operator: 'matches', value: '^[\\w.-]+@[\\w.-]+\\.\\w+$' } | | empty / notEmpty | Checks null, undefined, empty string/array | { field: 'phone', operator: 'notEmpty' } |

Action Types (GpRuleActionType)

| Action | Description | Example | | ----------------------- | ---------------------------------- | ---------------------------------------------------------------------------------------------------- | | setValue | Updates target field value | { type: 'setValue', target: 'discount', value: 20 } | | copyValue | Copies value from another field | { type: 'copyValue', fromField: 'billingAddress', target: 'shippingAddress' } | | transformValue | Transforms string format | { type: 'transformValue', fromField: 'title', target: 'slug', transformType: 'slugify' } | | setValidationError | Sets custom validation error | { type: 'setValidationError', target: 'confirmPassword', errorKey: 'mismatch' } | | clearValidationError | Clears custom validation error | { type: 'clearValidationError', target: 'confirmPassword', errorKey: 'mismatch' } | | setClass | Adds/removes CSS class | { type: 'setClass', target: 'emailField', className: 'is-valid' } | | setFocus | Focuses target element | { type: 'setFocus', target: 'shippingZip' } | | show / hide | Toggles target field visibility | { type: 'show', target: 'shippingAddress' } | | enable / disable | Toggles control disabled state | { type: 'disable', target: 'submitBtn' } | | compute / calculate | Formula evaluation with math utils | { type: 'compute', target: 'total', formula: 'ROUND(SUM(subtotal, tax) * (1 - discount/100), 2)' } | | setOptions | Populates dynamic dropdown options | { type: 'setOptions', target: 'state', options: [...] } | | toast | Displays a toast notification | { type: 'toast', message: 'Order submitted', severity: 'success' } | | apiCall | Executes REST API & maps response | { type: 'apiCall', url: '/api/zip/90210', responseMapping: { 'city': 'city' } } |


📄 License

MIT © Generated Pixel