
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
business-rules-engine
Advanced tools

Business rules engine is a lightweight JavaScript library for easy business rules definition of the product, the contract, the form etc.
The main benefit is that business rules engine is not tight to HTML DOM or any other UI framework. This validation engine is UI agnostic and that is why it can be used as an independent representation of business rules of a product, contract, etc. It can be easily reused by different types of applications, libraries.
This module is installed:
There are 3 ways how to define validation rules
{
FirstName: {
type: "string",
title: "First name",
required: "true",
maxLength: 15
},
LastName: {
type: "string",
"title": "Last name",
required: true,
maxLength: 15
},
Contacts: {
type: "array",
maxItems: 4,
minItems: 2,
items: {
type: "object",
properties: {
Email: {
type: "string",
title: "Email",
default: '',
required: true,
maxLength: 100,
pattern: "S*@S*" },
Mobile: {
type: "object",
properties: {
CountryCode: {
type: "string",
title: "Country code",
required: true,
maxLength: 3,
enum: ["FRA", "CZE", "USA", "GER"]
},
Number: {
type: "string",
title: "Phone number",
required: true,
maxLength: 9
}
}
},
FixedLine: {
type: "object",
properties: {
CountryCode: {
type: "string",
title: "Country code",
required: true,
maxLength: 3,
enum: ["FRA", "CZE", "USA", "GER"]
},
Number: {
type: "string",
title: "Phone number",
required: true,
maxLength: 9
}
}
}
}
}
}
}
// define data structure + validation rules meta data
{
FirstName: {
rules: {required: true, maxlength: 15}},
LastName: {
rules: {required: true, maxlength: 15}},
Contacts: [
{
Email: {
rules: {
required: true,
maxlength: 100,
email: true
}
},
Mobile: {
CountryCode: {
rules: {required: true, maxlength: 3, enum: ["FRA", "CZE", "USA", "GER"] }
},
Number: {
rules: {required: true, maxlength: 9 }
}
},
FixedLine: {
CountryCode: {
rules: {required: true, maxlength: 3, enum: ["FRA", "CZE", "USA", "GER"] }
},
Number: {
rules: {required: true, maxlength: 9 }
}
}
},{maxItems: 4, minItems: 2}
]
}
To define business rules for some object, you have to create abstract validator.
//create new validator for object with structure<IPerson>
var personValidator = new Validation.AbstractValidator();
//basic validators
var required = new Validators.RequiredValidator();
var maxLength = new Validators.MaxLengthValidator(15);
//assigned validators to property
personValidator.RuleFor("FirstName", required);
personValidator.RuleFor("FirstName",maxLength);
//assigned validators to property
personValidator.RuleFor("LastName", required);
personValidator.RuleFor("LastName",maxLength);
...
To use business rules and execute them on particular data
//create test data
var data = {
Person1:
{
FirstName:'John',
LastName: 'Smith'
},
Person2:{}
}
//create concrete rule
var person1Validator = personValidator.CreateRule("Person 1");
//execute validation
var result = person1Validator.Validate(this.Data.Person1);
//verify results
if (result.HasErrors){
console.log(result.ErrorMessage);
}
//---------
//--outputs
//---------
//create concrete rule
var person2Validator = personValidator.CreateRule("Person 2");
//execute validation
var result = person2Validator.Validate(this.Data.Person1);
//verify results
if (result.HasErrors){
console.log(result.ErrorMessage);
}
//---------
//--outputs
//---------
// FirstName: Field is required.
// LastName: Field is required.
All code is written in typescript.
npm install -g typescript
To compile to javascript.
tsc src/validation/Validation.ts --target ES5 --module commonjs
npm install -g mocha
npm install -g expect.js
To run tests
mocha test
To build all sources to dist folder (generates AMD, CommonJS and module pattern)
$ grunt dist
To run code analyze - complexity + jshint.
$ grunt ci
To generate api documentation.
$ grunt document
To generate typings -> typescript definition files.
$ grunt typings
To run tests
$ grunt test
FAQs
business rules engine
The npm package business-rules-engine receives a total of 44 weekly downloads. As such, business-rules-engine popularity was classified as not popular.
We found that business-rules-engine demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.