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

json-rules-engine-angular-ita

v1.0.4

Published

expand json-rules-engine to work with arrays and angular FormGroup

Downloads

4

Readme

json-rules-engine-angular-ITA

Welcome to the "json-rules-engine-angular-ITA" repository!

Overview

This open-source project contain 3 thing

  1. simple Angular wrapper library for JSON-RULE-ENGINE.
  2. one file bundle for vanilla Javascript project

what we use under the hood ?

This open-source project is a small wrapper helper utils written in TYPESCRIPT that can accept @angular/form object of a JavaScript library json-rules-engine
originally licensed under the ISC License.

Features

  • easy to create complex Form cross field validations
  • SOC - separate of concern - remove your form logic out of your angular component
  • non programer stuff member like Qa & project managers can read the Form cross validation logic

Getting Started

Follow these steps to get your project up and running quickly.

Installation

inside your angular project:

npm install json-rules-engine-angular-ITA

2 - import the base function 2,5 - add rule if you have 3 - run the base function 4 - add to the pipe

5- run the form observble

Usage

  • define the Rule in a Json format or JS object
  • inside your angular component initialize the Rules Engine ,pass the relevant rules for the specific form and call it whatever you want
  • call the Engine

the basic Rule Engine is actually return promise , in our example we use ngZone but you usually you will not need it

Example

define the rule . the $ sign is the define main root object path
to learn more bout how to define rules read the Json rule Engine Docs.

  import { RuleProperties} from 'json-rules-engine-angular-ITA
  const emailMatch = {
    conditions: {
      "all": [
        {
          "value": {
            "fact":"main",
            "path": "$.email"
          },
          "fact": "main",
          "path": "$.emailConfirm",
          "operator": "notEqual"
        }
      ]
    },
    event: {
      type: 'emailNotMatch',
      params: {
        formPath: 'emailConfirm'
      }
    },
    name: 'emailCheck',
    priority: 1
  }
  
  export const emailRules: RuleProperties[] = [emailMatch];

import { Component, NgZone, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms'
import { Engine } from 'json-rules-engine-angular-ITA;
import {  initEngine ,rulesEngineRunZone} from 'json-rules-engine-angular-ITA;
import {emailRules} from '../rules/email.rules'
@Component({
  selector: 'app-sample-email',
  templateUrl: './sample-email.component.html',
  styleUrls: ['./sample-email.component.scss']
})
export class SampleEmailComponent implements OnInit {
  engine: Engine

  emailForm: FormGroup = new FormGroup({
    email: new FormControl('', [Validators.required]),
    emailConfirm: new FormControl('', [Validators.required]),
  });
  constructor(private ngZone: NgZone) { }

  ngOnInit(): void {
    this.engine = initEngine(emailRules, this.emailForm);
    this.emailForm.valueChanges.subscribe(res => {


           this.ngZone.run(() => {
        
            rulesEngineRunZone(this.engine,this.emailForm)
  
        })
    })
  }

}

<p>sample-email</p>
<section>
    <div [formGroup]=emailForm class="form-group">
        <div class="form-control">
            <label for="">Email</label>
            <input type="text" formControlName="email">
          
        </div>
        <div>error list:  {{emailForm.controls.email.errors|json}}</div>
        <div *ngIf="emailForm.controls.email.errors?.required" class="error">
            חובה להכניס כתובת מייל
        </div>

        <div class="form-control">
            <label for="">Confirm Email</label>
            <input type="text" formControlName="emailConfirm">

        </div>
        <div>error list:  {{emailForm.controls.emailConfirm.errors|json}} </div>

        <div *ngIf="emailForm.controls.emailConfirm.errors?.emailNotMatch" class="error">
            כתובת מייל לא תואמת
        </div>

    </div>
</section>
<hr>
{{emailForm.value|json}}

Documentation

see in documentations and example folder in ths repo

Acknowledgments

We would like to express our gratitude to the creators of the original library for their valuable work, which served as the foundation for our customized version.

Feel free to contribute, report issues, or share your feedback to help us improve "json-rules-engine-angular-ITA". We appreciate your support!

License

This project is licensed under the MIT License - see the ISC file for details.